Skip to content

Commit

Permalink
feat: add validation for required fields in AlertLogService, Incident…
Browse files Browse the repository at this point in the history
…LogService, and ScheduledMaintenanceLogService
  • Loading branch information
simlarsen committed Jan 12, 2025
1 parent e737444 commit a685963
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 31 deletions.
82 changes: 51 additions & 31 deletions Common/Server/Services/AlertLogService.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -8,38 +9,57 @@ export class Service extends DatabaseService<Model> {
super(Model);
}

public async createAlertLog(data: {
alertId: ObjectID,
logInMarkdown: string,
alertLogEvent: AlertLogEvent,
projectId: ObjectID,
moreInformationInMarkdown?: string | undefined,
logSeverity?: LogSeverity | undefined,
}): Promise<Model> {
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<Model> {

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();
17 changes: 17 additions & 0 deletions Common/Server/Services/IncidentLogService.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -18,6 +19,22 @@ export class Service extends DatabaseService<Model> {
}): Promise<Model> {
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;
}
Expand Down
16 changes: 16 additions & 0 deletions Common/Server/Services/ScheduledMaintenanceLogService.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -17,6 +18,21 @@ export class Service extends DatabaseService<Model> {
logSeverity?: LogSeverity | undefined,
}): Promise<Model> {

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;
Expand Down

0 comments on commit a685963

Please sign in to comment.