Skip to content

Commit

Permalink
update: version v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekall committed Feb 23, 2022
1 parent d3bc5e0 commit 9a11382
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 12 deletions.
8 changes: 4 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const express = require("express")
const morgan = require("morgan")
const bodyParser = require("body-parser")
const favicon = require("serve-favicon")
const sequelize = require("./src/db/sequelize")
const sequelize = require("./db/sequelize")
const cors = require("cors")

const app = express()
Expand All @@ -16,9 +16,9 @@ app

sequelize.initDb()

require("./src/routes/initial")(app)
require("./src/routes/login")(app)
require("./src/routes/register")(app)
require("./routes/initial")(app)
require("./routes/login")(app)
require("./routes/register")(app)

app.use(({res}) =>{
const message = "Impossible de trouver la ressource demandée ! Veuillez essayer une autre URL."
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions migrations/20220223205033-create-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('Users', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
username: {
type: Sequelize.STRING
},
firstName: {
type: Sequelize.STRING
},
lastName: {
type: Sequelize.STRING
},
email: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('Users');
}
};
32 changes: 24 additions & 8 deletions src/models/user.js → models/user.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
'use strict';
const {
Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
return sequelize.define('User', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
class User extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
// define association here
}
}
User.init({
username: {
type: DataTypes.STRING,
allowNull: false,
Expand All @@ -16,6 +25,9 @@ module.exports = (sequelize, DataTypes) => {
notEmpty: { msg: "Le nom d'un utilisateur ne peut être vide."}
}
},
firstName: DataTypes.STRING,
lastName: DataTypes.STRING,
email: DataTypes.STRING,
password: {
type: DataTypes.STRING,
allowNull: false,
Expand All @@ -24,5 +36,9 @@ module.exports = (sequelize, DataTypes) => {
notEmpty: { msg: "Le mot de passe ne peut être vide."}
}
}
})
}
}, {
sequelize,
modelName: 'User',
});
return User;
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 9a11382

Please sign in to comment.