nestjs_auth init..

This commit is contained in:
최준흠 2022-09-10 22:00:40 +09:00
parent c911b75b27
commit 7ce649bb74
2 changed files with 17 additions and 17 deletions

View File

@ -17,7 +17,7 @@ export class TodoController {
constructor(private readonly todoService: TodoService) {} constructor(private readonly todoService: TodoService) {}
@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용
@ -106,8 +106,8 @@ export class TodoController {
console.log(fetchSQL) console.log(fetchSQL)
//전체 갯수 및 fetched Data //전체 갯수 및 fetched Data
const total = await this.todoService.count(fetchSQL) const total = this.todoService.count(fetchSQL)
const rows = await this.todoService.fetchAll(fetchSQL) const rows = this.todoService.fetchAll(fetchSQL)
const result = { const result = {
total: total, total: total,
perPage: perPage, perPage: perPage,
@ -122,26 +122,26 @@ export class TodoController {
} }
@Get(':id') @Get(':id')
async fetchOne(@Param('id') id: string): Promise<Todo | undefined> { fetchOne(@Param('id') id: string): Promise<Todo | undefined> {
return await this.todoService.fetchOne({ id: Number(id) }) return this.todoService.fetchOne({ id: Number(id) })
} }
@Post() @Post()
async add(@Body() data: TodoDTO): Promise<Todo> { add(@Body() data: TodoDTO): Promise<Todo> {
return await this.todoService.add(data) return this.todoService.add(data)
} }
@Put(':id') @Put(':id')
async update(@Param('id') id: string, @Body() data: TodoDTO): Promise<Todo> { update(@Param('id') id: string, @Body() data: TodoDTO): Promise<Todo> {
data.updatedAt = new Date() data.updatedAt = new Date()
return await this.todoService.update({ return this.todoService.update({
where: { id: Number(id) }, where: { id: Number(id) },
data: data data: data
}) })
} }
@Delete(':id') @Delete(':id')
async delete(@Param('id') id: string): Promise<Todo | undefined> { delete(@Param('id') id: string): Promise<Todo | undefined> {
return await this.todoService.remove({ id: Number(id) }) return this.todoService.remove({ id: Number(id) })
} }
} }

View File

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