From 76ee8ef5ac8a194ede6e72f8ceb11cb95e4886e5 Mon Sep 17 00:00:00 2001 From: chinguyen <chinguyen@meu-solutions.com> Date: Fri, 5 Feb 2021 18:00:14 +0700 Subject: [PATCH] commit --- src/dao/students.ts | 9 +++++++++ src/endpoints/students/students.get.ts | 5 +++++ src/routes/students.ts | 2 ++ 3 files changed, 16 insertions(+) diff --git a/src/dao/students.ts b/src/dao/students.ts index 8c83acc..a8182c4 100644 --- a/src/dao/students.ts +++ b/src/dao/students.ts @@ -18,6 +18,15 @@ export function findAll(): Promise<any> { } +export function findStudentPagination(page: any, pagesize: any): Promise<any>{ + return Students.findAll({ + offset: (page - 1 ) * pagesize, + limit: pagesize + + }) + +} + export function deleteUser(code: any): Promise<any> { return Students.destroy({ where:{code} diff --git a/src/endpoints/students/students.get.ts b/src/endpoints/students/students.get.ts index cd2fd52..2062ddc 100644 --- a/src/endpoints/students/students.get.ts +++ b/src/endpoints/students/students.get.ts @@ -7,4 +7,9 @@ export function getAllUsers(req: Request, res: Response) { .findAll() .then(students => res.status(200).send(students)) .catch(error => res.boom.badRequest(error)) +} + +export function getUserBasePagination(req: Request, res: Response){ + return StudentDao.findStudentPagination(req.query.page, req.query.pagesize) + .then(students => res.status(200).send(students)) } \ No newline at end of file diff --git a/src/routes/students.ts b/src/routes/students.ts index 21f33bd..6f4dcaa 100644 --- a/src/routes/students.ts +++ b/src/routes/students.ts @@ -3,7 +3,9 @@ import { StudentsController } from '../endpoints/_index' export function routes(app: Express) { app.get('/api/getStudents', StudentsController.StudentsGet.getAllUsers) + app.get('/api/getStudents?page&pagesize', StudentsController.StudentsGet.getUserBasePagination) app.post('/api/addStudent', StudentsController.StudentsPost.Add) app.delete('/api/deleteStudent/:code', StudentsController.StudentsDelete.deleteUser) app.put('/api/updateStudent/:code',StudentsController.StudentsPut.updateUser) + } \ No newline at end of file -- 2.18.1