updates collection methods

This commit is contained in:
saml33 2021-12-20 22:31:15 +11:00
parent 83d31dd168
commit 69fae81306
1 changed files with 18 additions and 4 deletions

View File

@ -129,11 +129,8 @@ router.get("/alerts/:mangoAccountPk", async (ctx, next) => {
router.post("/updates", async (ctx, next) => {
try {
const update: any = ctx.request.body
// await validateMangoAccount(client, alert)
// validateEmail(alert.email)
ctx.body = { status: "success" }
// alert.open = true
// alert.timestamp = Date.now()
ctx.db.collection("updates").insertOne(update)
} catch (e: any) {
let errorMessage = "Something went wrong"
@ -162,6 +159,23 @@ router.get("/get-updates", async (ctx, next) => {
}
})
router.post("/delete-update", async (ctx, next) => {
try {
const id: any = new ObjectId(ctx.request.body.id)
if (id) {
ctx.body = { status: "success" }
}
ctx.db.collection("updates").deleteOne({ _id: id })
} catch (e: any) {
let errorMessage = "Something went wrong"
if (e.name == "UserError") {
errorMessage = e.message
}
ctx.throw(400, errorMessage)
}
await next()
})
app.use(router.allowedMethods())
app.use(router.routes())