|
|
@@ -41,9 +41,10 @@ exports.login = handleError(async (req, res) => {
|
|
|
process.env.ENV === 'production'
|
|
|
? user.peran.filter((e) => roleData.includes(convertRole(e.peran.id)))[0]
|
|
|
: user.peran.filter((e) => roleData.includes(e.peran.id))[0]
|
|
|
+ let dataRole = {}
|
|
|
if (!cekUser) {
|
|
|
if (process.env.ENV === 'production') {
|
|
|
- role = {
|
|
|
+ dataRole = {
|
|
|
id: convertRole(role.peran.id),
|
|
|
nama: role.peran.nama,
|
|
|
menu: role.peran.menu,
|
|
|
@@ -56,22 +57,29 @@ exports.login = handleError(async (req, res) => {
|
|
|
email: user.username,
|
|
|
no_hp: user.no_hp,
|
|
|
alamat: user.alamat,
|
|
|
- role,
|
|
|
+ role: dataRole,
|
|
|
isPublic: false,
|
|
|
isPrivate: false,
|
|
|
})
|
|
|
} else {
|
|
|
- if (
|
|
|
- process.env.ENV === 'production' &&
|
|
|
- cekUser.role.id !== convertRole(role.peran.id)
|
|
|
- ) {
|
|
|
- role = {
|
|
|
- id: convertRole(role.peran.id),
|
|
|
- nama: role.peran.nama,
|
|
|
- menu: role.peran.menu,
|
|
|
+ if (process.env.ENV === 'production') {
|
|
|
+ if (cekUser.role.id !== convertRole(role.peran.id)) {
|
|
|
+ dataRole = {
|
|
|
+ id: convertRole(role.peran.id),
|
|
|
+ nama: role.peran.nama,
|
|
|
+ menu: role.peran.menu,
|
|
|
+ }
|
|
|
+ await userModel.updateOne({ _id: cekUser._id }, { role: dataRole })
|
|
|
+ }
|
|
|
+ if (!cekUser.lembaga) {
|
|
|
+ await userModel.updateOne(
|
|
|
+ { _id: cekUser._id },
|
|
|
+ { lembaga: role.organisasi }
|
|
|
+ )
|
|
|
}
|
|
|
- await userModel.updateOne({ _id: cekUser._id }, { role })
|
|
|
- cekUser = await userModel.findById(cekUser._id)
|
|
|
+ cekUser = await userModel.findOne({
|
|
|
+ user_id: user.id,
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
|