nestjs_auth...

This commit is contained in:
최준흠 2022-09-10 22:00:32 +09:00
parent 3456bec3d4
commit f54195bb8a
3 changed files with 18 additions and 18 deletions

View File

@ -40,6 +40,6 @@ export class AuthService {
async register(data: UserDTO): Promise<any | null> {
const user = await this.userService.add(data)
if (!user) return null
return await this.getTokens(user)
return this.getTokens(user)
}
}

View File

@ -25,7 +25,7 @@ export class UserController {
@Roles(ROLE.ADMIN)
@UseGuards(JwtAuthGuard, RolesGuard)
@Get()
async fetchAll(@Query() query): Promise<any> {
fetchAll(@Query() query) {
console.log(query)
//Field별 filter AND Sql용
@ -114,8 +114,8 @@ export class UserController {
console.log(fetchSQL)
//전체 갯수 및 fetched Data
const total = await this.userService.count(fetchSQL)
const rows = await this.userService.fetchAll(fetchSQL)
const total = this.userService.count(fetchSQL)
const rows = this.userService.fetchAll(fetchSQL)
const result = {
total: total,
perPage: perPage,
@ -132,23 +132,23 @@ export class UserController {
@Roles(ROLE.ADMIN)
@UseGuards(JwtAuthGuard, RolesGuard)
@Get(':id')
async fetchOne(@Param('id') id: string): Promise<User | undefined> {
return await this.userService.fetchOne({ id: Number(id) })
fetchOne(@Param('id') id: string): Promise<User | undefined> {
return this.userService.fetchOne({ id: Number(id) })
}
@Roles(ROLE.ADMIN)
@UseGuards(JwtAuthGuard, RolesGuard)
@Post('add')
async add(@Body() data: UserDTO): Promise<User> {
return await this.userService.add(data)
add(@Body() data: UserDTO): Promise<User> {
return this.userService.add(data)
}
@Roles(ROLE.ADMIN)
@UseGuards(JwtAuthGuard, RolesGuard)
@Put(':id')
async update(@Param('id') id: string, @Body() data: UserDTO): Promise<User> {
update(@Param('id') id: string, @Body() data: UserDTO): Promise<User> {
data.updatedAt = new Date()
return await this.userService.update({
return this.userService.update({
where: { id: Number(id) },
data: data
})
@ -157,7 +157,7 @@ export class UserController {
@Roles(ROLE.ADMIN)
@UseGuards(JwtAuthGuard, RolesGuard)
@Delete(':id')
async delete(@Param('id') id: string): Promise<User | undefined> {
return await this.userService.remove({ id: Number(id) })
delete(@Param('id') id: string): Promise<User | undefined> {
return this.userService.remove({ id: Number(id) })
}
}

View File

@ -18,7 +18,7 @@ export class UserService {
where?: Prisma.UserWhereInput
}): Promise<number> {
const { cursor, where } = params
return await this.prisma.user.count({
return this.prisma.user.count({
cursor,
where
})
@ -33,7 +33,7 @@ export class UserService {
orderBy?: Prisma.UserOrderByWithRelationInput
}): Promise<User[]> {
const { skip, take, cursor, where, orderBy } = params
return await this.prisma.user.findMany({
return this.prisma.user.findMany({
skip,
take,
cursor,
@ -44,12 +44,12 @@ export class UserService {
//단일 조회
async fetchOne(where: Prisma.UserWhereInput): Promise<User | null> {
return await this.prisma.user.findFirstOrThrow({ where: where })
return this.prisma.user.findFirstOrThrow({ where: where })
}
//단일 추가
async add(data: Prisma.UserCreateInput): Promise<User> {
return await this.prisma.user.create({ data })
return this.prisma.user.create({ data })
}
//단일 수정
@ -58,7 +58,7 @@ export class UserService {
data: Prisma.UserUpdateInput
}): Promise<User | null> {
const { where, data } = params
return await this.prisma.user.update({
return this.prisma.user.update({
data,
where
})
@ -66,6 +66,6 @@ export class UserService {
//단일 삭제
async remove(where: Prisma.UserWhereUniqueInput): Promise<User | null> {
return await this.prisma.user.delete({ where })
return this.prisma.user.delete({ where })
}
}