feat: tipos e funcoes de alertas do e-licencie
This commit is contained in:
parent
02f9f3902b
commit
3693c8db24
11 changed files with 141 additions and 6 deletions
75
src/e-licencie/Alertas/funcoes_alertas.ts
Normal file
75
src/e-licencie/Alertas/funcoes_alertas.ts
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import dayjs from "dayjs"
|
||||
import weekOfYear from "dayjs/plugin/weekOfYear"
|
||||
import type { intervalosDosAlertas, tipos_alertas } from "./tipos"
|
||||
|
||||
dayjs.extend(weekOfYear)
|
||||
|
||||
export const enviarHoje = (
|
||||
inter: tipos_alertas["intervalo_alertas"] | null | undefined,
|
||||
data?: string,
|
||||
): boolean => {
|
||||
const hoje = dayjs(data || undefined)
|
||||
|
||||
if (!inter) return true
|
||||
|
||||
if (inter == "D") return true
|
||||
|
||||
if (inter == "M" && hoje.get("D") == 1) return true
|
||||
|
||||
if (inter == "S" && hoje.get("d") == 1) return true
|
||||
|
||||
if (inter == "S" && hoje.get("d") == 1 && hoje.week() % 2 == 1) return true
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
export const intervalosTipos = (
|
||||
tipoEntrada: keyof typeof intervalosDosAlertas | undefined | null,
|
||||
log: string[],
|
||||
): {
|
||||
campo_situacao: string //campo que será buscado nas tabelas alertas
|
||||
prefixo_assunto: string // texto que vai no prefixo
|
||||
tipo: string //tipo de intervalo
|
||||
enviar_hoje: boolean //indica se está habilitado para envio hoje
|
||||
} => {
|
||||
log.push(`intervalosTipos -> tipoEntrada:${tipoEntrada}`)
|
||||
|
||||
const config: {
|
||||
[k in keyof typeof intervalosDosAlertas]: {
|
||||
campo_situacao: string
|
||||
prefixo_assunto: string
|
||||
tipo: k
|
||||
enviar_hoje: boolean
|
||||
}
|
||||
} = {
|
||||
M: {
|
||||
campo_situacao: "situacao_texto_30",
|
||||
prefixo_assunto: "(Previsão para os próximos 30 dias) ",
|
||||
tipo: "M",
|
||||
enviar_hoje: enviarHoje("M"),
|
||||
},
|
||||
Q: {
|
||||
campo_situacao: "situacao_texto_15",
|
||||
prefixo_assunto: "(Previsão para os próximos 15 dias) ",
|
||||
tipo: "Q",
|
||||
enviar_hoje: enviarHoje("Q"),
|
||||
},
|
||||
S: {
|
||||
campo_situacao: "situacao_texto_7",
|
||||
prefixo_assunto: "(Previsão para os próximos 7 dias) ",
|
||||
tipo: "S",
|
||||
enviar_hoje: enviarHoje("S"),
|
||||
},
|
||||
D: {
|
||||
campo_situacao: "situacao_texto",
|
||||
prefixo_assunto: "",
|
||||
tipo: "D",
|
||||
enviar_hoje: enviarHoje("D"),
|
||||
},
|
||||
}
|
||||
|
||||
const { campo_situacao, enviar_hoje, prefixo_assunto, tipo } =
|
||||
config[tipoEntrada || "D"] || config.D
|
||||
log.push(campo_situacao, prefixo_assunto, tipo, enviar_hoje ? "S" : "N")
|
||||
return { campo_situacao, prefixo_assunto, tipo, enviar_hoje }
|
||||
}
|
||||
2
src/e-licencie/Alertas/index.ts
Normal file
2
src/e-licencie/Alertas/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export * from "./funcoes_alertas"
|
||||
export * from "./tipos"
|
||||
12
src/e-licencie/Alertas/tipos.ts
Normal file
12
src/e-licencie/Alertas/tipos.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
export type tipos_alertas = {
|
||||
intervalo_alertas: "D" | "S" | "Q" | "M"
|
||||
}
|
||||
|
||||
export const intervalosDosAlertas: {
|
||||
[k in tipos_alertas["intervalo_alertas"]]: string
|
||||
} = {
|
||||
D: "Diário",
|
||||
S: "Semanal, nas segundas-feira",
|
||||
Q: "Quinzenal, nas segundas-feira",
|
||||
M: "Mensal, primeiro dia de cada mês",
|
||||
}
|
||||
1
src/e-licencie/index.ts
Normal file
1
src/e-licencie/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "./Alertas"
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
export * from "./residuos"
|
||||
export * from "./NPS"
|
||||
export * from "./variaveis"
|
||||
export * from "./e-licencie"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue