Skip to content

Commit

Permalink
feat : 알림 수신 여부 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
publdaze committed Oct 23, 2023
1 parent 840bf6f commit 7ccd783
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/users/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export class User {
@Prop()
role: Role;

@Prop()
isNotificationEnabled: boolean;

@Prop({ default: new Date(), type: mongoose.Schema.Types.Date })
createdAt: Date;

Expand Down
11 changes: 10 additions & 1 deletion src/users/users.controller.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -13,4 +15,11 @@ export class UsersController {
async create(@Body() userData: CreateUserDto): Promise<User> {
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);
}
}
14 changes: 14 additions & 0 deletions src/users/users.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
5 changes: 5 additions & 0 deletions src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 7ccd783

Please sign in to comment.