1번째 수정..
This commit is contained in:
parent
edab9b2b0f
commit
ca7d09b4c2
6
.env
6
.env
@ -4,4 +4,8 @@
|
|||||||
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
|
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
|
||||||
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
|
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
|
||||||
|
|
||||||
DATABASE_URL="mysql://root:@localhost:3306/test"
|
DATABASE_URL="mysql://root:@localhost:3306/test"
|
||||||
|
JWT_SECURITY_KEY = "security_key"
|
||||||
|
JWT_EXPIRE_MAX = "60s"
|
||||||
|
DEFAULT_TABLE_PER_PAGE = 20
|
||||||
|
DEFAULT_TABLE_PAGE = 0
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
|
import { env } from 'process'
|
||||||
|
|
||||||
export const jwtConstants = {
|
export const jwtConstants = {
|
||||||
secret: 'security-key',
|
secret: env.JWT_SECURITY_KEY,
|
||||||
expiresIn: '60s'
|
expiresIn: env.JWT_EXPIRE_MAX
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import {
|
|||||||
Query
|
Query
|
||||||
} from '@nestjs/common'
|
} from '@nestjs/common'
|
||||||
import { Todo } from '@prisma/client'
|
import { Todo } from '@prisma/client'
|
||||||
|
import { env } from 'process'
|
||||||
import { TodoDTO } from './dtos/todo.dto'
|
import { TodoDTO } from './dtos/todo.dto'
|
||||||
import { TodoService } from './todo.service'
|
import { TodoService } from './todo.service'
|
||||||
|
|
||||||
@ -18,10 +19,27 @@ export class TodoController {
|
|||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async fetchAll(@Query() query): Promise<Todo[]> {
|
async fetchAll(@Query() query): Promise<Todo[]> {
|
||||||
|
const take: number = isNaN(query.per_page)
|
||||||
|
? Number(env.DEFAULT_TABLE_PER_PAGE)
|
||||||
|
: Number(query.per_page)
|
||||||
|
const skip: number = isNaN(query.page)
|
||||||
|
? Number(env.DEFAULT_TABLE_PAGE)
|
||||||
|
: Number(query.page) * take
|
||||||
|
const search = query.searchString
|
||||||
|
? {
|
||||||
|
OR: [
|
||||||
|
{ title: { contains: query.searchString as string } },
|
||||||
|
{ content: { contains: query.searchString as string } }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
: {}
|
||||||
const sql = {
|
const sql = {
|
||||||
take: isNaN(query.per_page) ? 20 : Number(query.per_page),
|
take: take,
|
||||||
skip: isNaN(query.page) ? 0 : Number(query.page) * query.per_page,
|
skip: skip,
|
||||||
//where: { is_done: true },
|
where: {
|
||||||
|
//is_done: true,
|
||||||
|
...search
|
||||||
|
},
|
||||||
orderBy: { id: 'desc' }
|
orderBy: { id: 'desc' }
|
||||||
}
|
}
|
||||||
//console.log(query)
|
//console.log(query)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user