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 | 4x 4x 1x 3x 3x 2x 4x 4x 1x 3x 3x 2x 4x 4x 1x 3x 3x 2x 2x 2x 1x 2x 2x 1x 4x 4x 1x 3x 3x 2x 3x 3x 3x 3x 2x | import APIError from '../helpers/error'; import { t } from '../helpers/i18n'; import CustomerProductsInformation from '../source/customerProducts/information'; import CustomerInformation from '../source/customers/information'; import ProductInformation from '../source/products/information'; import UnitMeasureInformation from '../source/unitsMeasure/information'; async function validCustomerProductId(req) { const customerProductId = req.body.customerProductId || req.query.customerProductId; if (!customerProductId) { throw new APIError('INVALID_ID', t('BEE3421' /* ID inválido */)); } else { const existCustomerProduct = await CustomerProductsInformation.getCustomerProduct({ id: customerProductId, }); if (!existCustomerProduct) { throw new APIError( 'NOT_EXIST_CUSTOMER_PRODUCT_ID', t( 'BEE1185', { 0: customerProductId, } /* Produto do cliente ID = %{0} não localizado */ ) ); } } } async function validProductCode(req) { const productCode = req.body.productCode || req.query.productCode; if (!productCode) { throw new APIError('INVALID_PRODUCT_CODE'); } else { const existProduct = await ProductInformation.getProduct({ productCode, }); if (!existProduct) { throw new APIError( 'NO_EXIST_PRODUCT_CODE', t('BEE1186', { 0: productCode } /* Produto %{0} não cadastrado */) ); } } } async function validCustomerCode(req) { const customerCode = req.body.customerCode || req.query.customerCode; if (!customerCode) { throw new APIError('INVALID_CUSTOMER_CODE'); } else { const existCustomer = await CustomerInformation.getCustomer({ code: customerCode, }); if (!existCustomer) { throw new APIError( 'NO_EXIST_CUSTOMER_CODE', t('BEE1187', { 0: customerCode } /* Cliente %{0} não cadastrado */) ); } } } function validProductCustomerCode(req) { const productCustomerCode = req.body.productCustomerCode || req.query.productCustomerCode; if (!productCustomerCode) { throw new APIError('INVALID_CODE', t('BEE3430' /* Código inválido */)); } } function validProductCustomerName(req) { const productCustomerName = req.body.productCustomerName || req.query.productCustomerName; if (!productCustomerName) { throw new APIError('INVALID_NAME', t('BEE3562' /* Nome inválido */)); } } async function validUnitMeasure(req) { const unitMeasure = req.body.unitMeasure || req.query.unitMeasure; if (!unitMeasure) { throw new APIError('INVALID_UNIT_MEASURE'); } else { const existUnitMeasure = await UnitMeasureInformation.getUnitMeasure({ str_code: unitMeasure, }); if (!existUnitMeasure) { throw new APIError( 'NO_EXIST_UNIT_MEASURE', t( 'BEE1188', { 0: unitMeasure } /* Unidade de medida %{0} não cadastrado */ ) ); } } } async function duplicateConstraints(req) { const productCode = req.body.productCode || req.query.productCode; const customerCode = req.body.customerCode || req.query.customerCode; const duplicateCustomerProduct = await CustomerProductsInformation.getCustomerProduct({ productCode, customerCode, }); if (duplicateCustomerProduct) { throw new APIError( 'DUPLICATE_CUSTOMER_CODE_AND_PRODUCT_CODE', t( 'BEE1189', { 0: productCode, 1: customerCode, } /* Produto %{0} já cadastrado para o cliente %{1} */ ) ); } } export default { validCustomerProductId, validProductCode, validCustomerCode, validProductCustomerCode, validProductCustomerName, validUnitMeasure, duplicateConstraints, }; |