diff --git a/back-strapi/api/box/services/box.js b/back-strapi/api/box/services/box.js index 4af734a4..fcaca7b0 100644 --- a/back-strapi/api/box/services/box.js +++ b/back-strapi/api/box/services/box.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; /** * Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-services) @@ -6,8 +6,8 @@ */ const ALERTS_EMAILING = { - to: strapi.config.get('server.emails.admin'), - '500' : { + to: strapi.config.get("server.emails.admin"), + 500: { subject: '[ALERTE] Seuil des 500 atteint pour "%s"', text: 'La box "%s" a atteint le seuil des 500, pensez à réapprovisionner', html: ` @@ -16,7 +16,7 @@ const ALERTS_EMAILING = {

Bien cordialement,
Le back-office Tumeplay.

`, }, - '100': { + 100: { subject: '[ALERTE] Seuil des 100 atteint pour "%s"', text: 'La box "%s" a atteint le seuil des 100, pensez à réapprovisionner', html: ` @@ -25,7 +25,7 @@ const ALERTS_EMAILING = {

Bien cordialement,
Le back-office Tumeplay.

`, }, - '50': { + 50: { subject: '[ALERTE] Seuil des 50 atteint pour "%s"', text: 'La box "%s" a atteint le seuil des 50, pensez à réapprovisionner', html: ` @@ -34,7 +34,7 @@ const ALERTS_EMAILING = {

Bien cordialement,
Le back-office Tumeplay.

`, }, - '10': { + 10: { subject: '[ALERTE] Seuil des 10 atteint pour "%s"', text: 'La box "%s" a atteint le seuil des 10, pensez à réapprovisionner', html: ` @@ -43,7 +43,7 @@ const ALERTS_EMAILING = {

Bien cordialement,
Le back-office Tumeplay.

`, }, - '0': { + 0: { subject: '[ALERTE CRITIQUE] Plus de stock pour "%s"', text: 'La box "%s" n\'est plus disponible, pensez à réapprovisionner.', html: ` @@ -51,83 +51,101 @@ const ALERTS_EMAILING = {

La box "%s" n\'est plus disponible, pensez à réapprovisionner.

Bien cordialement,
Le back-office Tumeplay.

`, - } -} + }, +}; function parse(str) { var args = [].slice.call(arguments, 1), - i = 0; + i = 0; return str.replace(/%s/g, () => args[i++]); } - module.exports = { +module.exports = { async decrement(box_id, quantity) { - await strapi.query('box').model.query((qb) => { - qb.where('id', box_id); - qb.increment('stock', - quantity); - }).fetch(); + await strapi + .query("box") + .model.query((qb) => { + qb.where("id", box_id); + qb.increment("stock", -quantity); + }) + .fetch(); }, async checkBoxAvailability(box_id) { - const box = await strapi.services.box.findOne({ id: box_id }) + const box = await strapi.services.box.findOne({ id: box_id }); if (box && box.stock == 501) { - await strapi.plugins['email'].services.email.send( - Object.assign({ - subject: parse(ALERTS_EMAILING['500'].subject, box.title), - text: parse(ALERTS_EMAILING['500'].text, box.title), - html: parse(ALERTS_EMAILING['500'].html, box.title), - }, - { - to: ALERTS_EMAILING.to - }) + await strapi.plugins["email"].services.email.send( + Object.assign( + { + subject: parse(ALERTS_EMAILING["500"].subject, box.title), + text: parse(ALERTS_EMAILING["500"].text, box.title), + html: parse(ALERTS_EMAILING["500"].html, box.title), + }, + { + to: ALERTS_EMAILING.to, + from: "Tumeplay ", + } + ) ); } else if (box && box.stock == 101) { - await strapi.plugins['email'].services.email.send( - Object.assign({ - subject: parse(ALERTS_EMAILING['100'].subject, box.title), - text: parse(ALERTS_EMAILING['100'].text, box.title), - html: parse(ALERTS_EMAILING['100'].html, box.title), - }, - { - to: ALERTS_EMAILING.to - }) + await strapi.plugins["email"].services.email.send( + Object.assign( + { + subject: parse(ALERTS_EMAILING["100"].subject, box.title), + text: parse(ALERTS_EMAILING["100"].text, box.title), + html: parse(ALERTS_EMAILING["100"].html, box.title), + }, + { + to: ALERTS_EMAILING.to, + from: "Tumeplay ", + } + ) ); } else if (box && box.stock == 51) { - await strapi.plugins['email'].services.email.send( - Object.assign({ - subject: parse(ALERTS_EMAILING['50'].subject, box.title), - text: parse(ALERTS_EMAILING['50'].text, box.title), - html: parse(ALERTS_EMAILING['50'].html, box.title), - }, - { - to: ALERTS_EMAILING.to - }) + await strapi.plugins["email"].services.email.send( + Object.assign( + { + subject: parse(ALERTS_EMAILING["50"].subject, box.title), + text: parse(ALERTS_EMAILING["50"].text, box.title), + html: parse(ALERTS_EMAILING["50"].html, box.title), + }, + { + to: ALERTS_EMAILING.to, + from: "Tumeplay ", + } + ) ); } else if (box && box.stock == 11) { - await strapi.plugins['email'].services.email.send( - Object.assign({ - subject: parse(ALERTS_EMAILING['10'].subject, box.title), - text: parse(ALERTS_EMAILING['10'].text, box.title), - html: parse(ALERTS_EMAILING['10'].html, box.title), - }, - { - to: ALERTS_EMAILING.to - }) + await strapi.plugins["email"].services.email.send( + Object.assign( + { + subject: parse(ALERTS_EMAILING["10"].subject, box.title), + text: parse(ALERTS_EMAILING["10"].text, box.title), + html: parse(ALERTS_EMAILING["10"].html, box.title), + }, + { + to: ALERTS_EMAILING.to, + from: "Tumeplay ", + } + ) ); } else if (box && box.stock == 1) { - await strapi.plugins['email'].services.email.send( - Object.assign({ - subject: parse(ALERTS_EMAILING['0'].subject, box.title), - text: parse(ALERTS_EMAILING['0'].text, box.title), - html: parse(ALERTS_EMAILING['0'].html, box.title), - }, - { - to: ALERTS_EMAILING.to - }) + await strapi.plugins["email"].services.email.send( + Object.assign( + { + subject: parse(ALERTS_EMAILING["0"].subject, box.title), + text: parse(ALERTS_EMAILING["0"].text, box.title), + html: parse(ALERTS_EMAILING["0"].html, box.title), + }, + { + to: ALERTS_EMAILING.to, + from: "Tumeplay ", + } + ) ); } return box && box.stock > 0; }, -}; \ No newline at end of file +}; diff --git a/back-strapi/api/commande/controllers/commande.js b/back-strapi/api/commande/controllers/commande.js index 5a1102f0..e202a19e 100644 --- a/back-strapi/api/commande/controllers/commande.js +++ b/back-strapi/api/commande/controllers/commande.js @@ -359,6 +359,7 @@ module.exports = { await strapi.plugins["email"].services.email.sendTemplatedEmail( { to: entity.email, + from: "Tumeplay ", }, EMAIL_ORDER_CONFIRM, { @@ -380,7 +381,7 @@ module.exports = { ), } ); - } catch(e) { + } catch (e) { console.error("EMAIL ERR", e); } } @@ -423,9 +424,12 @@ module.exports = { if (!referent.openingHours) referent.openingHours = {}; try { - const sendResult = await strapi.plugins["email"].services.email.sendTemplatedEmail( + const sendResult = await strapi.plugins[ + "email" + ].services.email.sendTemplatedEmail( { to: entity.email, + from: "Tumeplay ", }, EMAIL_ORDER_CONFIRM_REF, { @@ -449,8 +453,8 @@ module.exports = { } ); console.log(sendResult); - console.log(JSON.stringify(sendResult,null,2)); - } catch(e) { + console.log(JSON.stringify(sendResult, null, 2)); + } catch (e) { console.error("Email referent error", e); } } @@ -464,6 +468,7 @@ module.exports = { await strapi.plugins["email"].services.email.sendTemplatedEmail( { to: users_email.join(","), + from: "Tumeplay ", }, REFERENT_ORDER_CONFIRM, { @@ -605,6 +610,7 @@ module.exports = { await strapi.plugins["email"].services.email.sendTemplatedEmail( { to: entity.email, + from: "Tumeplay ", }, ORDER_REFERENT_NOTIFY_USER, { diff --git a/back-strapi/config/functions/cron.js b/back-strapi/config/functions/cron.js index 603f8d90..ee9b0bff 100644 --- a/back-strapi/config/functions/cron.js +++ b/back-strapi/config/functions/cron.js @@ -314,6 +314,7 @@ module.exports = { await strapi.plugins["email"].services.email.sendTemplatedEmail( { + from: "Tumeplay ", to: strapi.config.get("server.emails.cat"), cc: strapi.config.get("server.emails.admin"), attachments: attachments, @@ -375,6 +376,7 @@ module.exports = { strapi.plugins["email"].services.email.sendTemplatedEmail( { to: user.email, + from: "Tumeplay ", }, CAT_TEMPLATE );