From 636285f497b8da75163b2045bd3888f989da220b Mon Sep 17 00:00:00 2001 From: saml33 Date: Tue, 21 Dec 2021 19:47:34 +1100 Subject: [PATCH] add password to delete update --- src/index.ts | 8 +++++--- src/utils.ts | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index f593e7d..6c829c1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -133,10 +133,10 @@ router.get("/alerts/:mangoAccountPk", async (ctx, next) => { router.post("/updates", async (ctx, next) => { try { - const update: any = ctx.request.body - await validateUpdatePassword(update.password) + const req: any = ctx.request.body + await validateUpdatePassword(req.password) ctx.body = { status: "success" } - ctx.db.collection("updates").insertOne(update) + ctx.db.collection("updates").insertOne(req.update) } catch (e: any) { let errorMessage = "Something went wrong" if (e.name == "UserError") { @@ -165,6 +165,8 @@ router.get("/get-updates", async (ctx, next) => { router.post("/delete-update", async (ctx, next) => { try { const id: any = new ObjectId(ctx.request.body.id) + const password: string = ctx.request.body.password + await validateUpdatePassword(password) if (id) { ctx.body = { status: "success" } } diff --git a/src/utils.ts b/src/utils.ts index a0164f0..b2158fd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -40,7 +40,7 @@ export const validateUpdatePassword = (password: string) => { resolve() } } catch (e) { - reject(new UserError("Something went wrong")) + reject(new UserError("Invalid password")) } }) }