From e204e9223c48300c7ec88fa6f48b07d4d5a196e3 Mon Sep 17 00:00:00 2001 From: Matthew Aaron Raymer Date: Tue, 29 Aug 2023 14:04:17 +0800 Subject: [PATCH 1/2] Change stats NOT IMPLEMENTED for unfinished methods --- src/main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index f532ce1..bcdf2ab 100644 --- a/src/main.ts +++ b/src/main.ts @@ -54,14 +54,14 @@ class Server { const subscription = req.body as Subscription; console.log(subscription); - res.status(201).send(); + res.status(501).send(); }); this.app.post('/mute', async (req: Request, res: Response) => { const subscription = req.body as Subscription; console.log(subscription); - res.status(201).send(); + res.status(501).send(); }); this.app.get('/vapid', async (_: Request, res: Response) => { From 298e394c04f60d706a26bb5627f28300283d3556 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Tue, 29 Aug 2023 20:32:07 +0800 Subject: [PATCH 2/2] Adding tentative db methods for removing and muting subscriptions --- src/Subscription.ts | 3 +++ src/db.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/Subscription.ts b/src/Subscription.ts index 27bf173..6582514 100644 --- a/src/Subscription.ts +++ b/src/Subscription.ts @@ -14,4 +14,7 @@ export class Subscription { @Column() keys_auth: string; + + @Column() + muted: boolean = false; } diff --git a/src/db.ts b/src/db.ts index dfe5b65..cc28188 100644 --- a/src/db.ts +++ b/src/db.ts @@ -58,12 +58,40 @@ class DBService { } + async removeSubscription(endpoint: string): Promise { + let result = true; + if (this.isReady) { + await this.dataSource.manager.delete(Subscription, { endpoint: endpoint }); + + } else { + result = false; + + } + return result; + } + + + async toggleMuteSubscription(endpoint: string): Promise { + let result = true; + if (this.isReady) { + const subscription = await this.dataSource.manager.findOne(Subscription, { where : {endpoint: endpoint} }); + subscription.muted = !subscription.muted; + await this.dataSource.manager.save(subscription) + } else { + result = false; + + } + return result; + } + + async getVapidKeys(): Promise { console.log(__filename, "getVapidKeys", this.isReady); let result = [ new VapidKeys() ]; if ( this.isReady ) { result = await this.dataSource.manager.find(VapidKeys); console.log(__filename, "results of find: ", result); + } else { console.log(__filename, "Database is not ready");