All files / source/storageAddresses update.js

100% Statements 14/14
100% Branches 5/5
100% Functions 3/3
100% Lines 14/14

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            204x 204x                                                                     203x   1x 1x         3x 3x         2x   1x 1x         2x 2x           1x 1x                  
import moment from 'moment-timezone';
 
import StorageAddressDao from '../../database/dao/storageAddress';
import APIError from '../../helpers/error';
 
async function updateStorageAddress(storageAddressId, storageAddress) {
  try {
    const updStorageAddress = await StorageAddressDao.updateStorageAddress(
      { id: storageAddressId },
      {
        name: storageAddress.name,
        branchCode: storageAddress.branchCode,
        type: storageAddress.type,
        sector: storageAddress.sector,
        street: storageAddress.street,
        level: storageAddress.level,
        column: storageAddress.column,
        drawer: storageAddress.drawer,
        blocked: storageAddress.blocked,
        size: storageAddress.size,
        height: storageAddress.height,
        width: storageAddress.width,
        length: storageAddress.length,
        curve: storageAddress.curve,
        capacityVolume: storageAddress.capacityVolume
          ? storageAddress.capacityVolume
          : 0,
        capacityWeight: storageAddress.capacityWeight
          ? storageAddress.capacityWeight
          : 0,
        shareAddress: storageAddress.shareAddress,
        rangeCode: storageAddress.rangeCode,
        note: storageAddress.note,
        shareAddressOfProductsWithDifferentLots:
          storageAddress.shareAddressOfProductsWithDifferentLots,
        inboundSequence: storageAddress.inboundSequence,
        outboundSequence: storageAddress.outboundSequence,
        updatedUser: storageAddress.updatedUser,
        updatedAt: moment().format(),
      }
    );
 
    return updStorageAddress;
  } catch (error) {
    console.log(error);
    throw new APIError('', error);
  }
}
 
async function updateStorageAddressPickingArea(query, pickingAreaId, userId) {
  try {
    const updStorageAddress = await StorageAddressDao.updateStorageAddress(
      query,
      { pickingAreaId, updatedUser: userId }
    );
 
    return updStorageAddress;
  } catch (error) {
    console.log(error);
    throw new APIError('', error);
  }
}
 
async function updateStorageAddresses(query, update, userId, opts = {}) {
  try {
    return await StorageAddressDao.updateStorageAddress(
      query,
      { ...update, updatedUser: userId, updatedAt: moment().format() },
      opts
    );
  } catch (error) {
    console.log(error);
    throw new APIError('', error);
  }
}
 
export default {
  updateStorageAddress,
  updateStorageAddressPickingArea,
  updateStorageAddresses,
};