fix: Saturday message not matching with database enabled/disabled

feat-scaling-ticket-remote-creation
adriano 2024-04-01 17:51:45 -03:00
parent 4b9dca2401
commit 88a71e5758
2 changed files with 34 additions and 24 deletions

View File

@ -213,7 +213,7 @@ export const remoteTicketCreation = async (
undefined, undefined,
queueId queueId
); );
botSendMessage(ticket, `\u200e${msg}`); botSendMessage(ticket, `${msg}`);
} }
const io = getIO(); const io = getIO();
@ -408,7 +408,6 @@ export const update = async (
for (const w of whatsappsByqueue) { for (const w of whatsappsByqueue) {
let whats = await ListWhatsAppsNumber(w.id); let whats = await ListWhatsAppsNumber(w.id);
console.log("-------> WHATS: ", JSON.stringify(whats, null, 6));
const ticket = await Ticket.findOne({ const ticket = await Ticket.findOne({
where: { where: {
[Op.and]: [ [Op.and]: [

View File

@ -62,21 +62,8 @@ const isWeekend = async (number: string | number) => {
weekend.value == "enabled" && weekend.value == "enabled" &&
weekend.message?.trim()?.length > 0 weekend.message?.trim()?.length > 0
) { ) {
// Specify your desired timezone
const brazilTimeZone = "America/Sao_Paulo";
const currentDateUtc = new Date();
// Convert UTC date to Brazil time zone
const currentDate = utcToZonedTime(currentDateUtc, brazilTimeZone);
// Format the date using the desired format
const formattedDate = _format(currentDate, "yyyy-MM-dd HH:mm:ssXXX");
const parsedDate = parseISO(formattedDate);
// Convert parsed date to Brazil time zone // Convert parsed date to Brazil time zone
const localDate = utcToZonedTime(parsedDate, brazilTimeZone); const localDate = localDateConvert();
// Check if it's Saturday or Sunday // Check if it's Saturday or Sunday
if (isSaturday(localDate)) { if (isSaturday(localDate)) {
@ -176,6 +163,14 @@ async function isOutBusinessTime(number: string | number) {
async function isOutBusinessTimeSaturday(number: string | number) { async function isOutBusinessTimeSaturday(number: string | number) {
let obj = { set: false, msg: "" }; let obj = { set: false, msg: "" };
// Convert parsed date to Brazil time zone
const localDate = localDateConvert();
// Check if it's Saturday or Sunday
if (!isSaturday(localDate)) {
return obj;
}
const outBusinessHoursSaturday = await SettingTicket.findOne({ const outBusinessHoursSaturday = await SettingTicket.findOne({
where: { key: "saturdayBusinessTime", number } where: { key: "saturdayBusinessTime", number }
}); });
@ -183,11 +178,9 @@ async function isOutBusinessTimeSaturday(number: string | number) {
let isWithinRange = false; let isWithinRange = false;
if ( if (
true && outBusinessHoursSaturday &&
outBusinessHoursSaturday outBusinessHoursSaturday.value == "enabled" &&
// outBusinessHoursSaturday && outBusinessHoursSaturday?.message?.trim()?.length > 0
// outBusinessHoursSaturday.value == "enabled" &&
// outBusinessHoursSaturday?.message?.trim()?.length > 0
) { ) {
const ticketDateTimeUpdate = splitDateTime( const ticketDateTimeUpdate = splitDateTime(
new Date( new Date(
@ -249,4 +242,22 @@ async function isOutBusinessTimeSaturday(number: string | number) {
return obj; return obj;
} }
function localDateConvert() {
const brazilTimeZone = "America/Sao_Paulo";
const currentDateUtc = new Date();
// Convert UTC date to Brazil time zone
const currentDate = utcToZonedTime(currentDateUtc, brazilTimeZone);
// Format the date using the desired format
const formattedDate = _format(currentDate, "yyyy-MM-dd HH:mm:ssXXX");
const parsedDate = parseISO(formattedDate);
// Convert parsed date to Brazil time zone
const localDate = utcToZonedTime(parsedDate, brazilTimeZone);
return localDate;
}
export { isWeekend, isHoliday, isOutBusinessTime, isOutBusinessTimeSaturday }; export { isWeekend, isHoliday, isOutBusinessTime, isOutBusinessTimeSaturday };