update
This commit is contained in:
parent
76fd9fb811
commit
fa6bc5f3f3
14 changed files with 224 additions and 47 deletions
|
|
@ -14,15 +14,18 @@ export default class EmailService {
|
|||
if (process.env.SMTP_HOST == undefined || process.env.SMTP_PORT == undefined) {
|
||||
throw new Error("Invalid SMTP config")
|
||||
}
|
||||
const config: any = {
|
||||
let config: any = {
|
||||
host: process.env.SMTP_HOST,
|
||||
port: parseInt(process.env.SMTP_PORT),
|
||||
secure: process.env.SMTP_SECURE == 'true',
|
||||
auth: {
|
||||
secure: process.env.SMTP_SECURE == 'true'
|
||||
}
|
||||
if (process.env.SMTP_USERNAME !== undefined && process.env.SMTP_PASSWORD !== undefined) {
|
||||
config.auth = {
|
||||
user: process.env.SMTP_USERNAME,
|
||||
pass: process.env.SMTP_PASSWORD,
|
||||
}
|
||||
}
|
||||
console.log(config)
|
||||
return nodemailer.createTransport(config)
|
||||
}
|
||||
|
||||
|
|
@ -54,8 +57,8 @@ export default class EmailService {
|
|||
const text: string = htmlToText.fromString(html, { wordwrap: 130 })
|
||||
|
||||
// for now replace every email by a predefined one
|
||||
console.info(to + ' replaced')
|
||||
to = "spamfree@matthieubessat.fr"
|
||||
// console.info(to + ' replaced')
|
||||
// to = "spamfree@matthieubessat.fr"
|
||||
subject += " - Forum des associations 2020"
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
@ -81,11 +84,11 @@ export default class EmailService {
|
|||
}
|
||||
|
||||
static getWebUiBaseUrl() {
|
||||
return process.env.WEB_UI_URL === undefined ? "URL_NOT_FOUND" : process.env.WEB_UI_URL
|
||||
return process.env.WEB_UI_URL === undefined ? "WEB_UI_URL_NOT_FOUND" : process.env.WEB_UI_URL
|
||||
}
|
||||
|
||||
static getBaseUrl() {
|
||||
return process.env.BASE_URL === undefined ? "URL_NOT_FOUND" : process.env.BASE_URL
|
||||
return process.env.BASE_URL === undefined ? "BASE_URL_NOT_FOUND" : process.env.BASE_URL
|
||||
}
|
||||
|
||||
static isMocked() {
|
||||
|
|
@ -93,4 +96,8 @@ export default class EmailService {
|
|||
// CUSTOM DESACTIVATION PLEASE ENABLE IN PRODUCTION
|
||||
return process.env.MOCK_EMAIL === "true"
|
||||
}
|
||||
|
||||
static getAdminAddress() {
|
||||
return process.env.ADMIN_ADDRESS === undefined ? "ADMIN_ADDRESS_NOT_FOUND" : process.env.ADMIN_ADDRESS
|
||||
}
|
||||
}
|
||||
|
|
@ -72,6 +72,7 @@ let main = async () => {
|
|||
.delete('/:id', AdminTagController.destroy)
|
||||
)
|
||||
.use('/organizations', express.Router()
|
||||
.post('/import', AdminOrganizationController.import)
|
||||
.get('/', AdminOrganizationController.getMany)
|
||||
.get('/:id', AdminOrganizationController.getOne)
|
||||
.post('', AdminOrganizationController.store)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,14 @@ export default class AdminOrganizationController {
|
|||
.catch(err => res.status(400).json({ success: false, errors: err }))
|
||||
}
|
||||
|
||||
static import(req: express.Request, res: express.Response) {
|
||||
const data = req.body.csv
|
||||
res.json({
|
||||
success: true,
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
static store(req: express.Request, res: express.Response) {
|
||||
let body: any = {
|
||||
token: AdminOrganizationController.generateToken(),
|
||||
|
|
@ -51,8 +59,8 @@ export default class AdminOrganizationController {
|
|||
extra.slug = slugify(req.body.name)
|
||||
}
|
||||
Organization.updateOne({ _id: req.params.id }, {
|
||||
...req.body,
|
||||
...extra,
|
||||
...req.body,
|
||||
updatedAt: new Date()
|
||||
})
|
||||
.then(data => res.json({ success: true, data }))
|
||||
|
|
@ -179,7 +187,7 @@ export default class AdminOrganizationController {
|
|||
}).then(updateData => {
|
||||
EmailService.send(
|
||||
data.get('email'),
|
||||
"Félicitation, vos changements ont été approvés et publiés !",
|
||||
"Félicitations, vos changements ont été approuvés et publiés !",
|
||||
"published",
|
||||
{
|
||||
adminName: data.get('adminName'),
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ export default class DelegateController {
|
|||
proposedVersion.gallery = []
|
||||
}
|
||||
if (Array.isArray(organization.proposedVersion.gallery)) {
|
||||
let toDeleteMedias = organization.proposedVersion.gallery.filter((media: any) =>
|
||||
// if a existing media is not in the new version we delete it AND in the published version
|
||||
proposedVersion.gallery.filter((m: any) => m.key === media.key).length === 0)
|
||||
let toDeleteMedias = organization.proposedVersion.gallery
|
||||
.filter((media: any) => proposedVersion.gallery.filter((m: any) => m.key === media.key).length === 0)
|
||||
.map((media: any) => media.key)
|
||||
MediaService.deleteMany(toDeleteMedias, 'galleryUpdated')
|
||||
}
|
||||
|
||||
|
|
@ -129,8 +129,8 @@ export default class DelegateController {
|
|||
// send email to the manager
|
||||
const organization: any = res.locals.organization
|
||||
EmailService.send(
|
||||
organization.email,
|
||||
"L'association \"" + organization.adminName + "\" demande à être vérifé",
|
||||
EmailService.getAdminAddress(),
|
||||
"L'association \"" + organization.adminName + "\" demande à être vérifié",
|
||||
"approval",
|
||||
{
|
||||
adminName: organization.adminName,
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ export default class PublicController {
|
|||
name: version.name,
|
||||
description: version.descriptionShort,
|
||||
thumbnail: version.thumbnail.location,
|
||||
tag: version.tag._id,
|
||||
tag: version.tag === null ? 'tag_not_found' : version.tag._id,
|
||||
slug: o.get('slug')
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue