diff --git a/src/controllers/user-management/user.controller.ts b/src/controllers/user-management/user.controller.ts index 9102232c..9d6cdaae 100644 --- a/src/controllers/user-management/user.controller.ts +++ b/src/controllers/user-management/user.controller.ts @@ -132,6 +132,23 @@ export class UserController { } } + @Put(":id/hide-welcome") + @ApiOperation({ summary: "Don't show welcome screen for a user again" }) + @Read() + async hideWelcome(@Req() req: AuthenticatedRequest): Promise { + const wasOk = await this.userService.hideWelcome(req.user.userId); + + AuditLog.success( + ActionType.UPDATE, + User.name, + req.user.userId, + req.user.userId, + req.user.username + ); + + return wasOk + } + @Get(":id") @ApiOperation({ summary: "Get one user" }) async find( diff --git a/src/entities/user.entity.ts b/src/entities/user.entity.ts index 852afe06..79440915 100644 --- a/src/entities/user.entity.ts +++ b/src/entities/user.entity.ts @@ -37,4 +37,7 @@ export class User extends DbBaseEntity { @Column({ default: false }) isSystemUser: boolean; + + @Column({ default: false }) + showWelcomeScreen: boolean; } diff --git a/src/migration/1652342361070-welcome-screen.ts b/src/migration/1652342361070-welcome-screen.ts new file mode 100644 index 00000000..bd75c9da --- /dev/null +++ b/src/migration/1652342361070-welcome-screen.ts @@ -0,0 +1,14 @@ +import {MigrationInterface, QueryRunner} from "typeorm"; + +export class welcomeScreen1652342361070 implements MigrationInterface { + name = 'welcomeScreen1652342361070' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "user" ADD "showWelcomeScreen" boolean NOT NULL DEFAULT false`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "showWelcomeScreen"`); + } + +} diff --git a/src/services/user-management/user.service.ts b/src/services/user-management/user.service.ts index 8bc1b583..8c187201 100644 --- a/src/services/user-management/user.service.ts +++ b/src/services/user-management/user.service.ts @@ -122,6 +122,7 @@ export class UserService { const mappedUser = this.mapDtoToUser(user, dto); mappedUser.createdBy = userId; mappedUser.updatedBy = userId; + mappedUser.showWelcomeScreen = true; await this.setPasswordHash(mappedUser, dto.password); @@ -138,6 +139,7 @@ export class UserService { async createUserFromKombit(profile: Profile): Promise { const user = new User(); await this.mapKombitLoginProfileToUser(user, profile); + user.showWelcomeScreen = true; return await this.userRepository.save(user); } @@ -256,9 +258,9 @@ export class UserService { take: +query.limit, skip: +query.offset, order: sorting, - where: { - isSystemUser: false - } + where: { + isSystemUser: false, + }, }); return { @@ -294,4 +296,9 @@ export class UserService { users: result, }; } + + async hideWelcome(id: number): Promise { + const res = await this.userRepository.update(id, { showWelcomeScreen: false }); + return !!res.affected + } }