Commit 76ee8ef5 authored by chinguyen's avatar chinguyen

commit

parent 4f6cd08d
...@@ -18,6 +18,15 @@ export function findAll(): Promise<any> { ...@@ -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> { export function deleteUser(code: any): Promise<any> {
return Students.destroy({ return Students.destroy({
where:{code} where:{code}
......
...@@ -7,4 +7,9 @@ export function getAllUsers(req: Request, res: Response) { ...@@ -7,4 +7,9 @@ export function getAllUsers(req: Request, res: Response) {
.findAll() .findAll()
.then(students => res.status(200).send(students)) .then(students => res.status(200).send(students))
.catch(error => res.boom.badRequest(error)) .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
...@@ -3,7 +3,9 @@ import { StudentsController } from '../endpoints/_index' ...@@ -3,7 +3,9 @@ import { StudentsController } from '../endpoints/_index'
export function routes(app: Express) { export function routes(app: Express) {
app.get('/api/getStudents', StudentsController.StudentsGet.getAllUsers) app.get('/api/getStudents', StudentsController.StudentsGet.getAllUsers)
app.get('/api/getStudents?page&pagesize', StudentsController.StudentsGet.getUserBasePagination)
app.post('/api/addStudent', StudentsController.StudentsPost.Add) app.post('/api/addStudent', StudentsController.StudentsPost.Add)
app.delete('/api/deleteStudent/:code', StudentsController.StudentsDelete.deleteUser) app.delete('/api/deleteStudent/:code', StudentsController.StudentsDelete.deleteUser)
app.put('/api/updateStudent/:code',StudentsController.StudentsPut.updateUser) app.put('/api/updateStudent/:code',StudentsController.StudentsPut.updateUser)
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment