Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dont overwrite registryId on update #379

Merged
merged 6 commits into from
Mar 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "climate-warehouse",
"version": "0.0.18",
"version": "0.0.19",
"private": true,
"bin": "build/server.js",
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/units.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/models/organizations/organizations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}, {});

Expand Down
43 changes: 30 additions & 13 deletions src/models/units/units.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
},
},
};
Expand Down