fix(Public): handle URL erros

This commit is contained in:
Matthieu Bessat 2020-08-04 23:49:50 +02:00
parent 09269a95b7
commit 8231d58c82

View file

@ -51,7 +51,7 @@ export default class PublicController {
return { return {
_id: o._id, _id: o._id,
name: version.name, name: version.name,
description: version.descriptionShort.replace(/\n/g, ''), description: version.descriptionShort.replace(/\n/g, ' '),
thumbnail: version.thumbnail.key, thumbnail: version.thumbnail.key,
tags: version.tags === null ? 'tags_not_found' : version.tags, tags: version.tags === null ? 'tags_not_found' : version.tags,
slug: o.get('slugs')[o.get('slugs').length -1] slug: o.get('slugs')[o.get('slugs').length -1]
@ -70,11 +70,11 @@ export default class PublicController {
organizationsJSON: JSON.stringify(organizationsData) organizationsJSON: JSON.stringify(organizationsData)
}) })
}).catch(err => () => { }).catch(err => () => {
console.log(err) console.error(err)
return ErrorController.handleServerError(err, req, res, []) return ErrorController.handleServerError(err, req, res, [])
}) })
}).catch(err => () => { }).catch(err => () => {
console.log(err) console.error(err)
return ErrorController.handleServerError(err, req, res, []) return ErrorController.handleServerError(err, req, res, [])
}) })
} }
@ -138,13 +138,28 @@ export default class PublicController {
} }
if (Utils.isStrUsable(version.contacts, 'facebook')) { if (Utils.isStrUsable(version.contacts, 'facebook')) {
version.contacts.facebookLabel = new URL(version.contacts.facebook).pathname.replace('/', '') try {
version.contacts.facebookLabel = new URL(version.contacts.facebook).pathname.replace('/', '')
} catch (err) {
console.error(err)
version.contacts.facebook = version.contacts.facebookLabel = "OULA, c'est pas bon :("
}
} }
if (Utils.isStrUsable(version.contacts, 'twitter')) { if (Utils.isStrUsable(version.contacts, 'twitter')) {
version.contacts.twitterLabel = new URL(version.contacts.twitter).pathname.replace('/', '') try {
version.contacts.twitterLabel = new URL(version.contacts.twitter).pathname.replace('/', '')
} catch (err) {
console.error(err)
version.contacts.twitter = version.contacts.twitterLabel = "OULA, c'est pas bon :("
}
} }
if (Utils.isStrUsable(version.contacts, 'instagram')) { if (Utils.isStrUsable(version.contacts, 'instagram')) {
version.contacts.instagramLabel = new URL(version.contacts.instagram).pathname.replace('/', '') try {
version.contacts.instagramLabel = new URL(version.contacts.instagram).pathname.replace('/', '')
} catch (err) {
console.error(err)
version.contacts.instagram = version.contacts.instagramLabel = "OULA, c'est pas bon :("
}
} }
} }
if (Array.isArray(version.gallery)) { if (Array.isArray(version.gallery)) {
@ -153,45 +168,46 @@ export default class PublicController {
return media return media
}) })
} }
version.cutDescription = Utils.isStrUsable(version, 'descriptionLong') && version.descriptionLong.length > 200 if (Utils.isUsable(version, 'schedule')) {
// TODO: Rassembler les horaires qui sont dans le même jour, uniquement pour le front
// TODO: Rassembler les horaires qui sont dans le même jour, uniquement pour le front version.schedule = version.schedule.map((s: any) => {
let days = [...new Set(s.when.map((w: any) => w.day))]
return {
when: days.map((day: any) => {
return {
day,
wow: 'wow',
hours: s.when
.filter((w: any) => w.day === day)
.map((hour: any) => { return { from: hour.from, to: hour.to } })
}
}),
name: s.name,
description: s.description
}
})
}
version.schedule = version.schedule.map((s: any) => { version.cutDescription = Utils.isStrUsable(version, 'descriptionLong') && version.descriptionLong.length > 200
let days = [...new Set(s.when.map((w: any) => w.day))]
return {
when: days.map((day: any) => {
return {
day,
wow: 'wow',
hours: s.when
.filter((w: any) => w.day === day)
.map((hour: any) => { return { from: hour.from, to: hour.to } })
}
}),
name: s.name,
description: s.description
}
})
// if (version.cutDescription) { // if (version.cutDescription) {
// version.descriptionFirstHalf = version.descriptionLong.substr(0, 200) // not gonna lie // version.descriptionFirstHalf = version.descriptionLong.substr(0, 200) // not gonna lie
// version.descriptionSecondHalf = version.descriptionLong.substr(200) // version.descriptionSecondHalf = version.descriptionLong.substr(200)
// } // }
let hour = lastPublished.toLocaleTimeString('fr-FR', { timezone: '+2' }) // let hour = lastPublished.toLocaleTimeString('fr-FR', { timezone: '+2' })
if (hour.charAt(1) === ':') { // if (hour.charAt(1) === ':') {
hour = '0' + hour // hour = '0' + hour
} // }
res.render('organization.twig', { res.render('organization.twig', {
layout: 'standalone', layout: 'standalone',
data: version, data: version,
lastPublished: lastPublished.toLocaleDateString('fr-FR') + ' ' + hour.substr(0, 5), //lastPublished: lastPublished.toLocaleDateString('fr-FR') + ' ' + hour.substr(0, 5),
isProposed, isProposed,
id: org.get('_id') id: org.get('_id')
}) })
} }
}).catch(err => () => { }).catch(err => () => {
console.log(err) console.error(err)
return ErrorController.handleServerError(err, req, res, []) return ErrorController.handleServerError(err, req, res, [])
}) })
} }