diff --git a/package.json b/package.json index 9f38ddcb..34ff2db9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "climate-warehouse", - "version": "0.0.18", + "version": "0.0.19", "private": true, "bin": "build/server.js", "type": "module", diff --git a/src/models/organizations/organizations.model.js b/src/models/organizations/organizations.model.js index 3ef6b332..f09f3b4d 100644 --- a/src/models/organizations/organizations.model.js +++ b/src/models/organizations/organizations.model.js @@ -200,7 +200,10 @@ class Organization extends Model { allSubscribedOrganizations.map((organization) => { const onResult = (data) => { const updateData = data.reduce((update, current) => { - update[current.key] = current.value; + // TODO: this needs to pull the v1 record + if (current.key !== 'registryId') { + update[current.key] = current.value; + } return update; }, {}); 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); }, }, };