All files / source/pickingAreas information.js

28.57% Statements 2/7
40% Branches 2/5
40% Functions 2/5
28.57% Lines 2/7

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            1x                                             1x                                                                                                                                                                                  
import PickingAreaDao from '../../database/dao/pickingAreas';
import ProductDao from '../../database/dao/product';
 
import { models } from '../../../config/database';
 
async function getPickingAreas(query, opts = {}) {
  return PickingAreaDao.findPickingAreas(query, {
    // raw: true,
    attributes: [
      'id',
      'productCode',
      'description',
      'branchCode',
      'depositCode',
      'note',
    ],
    include: [
      {
        required: false,
        model: models.Branch,
        as: 'branch',
        attributes: ['code', 'name'],
      },
    ],
    ...opts,
  });
}
 
async function getPickingArea(query, opts = {}) {
  return PickingAreaDao.findPickingArea(query, {
    // raw: true,
    attributes: [
      'id',
      'productCode',
      'depositCode',
      'description',
      'branchCode',
      'depositCode',
      'note',
    ],
    include: [
      {
        required: false,
        model: models.Branch,
        as: 'branch',
        attributes: ['code', 'name'],
      },
    ],
    ...opts,
  });
}
 
async function getAllPickingAreas(opts = {}) {
  return PickingAreaDao.findPickingAreas(
    {},
    {
      // raw: true,
      attributes: [
        'id',
        'productCode',
        'description',
        'branchCode',
        'depositCode',
        'note',
        'depositCode',
      ],
      include: [
        {
          required: true,
          model: models.Branch,
          as: 'branch',
          attributes: ['code', 'name'],
        },
        {
          required: true,
          model: models.Product,
          as: 'product',
          attributes: ['name'],
        },
        {
          required: true,
          model: models.Deposit,
          as: 'deposit',
          attributes: ['code', 'name'],
        },
      ],
      ...opts,
    }
  );
}
 
async function getOptionsProductsEnabledForPicking(
  query,
  opts = {},
  limit = 10
) {
  const products = await ProductDao.findProducts(query, {
    attributes: ['id', 'productCode', 'name'],
    limit,
    ...opts,
  });
 
  const result = products.map((product) => {
    return {
      value: product.productCode,
      label: product.name,
    };
  });
 
  return result;
}
 
export default {
  getPickingAreas,
  getPickingArea,
  getAllPickingAreas,
  getOptionsProductsEnabledForPicking,
};