All files / middlewares resupplyWaveValidations.js

100% Statements 8/8
100% Branches 6/6
100% Functions 1/1
100% Lines 8/8

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          4x   4x 1x         3x       3x 1x       2x 1x                                
import APIError from '../helpers/error';
import { t } from '../helpers/i18n';
import BranchInformation from '../source/branches/information';
 
async function validDepositIntermediary(req) {
  const { userMainBranch } = req;
 
  if (!userMainBranch) {
    throw new APIError(
      'INVALID_BRANCH_CODE',
      t('BEE1285' /* Código da filial deve ser informado */)
    );
  } else {
    const existBranch = await BranchInformation.getBranch({
      code: userMainBranch,
    });
 
    if (!existBranch) {
      throw new APIError(
        'NOT_EXIST_BRANCH_CODE',
        t('BEE1170', { 0: userMainBranch } /* Filial %{0} não localizada */)
      );
    } else if (!existBranch.intermediaryDeposit) {
      throw new APIError(
        'NOT_DEPOSIT_INTERMEDIARY',
        t(
          'BEE2933',
          {
            0: userMainBranch,
          } /* A filial %{0} ainda não possui um depósito intermediário cadastrado. Por favor, efetue o cadastro deste depósito antes de prosseguir com a criação da Onda. */
        )
      );
    }
  }
}
 
export default {
  validDepositIntermediary,
};