All files / source/reports dock.js

100% Statements 29/29
80% Branches 16/20
100% Functions 4/4
100% Lines 27/27

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                              3x 18x 3x                                     3x 18x   3x 4x 4x   4x 2x 2x 1x 1x 1x   4x 2x 2x 1x 1x 1x   4x 4x 24x   24x 24x 8x     4x      
import moment from 'moment-timezone';
import DockDao from '../../database/dao/dock';
import { models } from '../../../config/database';
import I18n from '../../helpers/i18n';
import { mountWhereBasedFilter } from '../../helpers/reports/sequelize';
 
// Funcao criada para popular o array headers e rows enviados por parametro
export default async function generateData(
  columns,
  filters,
  headers = [],
  rows = [],
  opts = {},
  appLanguage = 'ptBr'
) {
  const where = mountWhereBasedFilter(filters);
  const headersValue = columns.map((it) => it.value);
  const dados = await DockDao.findDocks(where, {
    attributes: headersValue,
    include: [
      {
        required: true,
        model: models.User,
        as: 'userCreated',
        attributes: ['login'],
      },
      {
        required: true,
        model: models.User,
        as: 'userUpdated',
        attributes: ['login'],
      },
    ],
    ...opts,
  });
 
  columns.forEach((it) => {
    headers.push(it.label);
  });
  dados.forEach((it) => {
    it.createdUser = it.userCreated.dataValues.login;
    it.updatedUser = it.userUpdated.dataValues.login;
 
    if (it.dockType === 1) {
      it.dockType = I18n.t('BEE201' /* Entrada */, undefined, appLanguage);
    } else if (it.dockType === 2) {
      it.dockType = I18n.t('BEE202' /* SaĆ­da */, undefined, appLanguage);
    } else Eif (it.dockType === 3) {
      it.dockType = I18n.t('BEE212' /* Ambas */, undefined, appLanguage);
    }
    if (it.status === 1) {
      it.status = I18n.t('BEE205' /* Liberada */, undefined, appLanguage);
    } else if (it.status === 2) {
      it.status = I18n.t('BEE206' /* Ocupada */, undefined, appLanguage);
    } else Eif (it.status === 3) {
      it.status = I18n.t('BEE213' /* Bloqueada */, undefined, appLanguage);
    }
    const row = [];
    for (let index = 0; index < headersValue.length; index++) {
      const column = headersValue[index];
 
      row.push(it[column]);
      if (column === 'createdAt' || column === 'updatedAt') {
        row[index] = moment(row[index]).format('l LTS');
      }
    }
    rows.push(row);
  });
}