nestjs_auth...
This commit is contained in:
parent
3456bec3d4
commit
f54195bb8a
@ -40,6 +40,6 @@ export class AuthService {
|
|||||||
async register(data: UserDTO): Promise<any | null> {
|
async register(data: UserDTO): Promise<any | null> {
|
||||||
const user = await this.userService.add(data)
|
const user = await this.userService.add(data)
|
||||||
if (!user) return null
|
if (!user) return null
|
||||||
return await this.getTokens(user)
|
return this.getTokens(user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ export class UserController {
|
|||||||
@Roles(ROLE.ADMIN)
|
@Roles(ROLE.ADMIN)
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Get()
|
@Get()
|
||||||
async fetchAll(@Query() query): Promise<any> {
|
fetchAll(@Query() query) {
|
||||||
console.log(query)
|
console.log(query)
|
||||||
|
|
||||||
//Field별 filter AND Sql용
|
//Field별 filter AND Sql용
|
||||||
@ -114,8 +114,8 @@ export class UserController {
|
|||||||
console.log(fetchSQL)
|
console.log(fetchSQL)
|
||||||
|
|
||||||
//전체 갯수 및 fetched Data
|
//전체 갯수 및 fetched Data
|
||||||
const total = await this.userService.count(fetchSQL)
|
const total = this.userService.count(fetchSQL)
|
||||||
const rows = await this.userService.fetchAll(fetchSQL)
|
const rows = this.userService.fetchAll(fetchSQL)
|
||||||
const result = {
|
const result = {
|
||||||
total: total,
|
total: total,
|
||||||
perPage: perPage,
|
perPage: perPage,
|
||||||
@ -132,23 +132,23 @@ export class UserController {
|
|||||||
@Roles(ROLE.ADMIN)
|
@Roles(ROLE.ADMIN)
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
async fetchOne(@Param('id') id: string): Promise<User | undefined> {
|
fetchOne(@Param('id') id: string): Promise<User | undefined> {
|
||||||
return await this.userService.fetchOne({ id: Number(id) })
|
return this.userService.fetchOne({ id: Number(id) })
|
||||||
}
|
}
|
||||||
|
|
||||||
@Roles(ROLE.ADMIN)
|
@Roles(ROLE.ADMIN)
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Post('add')
|
@Post('add')
|
||||||
async add(@Body() data: UserDTO): Promise<User> {
|
add(@Body() data: UserDTO): Promise<User> {
|
||||||
return await this.userService.add(data)
|
return this.userService.add(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Roles(ROLE.ADMIN)
|
@Roles(ROLE.ADMIN)
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Put(':id')
|
@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()
|
data.updatedAt = new Date()
|
||||||
return await this.userService.update({
|
return this.userService.update({
|
||||||
where: { id: Number(id) },
|
where: { id: Number(id) },
|
||||||
data: data
|
data: data
|
||||||
})
|
})
|
||||||
@ -157,7 +157,7 @@ export class UserController {
|
|||||||
@Roles(ROLE.ADMIN)
|
@Roles(ROLE.ADMIN)
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
async delete(@Param('id') id: string): Promise<User | undefined> {
|
delete(@Param('id') id: string): Promise<User | undefined> {
|
||||||
return await this.userService.remove({ id: Number(id) })
|
return this.userService.remove({ id: Number(id) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ export class UserService {
|
|||||||
where?: Prisma.UserWhereInput
|
where?: Prisma.UserWhereInput
|
||||||
}): Promise<number> {
|
}): Promise<number> {
|
||||||
const { cursor, where } = params
|
const { cursor, where } = params
|
||||||
return await this.prisma.user.count({
|
return this.prisma.user.count({
|
||||||
cursor,
|
cursor,
|
||||||
where
|
where
|
||||||
})
|
})
|
||||||
@ -33,7 +33,7 @@ export class UserService {
|
|||||||
orderBy?: Prisma.UserOrderByWithRelationInput
|
orderBy?: Prisma.UserOrderByWithRelationInput
|
||||||
}): Promise<User[]> {
|
}): Promise<User[]> {
|
||||||
const { skip, take, cursor, where, orderBy } = params
|
const { skip, take, cursor, where, orderBy } = params
|
||||||
return await this.prisma.user.findMany({
|
return this.prisma.user.findMany({
|
||||||
skip,
|
skip,
|
||||||
take,
|
take,
|
||||||
cursor,
|
cursor,
|
||||||
@ -44,12 +44,12 @@ export class UserService {
|
|||||||
|
|
||||||
//단일 조회
|
//단일 조회
|
||||||
async fetchOne(where: Prisma.UserWhereInput): Promise<User | null> {
|
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> {
|
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
|
data: Prisma.UserUpdateInput
|
||||||
}): Promise<User | null> {
|
}): Promise<User | null> {
|
||||||
const { where, data } = params
|
const { where, data } = params
|
||||||
return await this.prisma.user.update({
|
return this.prisma.user.update({
|
||||||
data,
|
data,
|
||||||
where
|
where
|
||||||
})
|
})
|
||||||
@ -66,6 +66,6 @@ export class UserService {
|
|||||||
|
|
||||||
//단일 삭제
|
//단일 삭제
|
||||||
async remove(where: Prisma.UserWhereUniqueInput): Promise<User | null> {
|
async remove(where: Prisma.UserWhereUniqueInput): Promise<User | null> {
|
||||||
return await this.prisma.user.delete({ where })
|
return this.prisma.user.delete({ where })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user