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

View File

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