diff --git a/Common/Server/Services/AlertLogService.ts b/Common/Server/Services/AlertLogService.ts index 7de6e5f951f..dfb8fcec6bd 100644 --- a/Common/Server/Services/AlertLogService.ts +++ b/Common/Server/Services/AlertLogService.ts @@ -1,3 +1,4 @@ +import BadDataException from "../../Types/Exception/BadDataException"; import LogSeverity from "../../Types/Log/LogSeverity"; import ObjectID from "../../Types/ObjectID"; import DatabaseService from "./DatabaseService"; @@ -8,38 +9,57 @@ export class Service extends DatabaseService { super(Model); } - public async createAlertLog(data: { - alertId: ObjectID, - logInMarkdown: string, - alertLogEvent: AlertLogEvent, - projectId: ObjectID, - moreInformationInMarkdown?: string | undefined, - logSeverity?: LogSeverity | undefined, - }): Promise { - const alertLog: Model = new Model(); - - if(!data.logSeverity) { - data.logSeverity = LogSeverity.Unspecified; - } - - alertLog.alertLogSeverity = data.logSeverity; - - alertLog.alertId = data.alertId; - alertLog.logInMarkdown = data.logInMarkdown; - alertLog.alertLogEvent = data.alertLogEvent; - alertLog.projectId = data.projectId; - - if(data.moreInformationInMarkdown) { - alertLog.moreInformationInMarkdown = data.moreInformationInMarkdown; - } - - return await this.create({ - data: alertLog, - props: { - isRoot: true, - } - }) + public async createAlertLog(data: { + alertId: ObjectID, + logInMarkdown: string, + alertLogEvent: AlertLogEvent, + projectId: ObjectID, + moreInformationInMarkdown?: string | undefined, + logSeverity?: LogSeverity | undefined, + }): Promise { + + if (!data.alertId) { + throw new BadDataException("Alert ID is required"); } + + if (!data.logInMarkdown) { + throw new BadDataException("Log in markdown is required"); + } + + if (!data.alertLogEvent) { + throw new BadDataException("Alert log event is required"); + } + + if (!data.projectId) { + throw new BadDataException("Project ID is required"); + } + + + + const alertLog: Model = new Model(); + + if (!data.logSeverity) { + data.logSeverity = LogSeverity.Unspecified; + } + + alertLog.alertLogSeverity = data.logSeverity; + + alertLog.alertId = data.alertId; + alertLog.logInMarkdown = data.logInMarkdown; + alertLog.alertLogEvent = data.alertLogEvent; + alertLog.projectId = data.projectId; + + if (data.moreInformationInMarkdown) { + alertLog.moreInformationInMarkdown = data.moreInformationInMarkdown; + } + + return await this.create({ + data: alertLog, + props: { + isRoot: true, + } + }) + } } export default new Service(); diff --git a/Common/Server/Services/IncidentLogService.ts b/Common/Server/Services/IncidentLogService.ts index 903fbd47b10..e8a82886489 100644 --- a/Common/Server/Services/IncidentLogService.ts +++ b/Common/Server/Services/IncidentLogService.ts @@ -1,3 +1,4 @@ +import BadDataException from "../../Types/Exception/BadDataException"; import LogSeverity from "../../Types/Log/LogSeverity"; import ObjectID from "../../Types/ObjectID"; import DatabaseService from "./DatabaseService"; @@ -18,6 +19,22 @@ export class Service extends DatabaseService { }): Promise { const incidentLog: Model = new Model(); + if(!data.incidentId){ + throw new BadDataException("Incident ID is required"); + } + + if(!data.logInMarkdown){ + throw new BadDataException("Log in markdown is required"); + } + + if(!data.incidentLogEvent){ + throw new BadDataException("Incident log event is required"); + } + + if(!data.projectId){ + throw new BadDataException("Project ID is required"); + } + if(!data.logSeverity) { data.logSeverity = LogSeverity.Unspecified; } diff --git a/Common/Server/Services/ScheduledMaintenanceLogService.ts b/Common/Server/Services/ScheduledMaintenanceLogService.ts index df0aaebbccc..5b71b7cf4e0 100644 --- a/Common/Server/Services/ScheduledMaintenanceLogService.ts +++ b/Common/Server/Services/ScheduledMaintenanceLogService.ts @@ -1,3 +1,4 @@ +import BadDataException from "../../Types/Exception/BadDataException"; import LogSeverity from "../../Types/Log/LogSeverity"; import ObjectID from "../../Types/ObjectID"; import DatabaseService from "./DatabaseService"; @@ -17,6 +18,21 @@ export class Service extends DatabaseService { logSeverity?: LogSeverity | undefined, }): Promise { + if (!data.scheduledMaintenanceId) { + throw new BadDataException("Scheduled Maintenance ID is required"); + } + + if (!data.logInMarkdown) { + throw new BadDataException("Log in markdown is required"); + } + + if (!data.scheduledMaintenanceLogEvent) { + throw new BadDataException("Scheduled Maintenance log event is required"); + } + + if (!data.projectId) { + throw new BadDataException("Project ID is required"); + } if(!data.logSeverity) { data.logSeverity = LogSeverity.Unspecified;