Skip to content

Commit

Permalink
Change id to uuid.
Browse files Browse the repository at this point in the history
  • Loading branch information
HranikBs23 committed Feb 21, 2022
1 parent 0868e0a commit 7ff9101
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 26 deletions.
15 changes: 10 additions & 5 deletions src/modules/platform/permission/permission-service.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ const Service = require(path.join(process.cwd(), 'src/modules/platform/service/s
const { DataTypes } = require('sequelize');

const PermissionService = sequelize.define('permission_services', {
permission_id: { //FK of permission table
type: DataTypes.INTEGER
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
service_id: { //FK of service table
type: DataTypes.INTEGER
permission_id: {
type: DataTypes.UUID
},
service_id: {
type: DataTypes.UUID
},
}, {
tableName: 'permission_services',
Expand All @@ -20,7 +26,6 @@ const PermissionService = sequelize.define('permission_services', {
});

Permission.hasMany(PermissionService, { as: "permission_services", foreignKey: "permission_id" });
// Permission.belongsToMany(Service, { through: PermissionService, foreignKey: "permission_id", otherKey: "service_id" });
PermissionService.belongsTo(Permission, { as: "permission", foreignKey: "permission_id" });
PermissionService.belongsTo(Service, { as: "service", foreignKey: "service_id" });

Expand Down
10 changes: 8 additions & 2 deletions src/modules/platform/permission/permission.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ const sequelize = require(path.join(process.cwd(), 'src/config/lib/sequelize'));
const { DataTypes } = require('sequelize');

const Permission = sequelize.define('permissions', {
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
title: {
type: DataTypes.STRING(50)
},
Expand All @@ -18,10 +24,10 @@ const Permission = sequelize.define('permissions', {
type: DataTypes.STRING(500)
},
created_by: {
type: DataTypes.INTEGER
type: DataTypes.UUID
},
updated_by: {
type: DataTypes.INTEGER
type: DataTypes.UUID
}
}, {
tableName: 'permissions',
Expand Down
10 changes: 8 additions & 2 deletions src/modules/platform/permission/profile-permission.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ const Permission = require(path.join(process.cwd(), 'src/modules/platform/permis
const { DataTypes } = require('sequelize');

const ProfilePermission = sequelize.define('profile_permissions', {
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
permission_id: {
type: DataTypes.INTEGER
type: DataTypes.UUID
},
profile_id: {
type: DataTypes.INTEGER
type: DataTypes.UUID
},
}, {
tableName: 'profile_permissions',
Expand Down
15 changes: 10 additions & 5 deletions src/modules/platform/permission/role-permission.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ const Role = require(path.join(process.cwd(), 'src/modules/platform/role/role.mo
const { DataTypes } = require('sequelize');

const RolePermission = sequelize.define('role_permissions', {
permission_id: { //FK of permission table
type: DataTypes.INTEGER
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
role_id: { //FK of role table
type: DataTypes.INTEGER
permission_id: {
type: DataTypes.UUID
},
role_id: {
type: DataTypes.UUID
},
}, {
tableName: 'role_permissions',
Expand All @@ -19,7 +25,6 @@ const RolePermission = sequelize.define('role_permissions', {
updatedAt: 'updated_at'
});

// Permission.hasMany(RolePermission, { as: "role_permissions", foreignKey: "permission_id" });
RolePermission.belongsTo(Permission, { as: "permission", foreignKey: "permission_id" });
Role.hasMany(RolePermission, { as: "role_permissions", foreignKey: "role_id" });

Expand Down
10 changes: 8 additions & 2 deletions src/modules/platform/profile/profile.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const Permission = require(path.join(process.cwd(), 'src/modules/platform/permis
const { DataTypes } = require('sequelize');

const Profile = sequelize.define('profiles', {
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
title: {
type: DataTypes.STRING(50)
},
Expand All @@ -20,10 +26,10 @@ const Profile = sequelize.define('profiles', {
type: DataTypes.STRING(500)
},
created_by: {
type: DataTypes.INTEGER
type: DataTypes.UUID
},
updated_by: {
type: DataTypes.INTEGER
type: DataTypes.UUID
}
}, {
tableName: 'profiles',
Expand Down
10 changes: 8 additions & 2 deletions src/modules/platform/role/role.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ const sequelize = require(path.join(process.cwd(), 'src/config/lib/sequelize'));
const { DataTypes } = require('sequelize');

const Role = sequelize.define('roles', {
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
title: {
type: DataTypes.STRING(50),
allowNull: false,
Expand All @@ -21,10 +27,10 @@ const Role = sequelize.define('roles', {
allowNull: true
},
created_by: {
type: DataTypes.INTEGER
type: DataTypes.UUID
},
updated_by: {
type: DataTypes.INTEGER
type: DataTypes.UUID
}
}, {
tableName: 'roles',
Expand Down
10 changes: 8 additions & 2 deletions src/modules/platform/service/service.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ const sequelize = require(path.join(process.cwd(), "src/config/lib/sequelize"));
const { DataTypes } = require('sequelize');

const service = sequelize.define('services', {
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
title: {
allowNull: false,
type: DataTypes.STRING,
Expand All @@ -12,10 +18,10 @@ const service = sequelize.define('services', {
type: DataTypes.STRING,
},
created_by: {
type: DataTypes.INTEGER
type: DataTypes.UUID
},
updated_by: {
type: DataTypes.INTEGER
type: DataTypes.UUID
},
}, {
tabletitle: 'services',
Expand Down
14 changes: 12 additions & 2 deletions src/modules/platform/user/user.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ const { DataTypes } = require("sequelize");
const Profile = require(path.join(process.cwd(), "src/modules/platform/profile/profile.model"));
const Role = require(path.join(process.cwd(), "src/modules/platform/role/role.model"));
const User = sequelize.define("users", {
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
profile_id: {
type: DataTypes.INTEGER,
allowNull: true
allowNull: true,
type: DataTypes.UUID
},
role_id: {
allowNull: true,
type: DataTypes.UUID
},
first_name: {
allowNull: true,
Expand Down
10 changes: 8 additions & 2 deletions src/modules/product/category.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ const sequelize = require(path.join(process.cwd(), "src/config/lib/sequelize"));
const { DataTypes } = require('sequelize');

const Category = sequelize.define('categories', {
shop_id: { // Foreign key of shops table
type: DataTypes.INTEGER
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
shop_id: {
type: DataTypes.UUID
},
name: {
type: DataTypes.STRING(50)
Expand Down
10 changes: 8 additions & 2 deletions src/modules/review/review.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ const sequelize = require(path.join(process.cwd(), "src/config/lib/sequelize"));
const { DataTypes } = require("sequelize");

const Review = sequelize.define("reviews", {
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
customer_id: {
type: DataTypes.INTEGER
type: DataTypes.UUID
},
product_id: {
type: DataTypes.INTEGER
type: DataTypes.UUID
},
rating: {
type: DataTypes.INTEGER
Expand Down

0 comments on commit 7ff9101

Please sign in to comment.