Skip to content

Commit

Permalink
fix: get active offer endpoint in correct strcuture
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Sep 14, 2022
1 parent 8e4c8f9 commit b3066f6
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions src/controllers/offer.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,58 @@ export const getCurrentOfferInfo = async (req, res) => {

const offerFile = JSON.parse(offerFileJson.metaValue);

// Out of time so just hard coding this
const projectChildRecords = [
'issuances',
'projectLocations',
'estimations',
'labels',
'projectRatings',
'coBenefits',
'relatedProjects',
];

const makerChanges = deserializeMaker(offerFile.offer.maker);
const takerChanges = deserializeTaker(offerFile.offer.taker);

console.log(makerChanges);

let maker = makerChanges.filter((record) => record.table === 'project');

makerChanges.forEach((record) => {
if (projectChildRecords.includes(record.table)) {
if (!maker[0].value[record.table]) {
maker[0].value[record.table] = [];
}

maker[0].value[record.table].push(record.value);
}
});

maker = maker.concat(
makerChanges.filter((record) => record.table === 'unit'),
);

let taker = takerChanges.filter((record) => record.table === 'project');

takerChanges.forEach((record) => {
if (projectChildRecords.includes(record.table)) {
if (!taker[0].value[record.table]) {
taker[0].value[record.table] = [];
}

taker[0].value[record.table].push(record.value);
}
});

taker = taker.concat(
takerChanges.filter((record) => record.table === 'unit'),
);

res.status(200).json({
changes: {
maker: makerChanges,
taker: takerChanges,
maker,
taker,
},
});
} catch (error) {
Expand Down

0 comments on commit b3066f6

Please sign in to comment.