From c4e56aae09da6689cd92744260f1d58d6eddfbfa Mon Sep 17 00:00:00 2001 From: Youssef Date: Fri, 12 Nov 2021 10:49:09 +0100 Subject: [PATCH] fix: remove record splash and update sql query in add-splash-entry --- .../admin-api/user-splash-controller.ts | 32 ++----------------- src/lib/services/user-splash-service.ts | 2 +- ...211109103930-add-splash-entry-for-users.js | 3 +- 3 files changed, 4 insertions(+), 33 deletions(-) diff --git a/src/lib/routes/admin-api/user-splash-controller.ts b/src/lib/routes/admin-api/user-splash-controller.ts index 68872fad54..8f01b2172e 100644 --- a/src/lib/routes/admin-api/user-splash-controller.ts +++ b/src/lib/routes/admin-api/user-splash-controller.ts @@ -25,34 +25,7 @@ class UserSplashController extends Controller { this.logger = config.getLogger('splash-controller.ts'); this.userSplashService = userSplashService; - this.post('/', this.recordSplash); - this.put('/:id', this.updateSplashSettings); - } - - private async recordSplash( - req: IAuthRequest, - res: Response, - ): Promise { - const BAD_REQUEST = 400; - const { user } = req; - - const { splashId } = req.body; - - if (!splashId) { - res.status(BAD_REQUEST).json({ - error: 'splashId must be present.', - }); - return; - } - - const splash = { - ...req.body, - userId: user.id, - seen: req.body.seen || false, - }; - - const updated = await this.userSplashService.updateSplash(splash); - res.json(updated); + this.post('/:id', this.updateSplashSettings); } private async updateSplashSettings( @@ -66,9 +39,8 @@ class UserSplashController extends Controller { ...req.body, splashId: id, userId: user.id, - seen: req.body.seen || false, + seen: true, }; - const updated = await this.userSplashService.updateSplash(splash); res.json(updated); } diff --git a/src/lib/services/user-splash-service.ts b/src/lib/services/user-splash-service.ts index 65d604ef85..0f609499d5 100644 --- a/src/lib/services/user-splash-service.ts +++ b/src/lib/services/user-splash-service.ts @@ -25,7 +25,7 @@ export default class UserSplashService { return []; } try { - const splashs = await ( + const splashs = ( await this.userSplashStore.getAllUserSplashs(user.id) ).reduce( (splashObject, splash) => ({ diff --git a/src/migrations/20211109103930-add-splash-entry-for-users.js b/src/migrations/20211109103930-add-splash-entry-for-users.js index 8a34421415..455f743e0a 100644 --- a/src/migrations/20211109103930-add-splash-entry-for-users.js +++ b/src/migrations/20211109103930-add-splash-entry-for-users.js @@ -2,8 +2,7 @@ exports.up = function (db, cb) { db.runSql(`SELECT * FROM users`, (err, results) => { results.rows.forEach((user) => { db.runSql( - `INSERT INTO user_splash(splash_id, user_id, seen) VALUES (?, ?, ?)`, - ['environments', user.id, false], + `INSERT INTO user_splash(splash_id, user_id, seen) SELECT 'environment', u.id, false FROM users u`, ); }); cb();