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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | 3x 3x 1x 2x 2x 1x 2x 2x 1x 3x 3x 1x 2x 2x 1x 2x 2x 1x 2x 2x 1x 2x 2x 1x 2x 2x 1x 3x 3x 1x 2x 1x 3x 3x 2x 2x 1x 3x 3x 2x 2x 1x 3x 3x 2x 2x 1x 3x 3x 2x 2x 1x 2x 2x 1x 1x 3x 3x 3x 1x 2x 2x 2x 1x 2x 2x 2x 1x 5x 5x 5x 5x 5x 2x 3x 3x 3x 3x 3x 2x 2x 1x 2x | import validator from 'validator'; import APIError from '../helpers/error'; import { t } from '../helpers/i18n'; import { passwordSHA256 } from '../helpers/validators/password'; import BranchInformation from '../source/branches/information'; import DepartmentInformation from '../source/departments/information'; import PasswordHistoryInformation from '../source/passwordHistory/information'; import UserFunctionInformation from '../source/userFunctions/information'; import UserInformation from '../source/users/information'; import WorkShiftInformation from '../source/workShifts/information'; import PrinterInformation from '../source/printers/information'; async function validUserId(req) { const userId = req.userId || req.body.userId || req.query.userId || req.body.id || req.query.id; if (!userId) { throw new APIError( '', t('BEE1252', { 0: userId } /* ID %{0} inválido ! */) ); } else { // Validar se o usuário existe const existUser = await UserInformation.getUser({ id: userId, }); if (!existUser) throw new APIError( '', t('BEE1253', { 0: userId } /* Usuário %{0} não localizado ! */) ); } } function validEmail(req) { const email = req.body.email || req.query.email; if (email && !validator.isEmail(email)) { throw new APIError( '', t('BEE1254', { 0: email } /* Email %{0} inválido ! */) ); } } async function validLogin(req) { const login = req.body.login || req.query.login; if (!login) { throw new APIError('INVALID_USER_LOGIN'); } else { const existUser = await UserInformation.getUser({ login, }); if (existUser) { throw new APIError( 'EXIST_USER_LOGIN', t('BEE636', { 0: login } /* Login %{0} já cadastrado */) ); } } } function validPassword(req) { const password = req.body.password || req.query.password || req.body.newPass || req.query.newPass; if (!password) { throw new APIError('', t('BEE1256' /* Senha deve ser informada ! */)); } } function validPassValid(req) { const passValid = req.body.passValid || req.query.passValid || req.body.newValid || req.query.newValid; if (!passValid) { throw new APIError( '', t('BEE1257' /* Validade da senha deve ser informada ! */) ); } } function validStatus(req) { const status = req.body.status || req.query.status; if (status > 1) { throw new APIError( '', t('BEE1199', { 0: status } /* Status %{0} inválido ! */) ); } } function validName(req) { const name = req.body.name || req.query.name; if (!name) { throw new APIError('', t('BEE1259' /* Nome deve ser informado ! */)); } } function validType(req) { const type = req.body.type || req.query.type; if (!type) { throw new APIError( '', t('BEE1260' /* Tipo usuário deve ser informado ! */) ); } else if (type > 4) { throw new APIError( '', t('BEE1261', { 0: type } /* Tipo usuário %{0} inválido ! */) ); } } async function validDepartment(req) { const department = req.body.department || req.query.department; if (department) { // Validar se existe o Departamento const existDepartment = await DepartmentInformation.getDepartment({ code: department, }); if (!existDepartment) throw new APIError( '', t('BEE1262', { 0: department } /* Departamento %{0} inválido ! */) ); } } async function validUserFunction(req) { const userFunction = req.body.userFunction || req.query.userFunction; if (userFunction) { // Validar se existe o Cargo const existFunction = await UserFunctionInformation.getUserFunction({ code: userFunction, }); if (!existFunction) throw new APIError( '', t('BEE1263', { 0: userFunction } /* Cargo %{0} inválido ! */) ); } } async function validWorkShift(req) { const workShift = req.body.workShift || req.query.workShift; if (workShift) { // Validar se existe o Turno const existWorkShift = await WorkShiftInformation.getWorkShift({ code: workShift, }); if (!existWorkShift) throw new APIError( '', t('BEE1264', { 0: workShift } /* Turno %{0} inválido ! */) ); } } async function validPrinter(req) { const printer = req.body.printer || req.query.printer; if (printer) { // Validar se existe a Impressora const exitPrinter = await PrinterInformation.getPrinter({ code: printer, }); if (!exitPrinter) throw new APIError( '', t('BEE1265', { 0: printer } /* Impressora %{0} inválida ! */) ); } } async function validMainBranch(req) { const user = await UserInformation.getUser({ id: req.userId, }); if (!user.mainBranch) throw new APIError( '', t('BEE3016' /* Usuário não possui Filial Principal parametrizada! */) ); req.userMainBranch = user.mainBranch; } async function returnPickingPermission(req) { const userId = req.userId || req.body.userId || req.query.userId; const user = await UserInformation.getUser({ id: userId, }); if (!user.pickingReturn) throw new APIError( '', t('BEE3167' /* Usuário não possui permissão para Devolução de Picking */) ); } async function passwordValid(req) { const { userId, password } = req.body; const user = await UserInformation.getUser({ id: userId, password: passwordSHA256(password), }); if (!user) { throw new APIError( '', t( 'BEE2587' /* A senha atual informada não corresponde a senha senha atual. */ ) ); } } async function validateDifferentPassword(req) { const { login, newPassword } = req.body; const user = await UserInformation.getUser({ login, password: passwordSHA256(newPassword), }); if (user) { throw new APIError( '', t('BEE2588' /* A nova senha não pode ser igual à senha atual. */) ); } } async function validPasswordHistories(req) { const userId = req.userId || req.body.userId || req.query.userId || req.body.id || req.query.id; const password = req.body.newPass || req.body.newPassword; const { login } = req.body; const user = !userId ? await UserInformation.getUser({ login }) : null; if (!user && !('userMainBranch' in req)) { throw new APIError( '', t('BEE3350', {} /* Filial principal não cadastrada para o usuário. */) ); } const branch = await BranchInformation.getBranch({ code: !userId ? user.mainBranch : req.userMainBranch, }); const limit = branch && branch.company ? branch.company.passwordHistoryLimit : 0; const passwordHistories = await PasswordHistoryInformation.getPasswordHistories( { userId: userId || user.id }, { limit, order: [['createdAt', 'DESC']], } ); const newPasswordHash = passwordSHA256(password); if (passwordHistories && passwordHistories.length) { const previousPasswords = passwordHistories.map((p) => p.password); if (previousPasswords.includes(newPasswordHash)) { throw new APIError( '', t( 'BEE3266', { 0: limit, } /* Você não pode reutilizar suas últimas %{0} senhas. Por favor, insira uma nova senha. */ ) ); } } req.passwordHistories = newPasswordHash; } export default { validUserId, validEmail, validLogin, validPassword, validPassValid, validStatus, validName, validType, validDepartment, validUserFunction, validWorkShift, validPrinter, validMainBranch, returnPickingPermission, passwordValid, validateDifferentPassword, validPasswordHistories, }; |