All files / source/products create.js

100% Statements 5/5
100% Branches 32/32
100% Functions 1/1
100% Lines 5/5

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            6x 6x                                                                                     5x   1x 1x              
import moment from 'moment-timezone';
 
import APIError from '../../helpers/error';
import ProductDao from '../../database/dao/product';
 
async function createProduct(product) {
  try {
    const newProduct = await ProductDao.createProduct({
      productCode: product.productCode,
      name: product.name,
      fullName: product.fullName,
      complementCode: product.complementCode,
      complementInfo: product.complementInfo,
      fullDescription: product.fullDescription,
      status: product.status || 1,
      unitMeasure: product.unitMeasure,
      materialFamily: product.materialFamily,
      productGroupingCode: product.productGroupingCode,
      stockGroup: product.stockGroup,
      productControlType: product.productControlType,
      stockControlType: product.stockControlType,
      volume: product.volume || 0,
      height: product.height || 0,
      width: product.width || 0,
      length: product.length || 0,
      grossWeight: product.grossWeight || 0,
      netWeight: product.netWeight || 0,
      origin: product.origin,
      taxClassification: product.taxClassification,
      conversionFactor: product.conversionFactor || 0,
      multipleSale: product.multipleSale || 0,
      businessUnit: product.businessUnit,
      level1: product.level1,
      level2: product.level2,
      level3: product.level3,
      level4: product.level4,
      level5: product.level5,
      controlExpirationDate: product.controlExpirationDate || false,
      inboundPreExpiration: product.inboundPreExpiration || 0,
      outboundPreExpiration: product.outboundPreExpiration || 0,
      lifeDays: product.lifeDays || 0,
      overdueDays: product.overdueDays || 0,
      minimalLeftOver: product.minimalLeftOver || 0,
      retailLoss: product.retailLoss || 0,
      note: product.note,
      createdUser: product.createdUser,
      createdAt: moment().format(),
      updatedUser: product.updatedUser,
      updatedAt: moment().format(),
    });
    return newProduct;
  } catch (error) {
    console.log(error);
    throw new APIError('', error);
  }
}
 
export default {
  createProduct,
};