Skip to content

Commit

Permalink
Correção do não envio dos Setores no primeiro contato
Browse files Browse the repository at this point in the history
  • Loading branch information
rtenorioh committed Feb 8, 2023
1 parent db346ae commit e2eb18f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 35 deletions.
46 changes: 22 additions & 24 deletions backend/src/helpers/Mustache.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,70 @@
/* eslint-disable prefer-template */
/* eslint-disable prettier/prettier */
/* eslint-disable @typescript-eslint/no-array-constructor */
import Mustache from "mustache";
import Ticket from "../models/Ticket";

export const msgsd = (): string => {

let ms = "";

const hh = new Date().getHours();

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";
}
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"; }

return ms;
};

export const control = (): string => {
const Hr = new Date();

const dd: string = `0${Hr.getDate()}`.slice(-2);
const mm: string = `0${Hr.getMonth() + 1}`.slice(-2);
const dd: string = ("0" + Hr.getDate()).slice(-2);
const mm: string = ("0" + (Hr.getMonth() + 1)).slice(-2);
const yy: string = Hr.getFullYear().toString();

const ctrl = `${yy + mm + dd}T`;
const ctrl = yy + mm + dd + "T";
return ctrl;
};

export const date = (): string => {
const Hr = new Date();

const dd: string = `0${Hr.getDate()}`.slice(-2);
const mm: string = `0${Hr.getMonth() + 1}`.slice(-2);
const dd: string = ("0" + Hr.getDate()).slice(-2);
const mm: string = ("0" + (Hr.getMonth() + 1)).slice(-2);
const yy: string = Hr.getFullYear().toString();

const dates = `${dd}-${mm}-${yy}`;
const dates = dd + "-" + mm + "-" + yy;
return dates;
};

export const hour = (): string => {
const Hr = new Date();

const hh: number = Hr.getHours();
const min: string = `0${Hr.getMinutes()}`.slice(-2);
const ss: string = `0${Hr.getSeconds()}`.slice(-2);
const min: string = ("0" + Hr.getMinutes()).slice(-2);
const ss: string = ("0" + Hr.getSeconds()).slice(-2);

const hours = `${hh}:${min}:${ss}`;
const hours = hh + ":" + min + ":" + ss;
return hours;
};

export default (body: string, ticket?: Ticket): string => {
const view = {
name: ticket ? ticket.contact.name : "",
user: ticket ? ticket?.user : "",
ticket_id: ticket ? ticket.id : "",
ms: msgsd(),
hour: hour(),
date: date(),
queue: ticket ? ticket?.queue?.name : "",
connection: ticket ? ticket.whatsapp.name : "",
user: ticket ? ticket?.user.name : "",
date_hour: [date(), hour()].join(" as "),
protocol: [control(), ticket ? ticket.id.toString() : ""].join("")
protocol: new Array(
control(),
ticket ? ticket.id.toString() : ""
).join(""),
};

return Mustache.render(body, view);
Expand Down
9 changes: 6 additions & 3 deletions backend/src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import pino from "pino";

const logger = pino({
prettyPrint: {
ignore: "pid,hostname"
transport: {
target: "pino-pretty",
options: {
colorize: true
}
},
level: "trace"
});

export { logger };
export { logger };
6 changes: 1 addition & 5 deletions frontend/src/components/MessageVariablesPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const MessageVariablesPicker = ({ onClick, disabled }) => {
},
{
name: i18n.t("messageVariablesPicker.vars.user"),
value: "{{user}} "
value: "{{user.name}} "
},
{
name: i18n.t("messageVariablesPicker.vars.greeting"),
Expand All @@ -44,10 +44,6 @@ const MessageVariablesPicker = ({ onClick, disabled }) => {
name: i18n.t("messageVariablesPicker.vars.hour"),
value: "{{hour}} "
},
{
name: i18n.t("messageVariablesPicker.vars.date_hour"),
value: "{{date_hour}} "
},
{
name: i18n.t("messageVariablesPicker.vars.ticket_id"),
value: "{{ticket_id}} "
Expand Down
1 change: 0 additions & 1 deletion frontend/src/translate/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const messages = {
protocolNumber: "Protocol",
date: "Date",
hour: "Hour",
date_hour: "Date and Time",
ticket_id: "Ticked ID",
queue: "Sector",
connection: "Connection"
Expand Down
1 change: 0 additions & 1 deletion frontend/src/translate/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const messages = {
protocolNumber: "Protocolo",
date: "Data",
hour: "Hora",
date_hour: "Data y Hora",
ticket_id: "Ticked ID",
queue: "Sector",
connection: "Conexión"
Expand Down
1 change: 0 additions & 1 deletion frontend/src/translate/languages/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const messages = {
protocolNumber: "Protocolo",
date: "Data",
hour: "Hora",
date_hour: "Data e Hora",
ticket_id: "Ticked ID",
queue: "Setor",
connection: "Conexão"
Expand Down

0 comments on commit e2eb18f

Please sign in to comment.