diff --git a/src/lib/routes/admin-api/index.ts b/src/lib/routes/admin-api/index.ts index 3e0edf6114..f1aa75c7fa 100644 --- a/src/lib/routes/admin-api/index.ts +++ b/src/lib/routes/admin-api/index.ts @@ -21,6 +21,7 @@ import ApiTokenController from './api-token-controller'; import UserAdminController from './user-admin'; import EmailController from './email'; import UserFeedbackController from './user-feedback-controller'; +import UserSplashController from './user-splash-controller'; import ProjectApi from './project'; import { EnvironmentsController } from './environments-controller'; @@ -92,6 +93,10 @@ class AdminApi extends Controller { '/environments', new EnvironmentsController(config, services).router, ); + this.app.use( + '/splash', + new UserSplashController(config, services).router, + ); } index(req, res) { diff --git a/src/lib/routes/admin-api/user-splash-controller.ts b/src/lib/routes/admin-api/user-splash-controller.ts index c2e9ad7b14..87815ebd3a 100644 --- a/src/lib/routes/admin-api/user-splash-controller.ts +++ b/src/lib/routes/admin-api/user-splash-controller.ts @@ -74,3 +74,4 @@ class UserSplashController extends Controller { } module.exports = UserSplashController; +export default UserSplashController; \ No newline at end of file diff --git a/src/lib/routes/admin-api/user.ts b/src/lib/routes/admin-api/user.ts index 1d2815a9c6..3e13b4db19 100644 --- a/src/lib/routes/admin-api/user.ts +++ b/src/lib/routes/admin-api/user.ts @@ -7,7 +7,7 @@ import { IUnleashServices } from '../../types/services'; import UserService from '../../services/user-service'; import SessionService from '../../services/session-service'; import UserFeedbackService from '../../services/user-feedback-service'; -import UserSplashService from 'lib/services/user-splash-service'; +import UserSplashService from '../../services/user-splash-service'; interface IChangeUserRequest { password: string; @@ -47,6 +47,7 @@ class UserController extends Controller { this.userService = userService; this.sessionService = sessionService; this.userFeedbackService = userFeedbackService; + this.userSplashService = userSplashService; this.get('/', this.getUser); this.post('/change-password', this.updateUserPass); @@ -62,12 +63,14 @@ class UserController extends Controller { const feedback = await this.userFeedbackService.getAllUserFeedback( user, ); - //const splash = await this.userSplashService.getAllUserSplash(user); + const splash = await this.userSplashService.getAllUserSplashs( + user, + ); // TODO: remove this line after we remove it from db. delete user.permissions; - return res.status(200).json({ user, permissions, feedback }).end(); + return res.status(200).json({ user, permissions, feedback, splash }).end(); } async updateUserPass( diff --git a/src/lib/services/user-splash-service.ts b/src/lib/services/user-splash-service.ts index 9dfb163dd2..65d604ef85 100644 --- a/src/lib/services/user-splash-service.ts +++ b/src/lib/services/user-splash-service.ts @@ -20,12 +20,21 @@ export default class UserSplashService { this.logger = getLogger('services/user-splash-service.js'); } - async getAllUserSplash(user: User): Promise { + async getAllUserSplashs(user: User): Promise { if (user.isAPI) { return []; } try { - return await this.userSplashStore.getAllUserSplashs(user.id); + const splashs = await ( + await this.userSplashStore.getAllUserSplashs(user.id) + ).reduce( + (splashObject, splash) => ({ + ...splashObject, + [splash.splashId]: splash.seen, + }), + {}, + ); + return splashs; } catch (err) { this.logger.error(err); diff --git a/src/test/fixtures/fake-user-splash-store.ts b/src/test/fixtures/fake-user-splash-store.ts index 2fb6af87b8..adc0775c7b 100644 --- a/src/test/fixtures/fake-user-splash-store.ts +++ b/src/test/fixtures/fake-user-splash-store.ts @@ -2,7 +2,7 @@ import { IUserSplashKey, IUserSplash, IUserSplashStore, -} from 'lib/types/stores/user-splash-store'; +} from '../../lib/types/stores/user-splash-store' export default class FakeUserSplashStore implements IUserSplashStore { // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -11,13 +11,13 @@ export default class FakeUserSplashStore implements IUserSplashStore { } // eslint-disable-next-line @typescript-eslint/no-unused-vars - getSplash(userId: number, splashId: string): Promise { - return Promise.resolve({ seen: false, userId: 123, splashId: 'env' }); + getSplash(userId: number, splashId: string): Promise { + return Promise.resolve(undefined); } // eslint-disable-next-line @typescript-eslint/no-unused-vars - updateSplash(splash: IUserSplash): Promise { - return Promise.resolve({ seen: false, userId: 123, splashId: 'env' }); + updateSplash(splash: IUserSplash): Promise { + return Promise.resolve(undefined); } // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -35,21 +35,6 @@ export default class FakeUserSplashStore implements IUserSplashStore { return Promise.resolve([]); } - // eslint-disable-next-line @typescript-eslint/no-unused-vars - getAllUserFeedback(userId: number): Promise { - return Promise.resolve([]); - } - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - getFeedback(userId: number, feedbackId: string): Promise { - return Promise.resolve(undefined); - } - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - updateFeedback(feedback: IUserSplash): Promise { - return Promise.resolve(undefined); - } - // eslint-disable-next-line @typescript-eslint/no-unused-vars delete(key: IUserSplashKey): Promise { return Promise.resolve(undefined);