Enhance Service Messages by Config & activeUntil #9
This commit is contained in:
@@ -3,19 +3,23 @@ import { prisma, Prisma } from "@repo/db";
|
||||
|
||||
export const addMessage = async (message: Prisma.NotamCreateInput) => {
|
||||
try {
|
||||
// Set all current messages with isMainMsg=true to active=false
|
||||
await prisma.notam.updateMany({
|
||||
where: { isMainMsg: true },
|
||||
where: { active: true },
|
||||
data: { active: false },
|
||||
});
|
||||
|
||||
const showUntil = new Date(message.showUntil);
|
||||
const showUntilActive = showUntil > new Date();
|
||||
|
||||
await prisma.notam.create({
|
||||
data: {
|
||||
message: message.message,
|
||||
color: message.color,
|
||||
isMainMsg: true,
|
||||
active: true,
|
||||
showUntil: new Date().toISOString(),
|
||||
wartungsmodus: message.wartungsmodus,
|
||||
disableHPG: message.disableHPG,
|
||||
showUntilActive,
|
||||
showUntil,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -25,9 +29,8 @@ export const addMessage = async (message: Prisma.NotamCreateInput) => {
|
||||
|
||||
export const disableMessage = async () => {
|
||||
try {
|
||||
// Set all current messages with isMainMsg=true to active=false
|
||||
await prisma.notam.updateMany({
|
||||
where: { isMainMsg: true },
|
||||
where: { active: true },
|
||||
data: { active: false },
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user