Commit 840e93d9 authored by chinguyen's avatar chinguyen

commit

parent edd4a923
import * as LanguagesDao from './languages' import * as LanguagesDao from './languages'
import * as AppUserDao from './appusers' import * as AppUserDao from './appusers'
import * as StudentDao from './students'
export { LanguagesDao } export { LanguagesDao }
export { AppUserDao } export { AppUserDao }
export { StudentDao }
import * as uuid from 'uuid'
import { Students } from './../sqlz/models/students';
export function create(students: any): Promise<any>{
return Students.create({
id: uuid.v1(),
firstname: students.firstname,
lastname: students.lastname,
email: students.email,
sdt: students.sdt
})
}
export function findAll(): Promise<any>{
return Students.findAll()
}
export function deleteUser(id: any): Promise<any>{
return Students.destroy({
where: {id: id}
})
}
import * as LanguageController from './languages/_index' import * as LanguageController from './languages/_index'
import * as AppUserController from './appusers/_index' import * as AppUserController from './appusers/_index'
import * as StudentsController from './students/_index'
export { LanguageController, AppUserController } export { LanguageController, AppUserController, StudentsController }
import * as StudentsGet from './students.get'
import * as StudentsPost from './students.post'
import * as StudentsDelete from './students.delete'
export { StudentsGet, StudentsPost, StudentsDelete }
\ No newline at end of file
import { Request, Response } from 'express'
import { StudentDao } from '../../dao/_index'
export function deleteUser(req: Request, res: Response){
return StudentDao.deleteUser(req.params.id).then(res.status(202).send({
message: 'delete successfull'
})).catch(error => res.boom.badRequest(error))
}
\ No newline at end of file
import { Request, Response } from 'express'
import { StudentDao } from '../../dao/_index'
export function getAllUsers(req: Request, res: Response){
return StudentDao
.findAll()
.then(students => res.status(200).send(students))
.catch(error => res.boom.badRequest(error))
}
\ No newline at end of file
import { Request, Response } from 'express'
import { StudentDao } from '../../dao/_index'
export function Add(req: Request, res: Response){
return StudentDao
.create(req.body)
.then(students => res.status(201).send(students))
.catch(error => res.boom.badRequest(error))
}
\ No newline at end of file
...@@ -2,6 +2,7 @@ import * as winston from 'winston' ...@@ -2,6 +2,7 @@ import * as winston from 'winston'
import { Express, Request, Response } from 'express' import { Express, Request, Response } from 'express'
import * as LanguagesRoutes from './languages' import * as LanguagesRoutes from './languages'
import * as AppUserRoutes from './appusers' import * as AppUserRoutes from './appusers'
import * as StudentsRoutes from './students'
export function initRoutes(app: Express) { export function initRoutes(app: Express) {
winston.log('info', '--> Initialisations des routes') winston.log('info', '--> Initialisations des routes')
...@@ -12,6 +13,7 @@ export function initRoutes(app: Express) { ...@@ -12,6 +13,7 @@ export function initRoutes(app: Express) {
LanguagesRoutes.routes(app) LanguagesRoutes.routes(app)
AppUserRoutes.routes(app) AppUserRoutes.routes(app)
StudentsRoutes.routes(app)
app.all('*', (req: Request, res: Response) => res.boom.notFound()) app.all('*', (req: Request, res: Response) => res.boom.notFound())
} }
import { Express } from 'express'
import { StudentsController } from '../endpoints/_index'
export function routes(app: Express){
app.get('/api/getStudents', StudentsController.StudentsGet.getAllUsers)
app.post('/api/addStudent', StudentsController.StudentsPost.Add)
app.delete('/api/deleteStudent', StudentsController.StudentsDelete.deleteUser)
}
\ No newline at end of file
'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('Students', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
firstname: {
type: Sequelize.STRING
},
lastname: {
type: Sequelize.STRING
},
email: {
type: Sequelize.STRING
},
sdt: {
type: Sequelize.NUMBER
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('Students');
}
};
\ No newline at end of file
import { Model, STRING, UUID, Deferrable,NUMBER } from 'sequelize'
import sequelize from './_index'
export class Students extends Model {
}
export class StudentsModel {
id: string
firstname: string
lastname: string
email: string
sdt: number
}
Students.init({
firstname: STRING(50),
lastname: STRING(50),
email: STRING(50),
sdt: NUMBER
}, {
sequelize,
modelName: 'Students',
})
\ 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