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 | 3x 3x 1x 2x 2x 1x 3x 3x 1x 2x 2x 1x 3x 3x 1x 2x 2x 1x 2x 2x 1x 6x 6x 6x 6x 6x 1x 5x 5x 5x 5x 5x 1x 4x 1x 3x 1x 2x 1x 2x 2x 2x 2x 1x | import { parse, isBefore, isValid } from 'date-fns'; import APIError from '../helpers/error'; import { t } from '../helpers/i18n'; import WorkShiftInformation from '../source/workShifts/information'; import UserInformation from '../source/users/information'; async function validWorkShiftId(req) { const workShiftId = req.body.workShiftId || req.query.workShiftId; if (!workShiftId) { throw new APIError('INVALID_ID', t('BEE3421' /* ID inválido */)); } else { const existWorkShift = await WorkShiftInformation.getWorkShift({ id: workShiftId, }); if (!existWorkShift) { throw new APIError( 'NOT_EXIST_WORK_SHIFT_ID', t('BEE1276', { 0: workShiftId } /* Turno %{0} não localizado ! */) ); } } } async function validCode(req) { const code = req.body.code || req.query.code; if (!code) { throw new APIError('INVALID_CODE'); } else { const existWorkShift = await WorkShiftInformation.getWorkShift({ code, }); if (existWorkShift) { throw new APIError( 'EXIST_WORK_SHIFT_CODE', t('BEE1173', { 0: code } /* Codigo %{0} já cadastrado */) ); } } } async function validExistingCode(req) { const code = req.body.code || req.query.code; if (!code) { throw new APIError('INVALID_WORK_SHIFT_CODE'); } else { const existWorkShift = await WorkShiftInformation.getWorkShift({ code, }); if (!existWorkShift) { throw new APIError( 'NOT_EXIST_WORK_SHIFT_CODE', t('BEE1192', { 0: code } /* Código %{0} não cadastrado */) ); } } } function validName(req) { const name = req.body.name || req.query.name; if (!name) { throw new APIError('INVALID_NAME', t('BEE3562' /* Nome inválido */)); } } function validTimes(req) { const startTime = req.body.startTime || req.query.startTime; const endTime = req.body.endTime || req.query.endTime; const breakStartTime = req.body.breakStartTime || req.query.breakStartTime; const breakEndTime = req.body.breakEndTime || req.query.breakEndTime; if (!startTime || !endTime || !breakStartTime || !breakEndTime) { throw new APIError('', t('BEE4316' /* Horários inválidos */)); } const startTimeValid = parse(startTime, 'HH:mm', new Date()); const endTimeValid = parse(endTime, 'HH:mm', new Date()); const breakStartTimeValid = parse(breakStartTime, 'HH:mm', new Date()); const breakEndTimeValid = parse(breakEndTime, 'HH:mm', new Date()); if ( !isValid(startTimeValid) || !isValid(endTimeValid) || !isValid(breakStartTimeValid) || !isValid(breakEndTimeValid) ) { throw new APIError('', t('BEE4316' /* Horários inválidos */)); } if (!isBefore(startTimeValid, endTimeValid)) { throw new APIError( '', t( 'BEE4317' /* O horário inicial do turno não pode ser maior ou igual ao horário final do turno. */ ) ); } if (!isBefore(breakStartTimeValid, breakEndTimeValid)) { throw new APIError( '', t( 'BEE4318' /* O horário inicial do intervalo não pode ser maior ou igual ao horário final do intervalo. */ ) ); } if ( !isBefore(startTimeValid, breakStartTimeValid) || !isBefore(breakEndTimeValid, endTimeValid) ) { throw new APIError( '', t( 'BEE4319' /* O horário do intervalo deve estar entre o horário inicial e final do turno. */ ) ); } } async function validDelete(req) { const workShiftId = req.body.workShiftId || req.query.workShiftId; const workShiftData = await WorkShiftInformation.getWorkShift({ id: workShiftId, }); const userWorkShifts = await UserInformation.getAllUsers({ workShift: workShiftData.code, }); if (userWorkShifts.length > 0) { throw new APIError('', t('BEE4320' /* Turno vinculado a um usuário */)); } } export default { validWorkShiftId, validCode, validName, validExistingCode, validTimes, validDelete, }; |