From 05dbcb2dba4161309bc312a6058b2a96153275d2 Mon Sep 17 00:00:00 2001 From: Robson Tenorio Date: Thu, 19 May 2022 11:33:05 -0300 Subject: [PATCH] =?UTF-8?q?Implementa=C3=A7=C3=A3o=20das=20tags=20{{ms}},?= =?UTF-8?q?=20{{procol}}=20e=20{{hora}}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/helpers/Mustache.ts | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/backend/src/helpers/Mustache.ts b/backend/src/helpers/Mustache.ts index 92bd3de3..89eeff5b 100644 --- a/backend/src/helpers/Mustache.ts +++ b/backend/src/helpers/Mustache.ts @@ -2,8 +2,34 @@ import Mustache from "mustache"; import Contact from "../models/Contact"; export default (body: string, contact: Contact): string => { + + let ms = ""; + + const Hr = new Date(); + + const dd: string = ("0" + Hr.getDate()).slice(-2); + const mm: string = ("0" + (Hr.getMonth() + 1)).slice(-2); + const yy: string = Hr.getFullYear().toString(); + const hh: number = Hr.getHours(); + const min: string = ("0" + Hr.getMinutes()).slice(-2); + const ss: string = ("0" + Hr.getSeconds()).slice(-2); + + if (hh >= 6){ms = "Bom dia";} + if (hh > 11){ms = "Boa tarde";} + if (hh > 17){ms = "Boa noite";} + if (hh > 23 || hh < 6){ms = "Boa madrugada";} + + let protocol = yy+mm+dd+String(hh)+min+ss; + + let hora = hh+":"+min+":"+ss; + const view = { - name: contact ? contact.name : "" + name: contact ? contact.name : "", + ms: ms, + protocol: protocol, + hora: hora, }; + return Mustache.render(body, view); -}; + +}; \ No newline at end of file