Skip to content

Commit

Permalink
fix: dont send createdAt, updatedAt to datalayer
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Mar 12, 2022
1 parent 2ab93a2 commit c054b0f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
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
1 change: 1 addition & 0 deletions src/models/organizations/organizations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
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

0 comments on commit c054b0f

Please sign in to comment.