updates collection methods
This commit is contained in:
parent
83d31dd168
commit
69fae81306
22
src/index.ts
22
src/index.ts
|
@ -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())
|
||||
|
||||
|
|
Loading…
Reference in New Issue