All files / middlewares waybillValidations.js

100% Statements 10/10
100% Branches 10/10
100% Functions 2/2
100% Lines 10/10

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          3x   3x 1x         2x             2x 1x                 2x   2x             2x 1x                      
import APIError from '../helpers/error';
import WaybillInformation from '../source/waybills/information';
import { t } from '../helpers/i18n';
 
async function validWaybillId(req) {
  const waybillId = req.body.waybillId || req.query.waybillId;
 
  if (!waybillId) {
    throw new APIError(
      '',
      t('BEE3248' /* O ID do Romaneio deve ser informado! */)
    );
  } else {
    const existWaybill = await WaybillInformation.getWaybill(
      {
        id: waybillId,
      },
      { userBranches: req.userBranches }
    );
 
    if (!existWaybill) {
      throw new APIError(
        '',
        t('BEE3171', { 0: waybillId } /* Romaneio ID = %{0} não localizado */)
      );
    }
  }
}
 
async function validWaybillSync(req) {
  const waybillId = req.body.waybillId || req.query.waybillId;
 
  const waybill = await WaybillInformation.getWaybill(
    {
      id: waybillId,
    },
    { userBranches: req.userBranches }
  );
 
  if (waybill.status > 1) {
    throw new APIError(
      '',
      t('BEE3172' /* Romaneio já foi integrado com ERP! */)
    );
  }
}
 
export default {
  validWaybillId,
  validWaybillSync,
};