Commit 756a4653 authored by chinguyen's avatar chinguyen

Merge branch 'develop' into 'jwt'

# Conflicts:
#   src/config.json
parents 63e28623 c7ec33c7
{ {
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{
"args": [
"task"
],
"name": "Gulp task",
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{ {
"name": "Debug Typescript", "name": "Debug Typescript",
"type": "node", "type": "node",
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
"scripts": { "scripts": {
"build": "gulp build", "build": "gulp build",
"doc": "gulp generate:doc", "doc": "gulp generate:doc",
"start": "cross-env NODE_ENV=development gulp watch", "start": "cross-env NODE_ENV=development gulp watch ",
"start:prod": "cross-env NODE_ENV=production gulp watch", "start:prod": "cross-env NODE_ENV=production gulp watch",
"run:test": "cross-env NODE_ENV=test gulp test", "run:test": "cross-env NODE_ENV=test gulp test",
"tslint": "gulp tslint", "tslint": "gulp tslint",
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
"lint-staged": "10.0.7", "lint-staged": "10.0.7",
"remap-istanbul": "0.13.0", "remap-istanbul": "0.13.0",
"rimraf": "3.0.2", "rimraf": "3.0.2",
"sequelize-cli": "5.5.1", "sequelize-cli": "^5.5.1",
"tslint": "6.0.0", "tslint": "6.0.0",
"typedoc": "0.16.10", "typedoc": "0.16.10",
"typescript": "3.8.2", "typescript": "3.8.2",
......
{ {
"development": { "development": {
"username": "postgres", "username": "postgres",
"password": "meu@sds12@!#gh", "password": "chinguyen@123",
"database": "node_sequelize", "database": "node_sequelize",
"host": "27.74.255.96", "host": "27.74.255.96",
"port": 5430, "port": 5430,
......
import * as uuid from 'uuid' import * as uuid from 'uuid'
import { Students } from './../sqlz/models/students' import { Students } from './../sqlz/models/students'
import { where, Op } from 'sequelize/types';
import { Request, Response } from 'express'
export function create(students: any): Promise<any> { export function create(students: any): Promise<any> {
return Students.create({ return Students.create({
...@@ -18,14 +19,17 @@ export function findAll(): Promise<any> { ...@@ -18,14 +19,17 @@ export function findAll(): Promise<any> {
} }
export function findStudentPagination(page: any, pagesize: any): Promise<any>{ export function findStudentPagination (page:any, pagesize:any): Promise<any>{
return Students.findAll({ return Students.findAndCountAll({
offset: (page - 1 ) * pagesize, offset: (page - 1 ) * pagesize,
limit: pagesize limit: pagesize
//offset: 1,
//limit: 2
}) })
} }
export function deleteUser(code: any): Promise<any> { export function deleteUser(code: any): Promise<any> {
return Students.destroy({ return Students.destroy({
......
...@@ -2,14 +2,14 @@ import { Request, Response } from 'express' ...@@ -2,14 +2,14 @@ import { Request, Response } from 'express'
import { StudentDao } from '../../dao/_index' import { StudentDao } from '../../dao/_index'
export function getAllUsers(req: Request, res: Response) { export function getAllUsers(req: Request, res: Response) {
return StudentDao return StudentDao
.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){ export function getUserBasePagination(req: Request, res: Response) {
return StudentDao.findStudentPagination(req.query.page, req.query.pagesize) return StudentDao.findStudentPagination(req.query.page, req.query.pagesize)
.then(students => res.status(200).send(students)) .then(students => res.status(200).send(students.rows))
} }
...@@ -2,8 +2,8 @@ import { Express } from 'express' ...@@ -2,8 +2,8 @@ import { Express } from 'express'
import { StudentsController } from '../endpoints/_index' 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/students/all', StudentsController.StudentsGet.getAllUsers)
app.get('/api/getStudents?page&pagesize', StudentsController.StudentsGet.getUserBasePagination) app.get('/api/students/paging*', 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)
......
{ {
"development": { "development": {
"username": "postgres", "username": "postgres",
"password": "chinguyen", "password": "chinguyen@123",
"database": "node_sequelize", "database": "node_sequelize",
"host": "127.0.0.1", "host": "127.0.0.1",
"port": 5432, "port": 5432,
......
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