-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround for extraData bug implemented for begrotingen upload and f…
…ix publishAsConcept
- Loading branch information
1 parent
6bd1be9
commit fff20c7
Showing
8 changed files
with
283 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/cms/lib/modules/resource-form-widgets/lib/budget.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const eventEmitter = require('../../../../events').emitter; | ||
const fetch = require('node-fetch'); | ||
|
||
module.exports = async function(self, options) { | ||
|
||
self.route('put', 'budget', async function(req, res) { | ||
eventEmitter.emit('resourceCrud'); | ||
const apiUrl = self.apos.settings.getOption(req, 'apiUrl'); | ||
const siteUrl = self.apos.settings.getOption(req, 'siteUrl'); | ||
const siteId = req.data.global.siteId; | ||
|
||
const data = req.body; | ||
const getUrl = `${apiUrl}/api/site/${siteId}/idea/${data.id}`; | ||
const postUrl = `${apiUrl}/api/site/${siteId}/idea/${data.id}`; | ||
|
||
/** | ||
* Format header | ||
*/ | ||
const httpHeaders = { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
}; | ||
|
||
if (req.session.jwt) { | ||
httpHeaders['X-Authorization'] = `Bearer ${req.session.jwt}`; | ||
} | ||
|
||
const response = await fetch(getUrl, { | ||
headers: httpHeaders | ||
}); | ||
|
||
if(response.ok) { | ||
const idea = await response.json(); | ||
let ideaBudgets = []; | ||
|
||
try { | ||
ideaBudgets = JSON.parse(idea?.extraData?.budgetDocuments); | ||
} | ||
catch(e) { | ||
|
||
} | ||
|
||
const indexToDelete = ideaBudgets.findIndex(d =>{ | ||
return d.name === data.name}); | ||
|
||
if(indexToDelete > -1) { | ||
ideaBudgets.splice(indexToDelete, 1); | ||
} | ||
|
||
console.log(JSON.stringify({ | ||
extraData: { | ||
budgetDocuments: JSON.stringify(ideaBudgets) | ||
}, | ||
})); | ||
|
||
const putResponse = await fetch(postUrl, { | ||
method: 'PUT', | ||
headers: httpHeaders, | ||
body: JSON.stringify({ | ||
extraData: { | ||
budgetDocuments: JSON.stringify(ideaBudgets) | ||
}, | ||
}), | ||
}); | ||
|
||
if(putResponse.ok) { | ||
const ideaResponse = await putResponse.json(); | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.end(JSON.stringify({ | ||
id: ideaResponse.id | ||
})); | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.