-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Julien Bouquillon
committed
Nov 24, 2023
1 parent
52cf584
commit 4c0f339
Showing
3 changed files
with
92 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
'use strict'; | ||
"use strict"; | ||
|
||
/** | ||
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-services) | ||
* to customize this service | ||
*/ | ||
|
||
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 = { | |
<p>Bien cordialement,<br>Le back-office Tumeplay.</p> | ||
`, | ||
}, | ||
'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 = { | |
<p>Bien cordialement,<br>Le back-office Tumeplay.</p> | ||
`, | ||
}, | ||
'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 = { | |
<p>Bien cordialement,<br>Le back-office Tumeplay.</p> | ||
`, | ||
}, | ||
'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,91 +43,109 @@ const ALERTS_EMAILING = { | |
<p>Bien cordialement,<br>Le back-office Tumeplay.</p> | ||
`, | ||
}, | ||
'0': { | ||
0: { | ||
subject: '[ALERTE CRITIQUE] Plus de stock pour "%s"', | ||
text: 'La box "%s" n\'est plus disponible, pensez à réapprovisionner.', | ||
html: ` | ||
<p>Cher administrateur,</p> | ||
<p>La box <b>"%s"</b> n\'est plus disponible, pensez à réapprovisionner.</p> | ||
<p>Bien cordialement,<br>Le back-office Tumeplay.</p> | ||
`, | ||
} | ||
} | ||
}, | ||
}; | ||
|
||
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 <[email protected]>", | ||
} | ||
) | ||
); | ||
} 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 <[email protected]>", | ||
} | ||
) | ||
); | ||
} 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 <[email protected]>", | ||
} | ||
) | ||
); | ||
} 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 <[email protected]>", | ||
} | ||
) | ||
); | ||
} 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 <[email protected]>", | ||
} | ||
) | ||
); | ||
} | ||
|
||
return box && box.stock > 0; | ||
}, | ||
}; | ||
}; |
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 |
---|---|---|
|
@@ -359,6 +359,7 @@ module.exports = { | |
await strapi.plugins["email"].services.email.sendTemplatedEmail( | ||
{ | ||
to: entity.email, | ||
from: "Tumeplay <[email protected]>", | ||
}, | ||
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 protected]>", | ||
}, | ||
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 <[email protected]>", | ||
}, | ||
REFERENT_ORDER_CONFIRM, | ||
{ | ||
|
@@ -605,6 +610,7 @@ module.exports = { | |
await strapi.plugins["email"].services.email.sendTemplatedEmail( | ||
{ | ||
to: entity.email, | ||
from: "Tumeplay <[email protected]>", | ||
}, | ||
ORDER_REFERENT_NOTIFY_USER, | ||
{ | ||
|
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 |
---|---|---|
|
@@ -314,6 +314,7 @@ module.exports = { | |
|
||
await strapi.plugins["email"].services.email.sendTemplatedEmail( | ||
{ | ||
from: "Tumeplay <[email protected]>", | ||
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 <[email protected]>", | ||
}, | ||
CAT_TEMPLATE | ||
); | ||
|