Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- module.exports = {
- up: (queryInterface, Sequelize) => {
- return queryInterface.createTable('Usuarios', {
- username: {
- type: Sequelize.STRING,
- primaryKey:true,
- allowNull:false,
- validate:{
- max:25
- }
- },
- primerNombre: {
- type: Sequelize.STRING,
- validate:{
- max:25
- }
- },
- segundoNombre: {
- type: Sequelize.STRING,
- validate:{
- max:25
- }
- },
- primerApellido: {
- type: Sequelize.STRING,
- validate:{
- max:25
- }
- },
- segundoapellido: {
- type: Sequelize.STRING,
- validate:{
- max:25
- }
- },
- direccion: {
- type: Sequelize.STRING,
- validate:{
- max:250
- }
- },
- telefono: {
- type: Sequelize.INTEGER,
- validate:{
- max:8
- }
- },
- password: {
- type: Sequelize.STRING,
- validate:{
- min:8
- },
- allowNull:false
- },
- admin:{
- type:Sequelize.BOOLEAN,
- allowNull: false,
- },
- createdAt: {
- allowNull: false,
- type: Sequelize.DATE
- },
- updatedAt: {
- allowNull: false,
- type: Sequelize.DATE
- }
- },
- {
- charset:'utf8'
- }
- );
- },
- down: (queryInterface, Sequelize) => {
- return queryInterface.dropTable('Usuarios');
- }
- };
- var express = require('express');
- router = express.Router();
- var model = require('../models/index');
- router.post('/',function(req,res,next){
- console.log("entramos a este evento");
- model.Usuario.create({
- username:req.body.username,
- primerNombre: req.body.primerNombre,
- segundoNombre: req.body.segundoNombre,
- primerApellido: req.body.primerApellido,
- segundoapellido: req.body.segundoapellido,
- direccion: req.body.direccion,
- telefono: req.body.telefono,
- password: req.body.password
- }).then(usuario => res.status(201).json({
- error: false,
- data: usuario,
- message: 'New user is been created'
- }))
- .catch(error => res.json({
- error:true,
- data:[],
- error:error
- }))
- });
- module.exports = router;
Add Comment
Please, Sign In to add comment