Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// const postgres = require("../utils/postgres");
const prisma = require("../utils/prisma");
import prisma from "../utils/prisma";
import { Event } from ".prisma/client/index";
Comment thread
mikephu marked this conversation as resolved.
Outdated

async function getAllEvents() {
async function getAllEvents(): Promise<Event[]> {
return prisma.event.findMany();
}

async function getEvents(limit, action, eventId) {
let events;
async function getEvents(limit: number, action: string, eventId: string): Promise<Event[]> {
let events: Event[];

switch (action) {
case "prev":
events = await prisma.events.findMany({
events = await prisma.event.findMany({
take: -1 * limit,
skip: 1, // skip cursor (TODO: check if skip 1 is needed for previous page queries)
cursor: {
Expand All @@ -22,7 +23,7 @@ async function getEvents(limit, action, eventId) {
});
break;
case "next":
events = await prisma.events.findMany({
events = await prisma.event.findMany({
take: limit,
skip: 1, // skip cursor
cursor: {
Expand All @@ -35,7 +36,7 @@ async function getEvents(limit, action, eventId) {
break;
// first request made for first page, no action in cursor present
default:
events = await prisma.events.findMany({
events = await prisma.event.findMany({
take: limit,
orderBy: {
eventId: "asc",
Expand All @@ -47,14 +48,14 @@ async function getEvents(limit, action, eventId) {
return events;
}

async function getPages(limit) {
const totalEvents = await prisma.events.count();
async function getPages(limit: number): Promise<number> {
const totalEvents = await prisma.event.count();
const totalPages = Math.ceil(totalEvents / limit);
return totalPages;
}

async function getEvent(eventId) {
const event = await prisma.events.findUnique({
async function getEvent(eventId: string): Promise<Event | null> {
const event = await prisma.event.findUnique({
where: {
eventId: eventId,
},
Expand Down
20 changes: 0 additions & 20 deletions packages/server/controllers/guilds.js

This file was deleted.

21 changes: 21 additions & 0 deletions packages/server/controllers/guilds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import prisma from "../utils/prisma";
import { Guild } from ".prisma/client/index";

async function getAllGuilds() {
const query = await prisma.guild.findMany();
return query;
}
Comment thread
mikephu marked this conversation as resolved.
Outdated

async function getGuild(guildId: string): Promise<Guild | null> {
const query = await prisma.guild.findFirst({
where: {
guildId: guildId,
},
});
return query;
}

module.exports = {
getGuild,
getAllGuilds,
};