Skip to content

Commit

Permalink
Merge pull request #724 from Chia-Network/fix-transfer-maker-taker
Browse files Browse the repository at this point in the history
fix: transfer maker taker
  • Loading branch information
MichaelTaylor3D authored Sep 2, 2022
2 parents c043a09 + b5b8d4c commit d703885
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 39 deletions.
6 changes: 5 additions & 1 deletion src/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ 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;
} else {
newRecord.orgUid = orgUid;
}

const childRecordsKeys = [
'projectLocations',
Expand Down
76 changes: 38 additions & 38 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 @@ -56,13 +56,13 @@ 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;
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 d703885

Please sign in to comment.