From 43a548eab072d62fca95de2357b0b30d64c1187d Mon Sep 17 00:00:00 2001 From: SrIzan10 <66965250+SrIzan10@users.noreply.github.com> Date: Tue, 24 Oct 2023 15:50:51 +0200 Subject: [PATCH] fix: database queries not working --- index.ts | 4 ++-- package.json | 2 +- prisma/schema.prisma | 2 ++ routes/sern/deleteTime.ts | 9 --------- routes/sern/getTime.ts | 7 ++----- 5 files changed, 7 insertions(+), 17 deletions(-) diff --git a/index.ts b/index.ts index 8e46477..a75aa56 100644 --- a/index.ts +++ b/index.ts @@ -10,7 +10,7 @@ const exec = (await import('util')).promisify((await import('child_process')).ex const dirname = path.dirname(fileURLToPath(import.meta.url)); -await exec('npx prisma generate') +if (process.argv[2] !== '--dev') await exec('npx prisma generate') /* MongoDB */ export const prisma = new PrismaClient() @@ -19,7 +19,7 @@ export const prisma = new PrismaClient() const app = express() const limiter = rateLimit({ windowMs: 1 * 60 * 1000, - max: 10, + max: 30, message: { success: false, reason: "you just got ratelimited", error: "You just got ratelimited." }, standardHeaders: true, }) diff --git a/package.json b/package.json index 7e712cc..bfb9169 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "module", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "dev": "tsc-watch --onSuccess \"node dist/index.js\"", + "dev": "tsc-watch --onSuccess \"node dist/index.js --dev\"", "build": "tsc --build" }, "repository": { diff --git a/prisma/schema.prisma b/prisma/schema.prisma index cd495ff..2696a89 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -12,6 +12,8 @@ model sern_timezones { v Int @default(0) @map("__v") @ignore timezone String userid String @unique + + @@map("sern-timezones") } model transcripts { diff --git a/routes/sern/deleteTime.ts b/routes/sern/deleteTime.ts index 6d51142..3691bba 100644 --- a/routes/sern/deleteTime.ts +++ b/routes/sern/deleteTime.ts @@ -3,15 +3,6 @@ import type { Handler } from 'express' export const del: Handler = async (req, res) => { if (req.query.userid && req.query.key === process.env.SERN_TIME) { - if ( - await prisma.sern_timezones.findUnique({ - where: { userid: req.query.userid as string }, - }) - ) - return res.status(400).json({ - error: "the user doesn't exist", - }) - await prisma.sern_timezones.delete({ where: { userid: req.query.userid as string, diff --git a/routes/sern/getTime.ts b/routes/sern/getTime.ts index 170c04b..e3905c5 100644 --- a/routes/sern/getTime.ts +++ b/routes/sern/getTime.ts @@ -3,15 +3,12 @@ import type { Handler } from "express" export const get: Handler = async (req, res) => { if (req.query.userid) { - if (await prisma.sern_timezones.count({ where: { userid: req.query.userid as string } }) === 0) - return res.status(400).json({ - error: "the user doesn't exist", - }) const timezone = await prisma.sern_timezones.findUnique({ where: { userid: req.query.userid as string, } - }) + }) + if (!timezone) return res.status(400).json({ error: "the user doesn't exist" }) res.json({ timezone: timezone?.timezone }) } else { res.status(400).json({