diff --git a/src/controllers/project.controller.js b/src/controllers/project.controller.js index 6633074b..0ee8d493 100644 --- a/src/controllers/project.controller.js +++ b/src/controllers/project.controller.js @@ -89,7 +89,7 @@ export const create = async (req, res) => { uuid, action: 'INSERT', table: Project.stagingTableName, - data: JSON.stringify([newRecord]), + data: JSON.stringify([_.omit(newRecord, 'createdAt', 'updatedAt')]), }); res.json({ message: 'Project staged successfully' }); @@ -310,7 +310,7 @@ export const update = async (req, res) => { uuid: req.body.warehouseProjectId, action: 'UPDATE', table: Project.stagingTableName, - data: JSON.stringify(stagedRecord), + data: JSON.stringify(_.omit(stagedRecord, 'createdAt', 'updatedAt')), }; await Staging.upsert(stagedData); diff --git a/src/controllers/units.controller.js b/src/controllers/units.controller.js index e3d056eb..9ab784a4 100644 --- a/src/controllers/units.controller.js +++ b/src/controllers/units.controller.js @@ -92,7 +92,7 @@ export const create = async (req, res) => { uuid, action: 'INSERT', table: Unit.stagingTableName, - data: JSON.stringify([newRecord]), + data: JSON.stringify([_.omit(newRecord, 'createdAt', 'updatedAt')]), }; await Staging.create(stagedData); @@ -321,7 +321,7 @@ export const update = async (req, res) => { uuid: req.body.warehouseUnitId, action: 'UPDATE', table: Unit.stagingTableName, - data: JSON.stringify(stagedRecord), + data: JSON.stringify(_.omit(stagedRecord, 'createdAt', 'updatedAt')), }; await Staging.upsert(stagedData); diff --git a/src/models/organizations/organizations.model.js b/src/models/organizations/organizations.model.js index c1caca66..f09f3b4d 100644 --- a/src/models/organizations/organizations.model.js +++ b/src/models/organizations/organizations.model.js @@ -200,6 +200,7 @@ class Organization extends Model { allSubscribedOrganizations.map((organization) => { const onResult = (data) => { const updateData = data.reduce((update, current) => { + // TODO: this needs to pull the v1 record if (current.key !== 'registryId') { update[current.key] = current.value; } diff --git a/src/models/units/units.model.js b/src/models/units/units.model.js index f46e44e7..1d762351 100644 --- a/src/models/units/units.model.js +++ b/src/models/units/units.model.js @@ -11,7 +11,7 @@ import { import { Label, Issuance, Staging } from '../../models'; import { UnitMirror } from './units.model.mirror'; import ModelTypes from './units.modeltypes.cjs'; - +import { transformSerialNumberBlock } from '../../utils/helpers'; import { createXlsFromSequelizeResults, transformFullXslsToChangeList, @@ -25,34 +25,51 @@ const virtualFields = { unitBlockStart: { type: Sequelize.VIRTUAL, get() { - const rawValue = this.getDataValue('serialNumberBlock'); - if (!rawValue) { + const serialNumberBlock = this.getDataValue('serialNumberBlock'); + if (!serialNumberBlock) { return undefined; } - return rawValue.split('-')[0]; + const serialNumberPattern = this.getDataValue('serialNumberPattern'); + const [unitBlockStart] = transformSerialNumberBlock( + serialNumberBlock, + serialNumberPattern, + ); + + return unitBlockStart; }, }, unitBlockEnd: { type: Sequelize.VIRTUAL, get() { - const rawValue = this.getDataValue('serialNumberBlock'); - if (!rawValue) { + const serialNumberBlock = this.getDataValue('serialNumberBlock'); + if (!serialNumberBlock) { return undefined; } - return rawValue.split('-')[1]; + + const serialNumberPattern = this.getDataValue('serialNumberPattern'); + const [, unitBlockEnd] = transformSerialNumberBlock( + serialNumberBlock, + serialNumberPattern, + ); + + return unitBlockEnd; }, }, unitCount: { type: Sequelize.VIRTUAL, get() { - const rawValue = this.getDataValue('serialNumberBlock'); - if (!rawValue) { + const serialNumberBlock = this.getDataValue('serialNumberBlock'); + if (!serialNumberBlock) { return undefined; } - const blocks = rawValue.split('-'); - const blockStart = Number(blocks[0].split(/(\d+)/)[1]); - const blockEnd = Number(blocks[1].split(/(\d+)/)[1]); - return blockEnd - blockStart; + + const serialNumberPattern = this.getDataValue('serialNumberPattern'); + const [unitBlockStart, unitBlockEnd] = transformSerialNumberBlock( + serialNumberBlock, + serialNumberPattern, + ); + + return Number(unitBlockEnd) - Number(unitBlockStart); }, }, };