|  | @@ -5,6 +5,7 @@ const jwt = require('jsonwebtoken')
 | 
	
		
			
				|  |  |  const { validate } = require('../utils/validation')
 | 
	
		
			
				|  |  |  const axios = require('../utils/axios')
 | 
	
		
			
				|  |  |  const qs = require('qs')
 | 
	
		
			
				|  |  | +const convertRole = require('../utils/convertRole')
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  exports.login = handleError(async (req, res) => {
 | 
	
		
			
				|  |  |    const isValid = validate(res, req.body, {
 | 
	
	
		
			
				|  | @@ -35,28 +36,34 @@ exports.login = handleError(async (req, res) => {
 | 
	
		
			
				|  |  |    let cekUser = await userModel.findOne({
 | 
	
		
			
				|  |  |      user_id: user.id,
 | 
	
		
			
				|  |  |    })
 | 
	
		
			
				|  |  | +  let role =
 | 
	
		
			
				|  |  | +    process.env.ENV === 'production'
 | 
	
		
			
				|  |  | +      ? user.peran.filter(
 | 
	
		
			
				|  |  | +          (e) =>
 | 
	
		
			
				|  |  | +            convertRole(e.peran.id) === 2020 ||
 | 
	
		
			
				|  |  | +            convertRole(e.peran.id) === 2021 ||
 | 
	
		
			
				|  |  | +            convertRole(e.peran.id) === 2022 ||
 | 
	
		
			
				|  |  | +            convertRole(e.peran.id) === 2023
 | 
	
		
			
				|  |  | +        )[0]
 | 
	
		
			
				|  |  | +      : user.peran.filter(
 | 
	
		
			
				|  |  | +          (e) =>
 | 
	
		
			
				|  |  | +            e.peran.id === 2020 ||
 | 
	
		
			
				|  |  | +            e.peran.id === 2021 ||
 | 
	
		
			
				|  |  | +            e.peran.id === 2022 ||
 | 
	
		
			
				|  |  | +            e.peran.id === 2023
 | 
	
		
			
				|  |  | +        )[0]
 | 
	
		
			
				|  |  |    if (!cekUser) {
 | 
	
		
			
				|  |  | -    let role = user.peran[0].peran
 | 
	
		
			
				|  |  |      if (process.env.ENV === 'production') {
 | 
	
		
			
				|  |  |        role = {
 | 
	
		
			
				|  |  | -        id:
 | 
	
		
			
				|  |  | -          role.id === 2024
 | 
	
		
			
				|  |  | -            ? 2020
 | 
	
		
			
				|  |  | -            : role.id === 2025
 | 
	
		
			
				|  |  | -            ? 2021
 | 
	
		
			
				|  |  | -            : role.id === 2026
 | 
	
		
			
				|  |  | -            ? 2022
 | 
	
		
			
				|  |  | -            : role.id === 2027
 | 
	
		
			
				|  |  | -            ? 2023
 | 
	
		
			
				|  |  | -            : role.id,
 | 
	
		
			
				|  |  | -        nama: role.nama,
 | 
	
		
			
				|  |  | -        menu: role.menu,
 | 
	
		
			
				|  |  | +        id: convertRole(role.peran.id),
 | 
	
		
			
				|  |  | +        nama: role.peran.nama,
 | 
	
		
			
				|  |  | +        menu: role.peran.menu,
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      cekUser = await userModel.create({
 | 
	
		
			
				|  |  |        user_id: user.id,
 | 
	
		
			
				|  |  |        nama: user.nama,
 | 
	
		
			
				|  |  | -      lembaga: user.peran[0].organisasi,
 | 
	
		
			
				|  |  | +      lembaga: role.organisasi,
 | 
	
		
			
				|  |  |        email: user.username,
 | 
	
		
			
				|  |  |        no_hp: user.no_hp,
 | 
	
		
			
				|  |  |        alamat: user.alamat,
 | 
	
	
		
			
				|  | @@ -64,6 +71,19 @@ exports.login = handleError(async (req, res) => {
 | 
	
		
			
				|  |  |        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,
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +      await userModel.updateOne({ _id: cekUser._id }, { role })
 | 
	
		
			
				|  |  | +      cekUser = await userModel.findById(cekUser._id)
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const accessToken = jwt.sign({ _id: cekUser._id }, process.env.SECRET, {
 |