Skip to content

Commit

Permalink
feat: unify models
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisSenicourt committed May 15, 2024
1 parent 72add25 commit 80007d0
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 98 deletions.
2 changes: 1 addition & 1 deletion controllers/POIController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const POI = require('../models/POIModel');
const POI = require('../models').POI;

// Méthode pour créer un nouveau POI
exports.createPOI = async (req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion controllers/cityController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const City = require('../models/cityModel');
const City = require('../models').City;

// Méthode pour créer une nouvelle ville
exports.createCity = async (req, res) => {
Expand Down
2 changes: 1 addition & 1 deletion controllers/userController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const User = require('../models/userModel');
const User = require('../models').CMSUser;
const TokenService = require('../service/token');
const bcrypt = require('bcrypt');

Expand Down
44 changes: 0 additions & 44 deletions models/POIModel.js

This file was deleted.

30 changes: 0 additions & 30 deletions models/cityModel.js

This file was deleted.

88 changes: 88 additions & 0 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const { DataTypes } = require('sequelize');
const sequelize = require('../service/database');

const City = sequelize.define('City', {
ID: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
CityName: {
type: DataTypes.STRING(255),
allowNull: false
},
Latitude: {
type: DataTypes.DECIMAL(10, 8),
allowNull: false
},
Longitude: {
type: DataTypes.DECIMAL(11, 8),
allowNull: false
},
Reach: {
type: DataTypes.INTEGER,
allowNull: false
}
});

const POI = sequelize.define('POI', {
ID: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
CityId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: City,
key: 'ID'
}
},
Name: {
type: DataTypes.STRING(255),
allowNull: false
},
Latitude: {
type: DataTypes.DECIMAL(10, 8),
allowNull: false
},
Longitude: {
type: DataTypes.DECIMAL(11, 8),
allowNull: false
},
Description: {
type: DataTypes.TEXT,
allowNull: false
}
});

const CMSUser = sequelize.define('CMSUser', {
ID: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
Mail: {
type: DataTypes.STRING,
allowNull: false,
unique: true
},
Password: {
type: DataTypes.STRING,
allowNull: false
}
});

// Association entre les villes et les POIs
City.hasMany(POI, {
foreignKey: 'CityId',
onDelete: 'CASCADE',
hooks: true
});

module.exports = {
City,
POI,
CMSUser,
}
21 changes: 0 additions & 21 deletions models/userModel.js

This file was deleted.

0 comments on commit 80007d0

Please sign in to comment.