fix: id cleanup in backend

This commit is contained in:
Matthieu Bessat 2020-08-04 22:53:42 +02:00
parent bac94738fd
commit 09269a95b7

View file

@ -49,10 +49,36 @@ export default class DelegateController {
// only update proposedVersion
let proposedVersion: any = req.body
proposedVersion.tags = tags
if (Utils.isUsable(proposedVersion, 'pricing') && Array.isArray(proposedVersion.pricing)) {
proposedVersion.pricing = proposedVersion.pricing.map((i: any) => {
delete i._id
return i
}).filter((i: any) => i.isExample !== true)
}
if (Utils.isUsable(proposedVersion, 'schedule') && Array.isArray(proposedVersion.schedule)) {
proposedVersion.schedule = proposedVersion.schedule.map((i: any) => {
delete i._id
if (Array.isArray(i.when) && i.when.length > 0) {
i.when = i.when.map((w: any) => {
delete w._id
return w
})
}
return i
}).filter((i: any) => i.isExample !== true)
}
// remove useless isResponsable
if (Utils.isUsable(proposedVersion, 'contacts.peoples') && Array.isArray(proposedVersion.contacts.peoples)) {
proposedVersion.contacts.peoples = proposedVersion.contacts.peoples.filter((p: any) => !p.isResponsable)
proposedVersion.contacts.peoples = proposedVersion.contacts.peoples
.filter((p: any) => !p.isResponsable)
// cleanup id
.map((p: any) => {
delete p._id
return p
})
}
// sanitize short description
@ -69,10 +95,6 @@ export default class DelegateController {
)
}
// validate contact.address
// validate all fields to not overflow
// validate the size of all the json, all the data recorded
// manage medias
// delete media that are not used
if (!Array.isArray(proposedVersion.gallery)) {
@ -119,6 +141,8 @@ export default class DelegateController {
proposedVersion.pricing = []
}
// validate all fields to not overflow
// validate the size of all the json, all the data recorded
// just before updating the whole organization, we want to check the size of the proposedVersion JSON String, just in case it is too large
if (JSON.stringify(proposedVersion).length > 10000) {
return res.status(413).json({