Skip to content

Commit

Permalink
fix: transfer maker taker
Browse files Browse the repository at this point in the history
  • Loading branch information
danielstefanequilobe committed Sep 2, 2022
1 parent 7216f51 commit 8ba9c47
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions src/models/staging/staging.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Staging extends Model {
raw: true,
});

const takerProjectRecord = _.head(JSON.parse(stagingRecord.data));
const makerProjectRecord = _.head(JSON.parse(stagingRecord.data));

const myOrganization = await Organization.findOne({
where: { isHome: true },
Expand All @@ -58,11 +58,11 @@ class Staging extends Model {

// The record still has the orgUid of the makerProjectRecord,
// we will update this to the correct orgUId later
maker.storeId = takerProjectRecord.orgUid;
taker.storeId = myOrganization.orgUid;
taker.storeId = makerProjectRecord.orgUid;
maker.storeId = myOrganization.orgUid;

const makerProjectRecord = await Project.findOne({
where: { warehouseProjectId: takerProjectRecord.warehouseProjectId },
const takerProjectRecord = await Project.findOne({
where: { warehouseProjectId: makerProjectRecord.warehouseProjectId },
include: Project.getAssociatedModels().map((association) => {
return {
model: association.model,
Expand All @@ -71,26 +71,26 @@ class Staging extends Model {
}),
});

makerProjectRecord.projectStatus = 'Transitioned';
takerProjectRecord.projectStatus = 'Transitioned';

const issuanceIds = makerProjectRecord.issuances.reduce((ids, issuance) => {
const issuanceIds = takerProjectRecord.issuances.reduce((ids, issuance) => {
if (!ids.includes(issuance.id)) {
ids.push(issuance.id);
}
return ids;
}, []);

let unitMakerRecords = await Unit.findAll({
let unitTakerRecords = await Unit.findAll({
where: {
issuanceId: { [Op.in]: issuanceIds },
},
raw: true,
});

// Takers get an unlatered copy of all the project units from the maker
const unitTakerRecords = _.cloneDeep(unitMakerRecords);
// Makers get an unlatered copy of all the project units from the taker
const unitMakerRecords = _.cloneDeep(unitTakerRecords);

unitMakerRecords = unitMakerRecords.map((record) => {
unitTakerRecords = unitTakerRecords.map((record) => {
record.unitStatus = 'Exported';
return record;
});
Expand All @@ -113,50 +113,50 @@ class Staging extends Model {
issuances: 'id',
};

const makerProjectXslsSheets = createXlsFromSequelizeResults({
rows: [makerProjectRecord],
const takerProjectXslsSheets = createXlsFromSequelizeResults({
rows: [takerProjectRecord],
model: Project,
toStructuredCsv: true,
});

const takerProjectXslsSheets = createXlsFromSequelizeResults({
rows: [takerProjectRecord],
const makerProjectXslsSheets = createXlsFromSequelizeResults({
rows: [makerProjectRecord],
model: Project,
toStructuredCsv: true,
});

const makerUnitXslsSheets = createXlsFromSequelizeResults({
rows: unitMakerRecords,
const takerUnitXslsSheets = createXlsFromSequelizeResults({
rows: unitTakerRecords,
model: Unit,
toStructuredCsv: true,
});

const takerUnitXslsSheets = createXlsFromSequelizeResults({
rows: unitTakerRecords,
const makerUnitXslsSheets = createXlsFromSequelizeResults({
rows: unitMakerRecords,
model: Unit,
toStructuredCsv: true,
});

const takerProjectInclusions = await transformFullXslsToChangeList(
takerProjectXslsSheets,
const makerProjectInclusions = await transformFullXslsToChangeList(
makerProjectXslsSheets,
'insert',
primaryProjectKeyMap,
);

const makerProjectInclusions = await transformFullXslsToChangeList(
makerProjectXslsSheets,
const takerProjectInclusions = await transformFullXslsToChangeList(
takerProjectXslsSheets,
'insert',
primaryProjectKeyMap,
);

const makerUnitInclusions = await transformFullXslsToChangeList(
makerUnitXslsSheets,
const takerUnitInclusions = await transformFullXslsToChangeList(
takerUnitXslsSheets,
'insert',
primaryUnitKeyMap,
);

const takerUnitInclusions = await transformFullXslsToChangeList(
takerUnitXslsSheets,
const makerUnitInclusions = await transformFullXslsToChangeList(
makerUnitXslsSheets,
'insert',
primaryUnitKeyMap,
);
Expand All @@ -167,18 +167,18 @@ class Staging extends Model {
.map((inclusion) => ({ key: inclusion.key, value: inclusion.value }));
});*/

maker.inclusions.push(
...makerProjectInclusions.project
taker.inclusions.push(
...takerProjectInclusions.project
.filter((inclusion) => inclusion.action !== 'delete')
.map((inclusion) => ({
key: inclusion.key,
value: inclusion.value,
})),
);

if (makerUnitInclusions?.unit) {
maker.inclusions.push(
...makerUnitInclusions.unit
if (takerUnitInclusions?.unit) {
taker.inclusions.push(
...takerUnitInclusions.unit
.filter((inclusion) => inclusion.action !== 'delete')
.map((inclusion) => ({
key: inclusion.key,
Expand All @@ -187,18 +187,18 @@ class Staging extends Model {
);
}

taker.inclusions.push(
...takerProjectInclusions.project
maker.inclusions.push(
...makerProjectInclusions.project
.filter((inclusion) => inclusion.action !== 'delete')
.map((inclusion) => ({
key: inclusion.key,
value: inclusion.value,
})),
);

if (takerUnitInclusions?.unit) {
taker.inclusions.push(
...takerUnitInclusions.unit
if (makerUnitInclusions?.unit) {
maker.inclusions.push(
...makerUnitInclusions.unit
.filter((inclusion) => inclusion.action !== 'delete')
.map((inclusion) => ({
key: inclusion.key,
Expand Down

0 comments on commit 8ba9c47

Please sign in to comment.