Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | 13x 13x 13x 13x 1x 1x 1x 13x 1x 1x 1x 12x 12x 1x 1x 1x 13x 1x 1x 1x 13x 1x 1x 1x 12x 1x 1x 1x 13x 1x 1x 1x 13x 1x 1x 1x 13x 12x 12x 1x 1x 1x 13x 12x 12x 1x 1x 1x 13x 12x 12x 1x 1x 1x 13x 13x 13x 13x 13x 11x 2x 2x 13x | /* eslint-disable no-restricted-syntax */ import moment from 'moment-timezone'; import validator from 'validator'; import { t } from '../../helpers/i18n'; import DepartmentInformation from '../departments/information'; import UserFunctionInformation from '../userFunctions/information'; import WorkShiftInformation from '../workShifts/information'; import UserCreate from './create'; import UserInformation from './information'; async function validUser(user) { let isValid = true; let code = ''; let message = ''; if (user.email && !validator.isEmail(user.email)) { isValid = false; code = 9001; message = t('BEE1254', { 0: user.email } /* Email %{0} inválido ! */); } if (!user.login) { isValid = false; code = 9002; message = t('BEE1362' /* Login deve ser informado ! */); } else { const existUser = await UserInformation.getUser({ login: user.login, }); if (existUser) { isValid = false; code = 9003; message = t('BEE636', { 0: user.login } /* Login %{0} já cadastrado */); } } if (!user.name) { isValid = false; code = 9004; message = t('BEE1259' /* Nome deve ser informado ! */); } if (!user.type) { isValid = false; code = 9005; message = t('BEE1260' /* Tipo usuário deve ser informado ! */); } else if (user.type > 4) { isValid = false; code = 9006; message = t('BEE1261', { 0: user.type } /* Tipo usuário %{0} inválido ! */); } if (!user.password) { isValid = false; code = 9007; message = t('BEE1256' /* Senha deve ser informada ! */); } if ( user.passValid && !validator.toDate(moment(user.passValid, 'DD/MM/YYYY', true).format()) ) { isValid = false; code = 9008; message = t( 'BEE1366', { 0: user.passValid, } /* Validade da senha %{0} com problema no formato! 'DD/MM/YYYY' */ ); } if (user.department) { const existDepartment = await DepartmentInformation.getDepartment({ code: user.department, }); if (!existDepartment) { isValid = false; code = 9010; message = t( 'BEE1262', { 0: user.department } /* Departamento %{0} inválido ! */ ); } } if (user.userFunction) { const existFunction = await UserFunctionInformation.getUserFunction({ code: user.userFunction, }); if (!existFunction) { isValid = false; code = 9011; message = t( 'BEE1263', { 0: user.userFunction } /* Cargo %{0} inválido ! */ ); } } if (user.workShift) { const existWorkShift = await WorkShiftInformation.getWorkShift({ code: user.workShift, }); if (!existWorkShift) { isValid = false; code = 9012; message = t('BEE1264', { 0: user.workShift } /* Turno %{0} inválido ! */); } } return { isValid, code, message, }; } async function importUsers(users, userId) { const listUsersErrors = []; for (const user of users) { const valid = await validUser(user); if (!valid.isValid) { listUsersErrors.push({ login: user.login, error: valid.code, message: valid.message, }); } else { const newUser = { email: user.email, login: user.login, name: user.name, type: user.type, status: true, password: user.password, passValid: user.passValid ? moment(user.passValid, 'DD/MM/YYYY', true).format() : new Date(moment().add(90, 'days').format('MM/DD/YYYY')), department: user.department, userFunction: user.userFunction, workShift: user.workShift, accessProfile: user.accessProfile, printer: user.printer, userBranches: user.userBranches.toString(), mainBranch: user.mainBranch, note: user.note, createdUser: userId, updatedUser: userId, }; await UserCreate.createUser(newUser); } } return { listUsersErrors }; } export default { importUsers, }; |