All files / middlewares outboundMonitorValidations.js

100% Statements 14/14
100% Branches 8/8
100% Functions 4/4
100% Lines 14/14

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          2x 2x     2x 1x         2x 2x 1x               2x   2x     2x 1x         2x 2x 1x                          
import APIError from '../helpers/error';
import OutboundRangeInformation from '../source/outboundRange/information';
import I18n from '../helpers/i18n';
 
async function validOutboundRangeId(req) {
  const { outboundRangeId } = req.body;
  const existOutboundRange = await OutboundRangeInformation.getOutboundRange({
    id: outboundRangeId,
  });
  if (!existOutboundRange) {
    throw new APIError('OUTBOUND_RANGE_ID_NOT_FOUND', '');
  }
}
 
function validFieldsOutboundRange(req) {
  const { fieldsOutboundRange } = req.body;
  if (!Object.keys(fieldsOutboundRange).length) {
    throw new APIError(
      '',
      I18n.t('BEE2005' /* Nenhuma Informação para atualizar */)
    );
  }
}
 
async function validOutboundRangeProductId(req) {
  const { outboundRangeProductId } = req.body;
  const existOutboundRangeProduct =
    await OutboundRangeInformation.getOutboundRangeProduct({
      id: outboundRangeProductId,
    });
  if (!existOutboundRangeProduct) {
    throw new APIError('OUTBOUND_RANGE_PRODUCT_ID_NOT_FOUND', '');
  }
}
 
function validFieldsOutboundRangeProduct(req) {
  const { fieldsOutboundRangeProduct } = req.body;
  if (!Object.keys(fieldsOutboundRangeProduct).length) {
    throw new APIError(
      '',
      I18n.t('BEE2005' /* Nenhuma Informação para atualizar */)
    );
  }
}
 
export default {
  validFieldsOutboundRange,
  validOutboundRangeId,
  validOutboundRangeProductId,
  validFieldsOutboundRangeProduct,
};