diff --git a/.env b/.env index c73643c..71e3837 100644 --- a/.env +++ b/.env @@ -4,4 +4,8 @@ # 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 -DATABASE_URL="mysql://root:@localhost:3306/test" \ No newline at end of file +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 diff --git a/src/auth/guards/constants.ts b/src/auth/guards/constants.ts index 53a2898..8248ece 100644 --- a/src/auth/guards/constants.ts +++ b/src/auth/guards/constants.ts @@ -1,4 +1,6 @@ +import { env } from 'process' + export const jwtConstants = { - secret: 'security-key', - expiresIn: '60s' + secret: env.JWT_SECURITY_KEY, + expiresIn: env.JWT_EXPIRE_MAX } diff --git a/src/todo/todo.controller.ts b/src/todo/todo.controller.ts index 6b7831d..1d14a3b 100644 --- a/src/todo/todo.controller.ts +++ b/src/todo/todo.controller.ts @@ -9,6 +9,7 @@ import { Query } from '@nestjs/common' import { Todo } from '@prisma/client' +import { env } from 'process' import { TodoDTO } from './dtos/todo.dto' import { TodoService } from './todo.service' @@ -18,10 +19,27 @@ export class TodoController { @Get() async fetchAll(@Query() query): Promise { + 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 = { - take: isNaN(query.per_page) ? 20 : Number(query.per_page), - skip: isNaN(query.page) ? 0 : Number(query.page) * query.per_page, - //where: { is_done: true }, + take: take, + skip: skip, + where: { + //is_done: true, + ...search + }, orderBy: { id: 'desc' } } //console.log(query)