Skip to content

Commit

Permalink
Refactor profile.
Browse files Browse the repository at this point in the history
  • Loading branch information
HranikBs23 committed Feb 23, 2022
1 parent 4883cf7 commit 866f62d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/modules/platform/profile/profile.controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path');
const Profile = require('./profile.model');
const Permission = require(path.join(process.cwd(), 'src/modules/platform/permission/permission.model'));
const User = require(path.join(process.cwd(), 'src/modules/platform/user/user.model'));
const ProfilePermission = require(path.join(process.cwd(), 'src/modules/platform/permission/profile-permission.model'));
const { makeCustomSlug } = require(path.join(process.cwd(), 'src/modules/core/services/slug'));
const { Op } = require('sequelize');
Expand Down Expand Up @@ -64,7 +65,17 @@ async function getProfiles(req, res) {
attributes: ["id", "title", "slug"]
}
]
}
},
{
model: User,
as: "createdByUser",
attributes: ["id", "first_name", "last_name"]
},
{
model: User,
as: "updatedByUser",
attributes: ["id", "first_name", "last_name"]
},
]
});

Expand Down Expand Up @@ -106,8 +117,18 @@ async function getProfile(req, res) {
as: "permission",
attributes: ["id", "title", "slug"]
}
]
}
],
},
{
model: User,
as: "createdByUser",
attributes: ["id", "first_name", "last_name"]
},
{
model: User,
as: "updatedByUser",
attributes: ["id", "first_name", "last_name"]
},
]
});

Expand Down
3 changes: 3 additions & 0 deletions src/modules/platform/user/user.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ Profile.belongsTo(User, { as: "updatedByUser", foreignKey: "updated_by" });
Role.hasMany(User, { as: 'users', foreignKey: 'role_id' });
User.belongsTo(Role, { as: 'role', foreignKey: 'role_id' });

Role.belongsTo(User, { as: "createdByUser", foreignKey: "created_by" });
Role.belongsTo(User, { as: "updatedByUser", foreignKey: "updated_by" });

Permission.belongsTo(User, { as: 'createdByUser', foreignKey: 'created_by' });
Permission.belongsTo(User, { as: 'updatedByUser', foreignKey: 'created_by' });

Expand Down

0 comments on commit 866f62d

Please sign in to comment.