Files
oneuptime/Common/Server/Services/StatusPageAnnouncementService.ts
Nawaz Dhandala 83b91af708 Refactor code for consistency and readability across various components
- Updated import statements for better formatting in multiple files.
- Added semicolons for consistency in BarChart and SparkChart components.
- Improved code readability by using braces for single-line if statements in various functions.
- Enhanced the structure of return statements for clarity in SubscriberNotificationStatus and other components.
- Refactored map functions to use explicit return statements for better readability.
- Cleaned up whitespace and formatting in multiple files for a more uniform code style.
2025-08-07 13:55:08 +01:00

57 lines
2.2 KiB
TypeScript

import DatabaseService from "./DatabaseService";
import Model from "../../Models/DatabaseModels/StatusPageAnnouncement";
import CreateBy from "../Types/Database/CreateBy";
import UpdateBy from "../Types/Database/UpdateBy";
import { OnCreate, OnUpdate } from "../Types/Database/Hooks";
import StatusPageSubscriberNotificationStatus from "../../Types/StatusPage/StatusPageSubscriberNotificationStatus";
export class Service extends DatabaseService<Model> {
public constructor() {
super(Model);
}
protected override async onBeforeCreate(
createBy: CreateBy<Model>,
): Promise<OnCreate<Model>> {
// Set notification status based on shouldStatusPageSubscribersBeNotified
if (createBy.data.shouldStatusPageSubscribersBeNotified === false) {
createBy.data.subscriberNotificationStatus =
StatusPageSubscriberNotificationStatus.Skipped;
createBy.data.subscriberNotificationStatusMessage =
"Notifications skipped as subscribers are not to be notified for this announcement.";
} else if (createBy.data.shouldStatusPageSubscribersBeNotified === true) {
createBy.data.subscriberNotificationStatus =
StatusPageSubscriberNotificationStatus.Pending;
}
return {
createBy,
carryForward: null,
};
}
protected override async onBeforeUpdate(
updateBy: UpdateBy<Model>,
): Promise<OnUpdate<Model>> {
// Set notification status based on shouldStatusPageSubscribersBeNotified if it's being updated
if (updateBy.data.shouldStatusPageSubscribersBeNotified !== undefined) {
if (updateBy.data.shouldStatusPageSubscribersBeNotified === false) {
updateBy.data.subscriberNotificationStatus =
StatusPageSubscriberNotificationStatus.Skipped;
updateBy.data.subscriberNotificationStatusMessage =
"Notifications skipped as subscribers are not to be notified for this announcement.";
} else if (updateBy.data.shouldStatusPageSubscribersBeNotified === true) {
updateBy.data.subscriberNotificationStatus =
StatusPageSubscriberNotificationStatus.Pending;
}
}
return {
updateBy,
carryForward: null,
};
}
}
export default new Service();