From 7ccd783b1e1a08a68df5c297768db08633a60a5b Mon Sep 17 00:00:00 2001 From: publdaze Date: Mon, 23 Oct 2023 17:57:16 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EC=95=8C=EB=A6=BC=20=EC=88=98?= =?UTF-8?q?=EC=8B=A0=20=EC=97=AC=EB=B6=80=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/users/entities/user.entity.ts | 3 +++ src/users/users.controller.ts | 11 ++++++++++- src/users/users.repository.ts | 14 ++++++++++++++ src/users/users.service.ts | 5 +++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/users/entities/user.entity.ts b/src/users/entities/user.entity.ts index 21c6004..66fbddc 100644 --- a/src/users/entities/user.entity.ts +++ b/src/users/entities/user.entity.ts @@ -24,6 +24,9 @@ export class User { @Prop() role: Role; + @Prop() + isNotificationEnabled: boolean; + @Prop({ default: new Date(), type: mongoose.Schema.Types.Date }) createdAt: Date; diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index 6c851c9..33c0419 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -1,8 +1,10 @@ -import { Body, Controller, Post } from '@nestjs/common'; +import { Body, Controller, Post, Put, UseGuards } from '@nestjs/common'; import { CreateUserDto } from './dtos/create-user.dto'; import { User } from './entities/user.entity'; import { UsersService } from './users.service'; import { ApiOperation } from '@nestjs/swagger'; +import { RolesGuard } from 'src/auth/passport/role.guard'; +import { AuthGuard } from '@nestjs/passport'; @Controller('users') export class UsersController { @@ -13,4 +15,11 @@ export class UsersController { async create(@Body() userData: CreateUserDto): Promise { return await this.userService.create(userData); } + + @Put('/notification') + @UseGuards(AuthGuard('jwt'), RolesGuard) + async setNotificationEnable(@Body() req) { + console.log(req); + return await this.userService.setNotificationEnable(req.body); + } } diff --git a/src/users/users.repository.ts b/src/users/users.repository.ts index 4243bd8..adc9ec7 100644 --- a/src/users/users.repository.ts +++ b/src/users/users.repository.ts @@ -32,4 +32,18 @@ export class UsersRepository { throw err; } } + + async setNotificationEnable(isNotificationEnabled: boolean) { + try { + return await this.usersModel.findOneAndUpdate( + { + loginId: 'admin', + }, + { isNotificationEnabled: isNotificationEnabled }, + ); + } catch (err) { + console.log('Error get users set notification enable:', err.message); + throw err; + } + } } diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 9faa1df..2bb0e21 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -17,9 +17,14 @@ export class UsersService { user.username = username; user.role = role; user.expoToken = ''; + user.isNotificationEnabled = false; await this.usersRepository.save(user); user.password = undefined; return user; } + + async setNotificationEnable(isNotificationEnabled: boolean) { + await this.usersRepository.setNotificationEnable(isNotificationEnabled); + } }