From 5cdd60dccac7b6aa8fc5c5d73456d9599c470dda Mon Sep 17 00:00:00 2001 From: Daniel Stefan Date: Fri, 2 Sep 2022 19:30:58 +0300 Subject: [PATCH 1/4] fix: transfer maker taker --- src/controllers/project.controller.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/controllers/project.controller.js b/src/controllers/project.controller.js index 9d3a68f1..fc3c3cf9 100644 --- a/src/controllers/project.controller.js +++ b/src/controllers/project.controller.js @@ -280,7 +280,9 @@ const update = async (req, res, isTransfer = false) => { const newRecord = _.cloneDeep(req.body); const { orgUid } = await Organization.getHomeOrg(); - newRecord.orgUid = orgUid; + if (isTransfer) { + newRecord.orgUid = originalRecord.orgUid; + } const childRecordsKeys = [ 'projectLocations', From 7216f51378686b458748e34e977a30a5a034ac5f Mon Sep 17 00:00:00 2001 From: Daniel Stefan Date: Fri, 2 Sep 2022 19:33:32 +0300 Subject: [PATCH 2/4] fix: transfer maker taker --- src/models/staging/staging.model.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/staging/staging.model.js b/src/models/staging/staging.model.js index 048a34c9..fa69e4d7 100644 --- a/src/models/staging/staging.model.js +++ b/src/models/staging/staging.model.js @@ -56,7 +56,7 @@ class Staging extends Model { const maker = { inclusions: [] }; const taker = { inclusions: [] }; - // The record still has the orgUid of the takerProjectRecord, + // 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; From 8ba9c47732f704de6401700c9d51ee425f6c6018 Mon Sep 17 00:00:00 2001 From: Daniel Stefan Date: Fri, 2 Sep 2022 19:42:43 +0300 Subject: [PATCH 3/4] fix: transfer maker taker --- src/models/staging/staging.model.js | 74 ++++++++++++++--------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/models/staging/staging.model.js b/src/models/staging/staging.model.js index fa69e4d7..8bfc1c44 100644 --- a/src/models/staging/staging.model.js +++ b/src/models/staging/staging.model.js @@ -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 }, @@ -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, @@ -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; }); @@ -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, ); @@ -167,8 +167,8 @@ 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, @@ -176,9 +176,9 @@ class Staging extends Model { })), ); - 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, @@ -187,8 +187,8 @@ class Staging extends Model { ); } - taker.inclusions.push( - ...takerProjectInclusions.project + maker.inclusions.push( + ...makerProjectInclusions.project .filter((inclusion) => inclusion.action !== 'delete') .map((inclusion) => ({ key: inclusion.key, @@ -196,9 +196,9 @@ class Staging extends Model { })), ); - 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, From b5b8d4c071337235bd9d803bbe3e623983c5cdb1 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Fri, 2 Sep 2022 12:52:56 -0400 Subject: [PATCH 4/4] fix: test --- src/controllers/project.controller.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/controllers/project.controller.js b/src/controllers/project.controller.js index fc3c3cf9..448d5906 100644 --- a/src/controllers/project.controller.js +++ b/src/controllers/project.controller.js @@ -282,6 +282,8 @@ const update = async (req, res, isTransfer = false) => { const { orgUid } = await Organization.getHomeOrg(); if (isTransfer) { newRecord.orgUid = originalRecord.orgUid; + } else { + newRecord.orgUid = orgUid; } const childRecordsKeys = [