From f38d8dff22227fc55a02e020aaf657de510cc23b Mon Sep 17 00:00:00 2001 From: SrIzan10 <66965250+SrIzan10@users.noreply.github.com> Date: Mon, 14 Nov 2022 16:34:42 +0100 Subject: [PATCH] feat: sern deletetime thing --- index.ts | 23 ++++++++++++++++++++++- util/consolelogTime.ts | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index 4568156..667ae7d 100644 --- a/index.ts +++ b/index.ts @@ -43,7 +43,7 @@ app.post("/sern/newTime", async (req, res, next) => { userid: req.body.userid, }) saveToDB.save() - res.json({ "ok": "kay done" }) + res.json({ "ok": "you were added successfully!" }) } } }) @@ -74,6 +74,27 @@ app.get("/sern/getTime", async (req, res, next) => { } }) +app.delete("/sern/deleteTime", async (req, res) => { + if (req.query.userid && req.query.key === process.env.SERN_TIME) { + sernTime.exists({ userid: req.query.userid }, async function (err, doc) { + if (err) throw err + if (doc) { + const timezone = await sernTime.findOne({ userid: req.query.userid }) + await timezone!.delete() + res.json({"ok": "done"}) + } else { + res.status(400).json({ + "error": "the user doesn't exist", + }) + } + }) + } else { + res.status(400).json({ + "error": "make sure you have the userid param and the right key", + }) + } +}) + app.listen(7272, () => { consolelogTime(`listening`) }) diff --git a/util/consolelogTime.ts b/util/consolelogTime.ts index e047d81..c8b96bf 100644 --- a/util/consolelogTime.ts +++ b/util/consolelogTime.ts @@ -3,5 +3,5 @@ export async function consolelogTime(message: string) { const unix = new Date() - return console.log(`[${unix.toLocaleTimeString()}] ${message}`); + return console.log(`[${unix.toLocaleTimeString(('es-ES'))}] ${message}`); } \ No newline at end of file