Skip to content

Commit

Permalink
feat: add severity fields to AlertLog, IncidentLog, and ScheduledMain…
Browse files Browse the repository at this point in the history
…tenanceLog models
  • Loading branch information
simlarsen committed Jan 12, 2025
1 parent b4a2726 commit e737444
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 3 deletions.
29 changes: 29 additions & 0 deletions Common/Models/DatabaseModels/AlertLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import IconProp from "../../Types/Icon/IconProp";
import ObjectID from "../../Types/ObjectID";
import Permission from "../../Types/Permission";
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
import LogSeverity from "../../Types/Log/LogSeverity";

export enum AlertLogEvent {
PublicNote = "PublicNote",
Expand Down Expand Up @@ -391,4 +392,32 @@ export default class AlertLog extends BaseModel {
unique: false,
})
public alertLogEvent?: AlertLogEvent = undefined;

@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CreateAlertLog,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.ReadAlertLog,
],
update: [],
})
@TableColumn({
type: TableColumnType.ShortText,
required: true,
title: "Alert Log Severity",
description: "Alert Log Severity",
})
@Column({
type: ColumnType.ShortText,
nullable: false,
unique: false,
})
public alertLogSeverity?: LogSeverity = undefined;
}
30 changes: 30 additions & 0 deletions Common/Models/DatabaseModels/IncidentLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import IconProp from "../../Types/Icon/IconProp";
import ObjectID from "../../Types/ObjectID";
import Permission from "../../Types/Permission";
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
import LogSeverity from "../../Types/Log/LogSeverity";

export enum IncidentLogEvent {
PublicNote = "PublicNote",
Expand All @@ -29,6 +30,7 @@ export enum IncidentLogEvent {
PrivateNote = "PrivateNote",
}


@EnableDocumentation()
@CanAccessIfCanReadOn("incident")
@TenantColumn("projectId")
Expand Down Expand Up @@ -391,4 +393,32 @@ export default class IncidentLog extends BaseModel {
unique: false,
})
public incidentLogEvent?: IncidentLogEvent = undefined;

@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CreateIncidentLog,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.ReadIncidentLog,
],
update: [],
})
@TableColumn({
type: TableColumnType.ShortText,
required: true,
title: "Incident Log Severity",
description: "Incident Log Severity",
})
@Column({
type: ColumnType.ShortText,
nullable: false,
unique: false,
})
public incidentLogSeverity?: LogSeverity = undefined;
}
30 changes: 30 additions & 0 deletions Common/Models/DatabaseModels/ScheduledMaintenanceLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import IconProp from "../../Types/Icon/IconProp";
import ObjectID from "../../Types/ObjectID";
import Permission from "../../Types/Permission";
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
import LogSeverity from "../../Types/Log/LogSeverity";

export enum ScheduledMaintenanceLogEvent {
PublicNote = "PublicNote",
Expand Down Expand Up @@ -395,4 +396,33 @@ export default class ScheduledMaintenanceLog extends BaseModel {
})
public scheduledMaintenanceLogEvent?: ScheduledMaintenanceLogEvent =
undefined;

@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.CreateScheduledMaintenanceLog,
],
read: [
Permission.ProjectOwner,
Permission.ProjectAdmin,
Permission.ProjectMember,
Permission.ReadScheduledMaintenanceLog,
],
update: [],
})
@TableColumn({
type: TableColumnType.ShortText,
required: true,
title: "Scheduled Maintenance Log Severity",
description: "Scheduled Maintenance Log Severity",
})
@Column({
type: ColumnType.ShortText,
nullable: false,
unique: false,
})
public scheduledMaintenanceLogSeverity?: LogSeverity = undefined;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MigrationName1736703138918 implements MigrationInterface {
public name = 'MigrationName1736703138918'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "IncidentLog" ADD "incidentLogSeverity" character varying NOT NULL`);
await queryRunner.query(`ALTER TABLE "AlertLog" ADD "alertLogSeverity" character varying NOT NULL`);
await queryRunner.query(`ALTER TABLE "ScheduledMaintenanceLog" ADD "scheduledMaintenanceLogSeverity" character varying NOT NULL`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "ScheduledMaintenanceLog" DROP COLUMN "scheduledMaintenanceLogSeverity"`);
await queryRunner.query(`ALTER TABLE "AlertLog" DROP COLUMN "alertLogSeverity"`);
await queryRunner.query(`ALTER TABLE "IncidentLog" DROP COLUMN "incidentLogSeverity"`);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import { MigrationName1736364478985 } from "./1736364478985-MigrationName";
import { MigrationName1736364957990 } from "./1736364957990-MigrationName";
import { MigrationName1736365532085 } from "./1736365532085-MigrationName";
import { MigrationName1736675947746 } from "./1736675947746-MigrationName";
import { MigrationName1736703138918 } from "./1736703138918-MigrationName";

export default [
InitialMigration,
Expand Down Expand Up @@ -180,4 +181,5 @@ export default [
MigrationName1736364957990,
MigrationName1736365532085,
MigrationName1736675947746,
MigrationName1736703138918
];
37 changes: 36 additions & 1 deletion Common/Server/Services/AlertLogService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
import LogSeverity from "../../Types/Log/LogSeverity";
import ObjectID from "../../Types/ObjectID";
import DatabaseService from "./DatabaseService";
import Model from "Common/Models/DatabaseModels/AlertLog";
import Model, { AlertLogEvent } from "Common/Models/DatabaseModels/AlertLog";

export class Service extends DatabaseService<Model> {
public constructor() {
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,
}
})
}
}

export default new Service();
35 changes: 34 additions & 1 deletion Common/Server/Services/IncidentLogService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
import LogSeverity from "../../Types/Log/LogSeverity";
import ObjectID from "../../Types/ObjectID";
import DatabaseService from "./DatabaseService";
import Model from "Common/Models/DatabaseModels/IncidentLog";
import Model, { IncidentLogEvent } from "Common/Models/DatabaseModels/IncidentLog";

export class Service extends DatabaseService<Model> {
public constructor() {
super(Model);
}

public async createIncidentLog(data: {
incidentId: ObjectID,
logInMarkdown: string,
incidentLogEvent: IncidentLogEvent,
projectId: ObjectID,
moreInformationInMarkdown?: string | undefined,
logSeverity?: LogSeverity | undefined,
}): Promise<Model> {
const incidentLog: Model = new Model();

if(!data.logSeverity) {
data.logSeverity = LogSeverity.Unspecified;
}
incidentLog.incidentLogSeverity = data.logSeverity;
incidentLog.incidentId = data.incidentId;
incidentLog.logInMarkdown = data.logInMarkdown;
incidentLog.incidentLogEvent = data.incidentLogEvent;
incidentLog.projectId = data.projectId;

if(data.moreInformationInMarkdown) {
incidentLog.moreInformationInMarkdown = data.moreInformationInMarkdown;
}

return await this.create({
data: incidentLog,
props: {
isRoot: true,
}
})
}
}

export default new Service();
39 changes: 38 additions & 1 deletion Common/Server/Services/ScheduledMaintenanceLogService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
import LogSeverity from "../../Types/Log/LogSeverity";
import ObjectID from "../../Types/ObjectID";
import DatabaseService from "./DatabaseService";
import Model from "Common/Models/DatabaseModels/ScheduledMaintenanceLog";
import Model, { ScheduledMaintenanceLogEvent } from "Common/Models/DatabaseModels/ScheduledMaintenanceLog";

export class Service extends DatabaseService<Model> {
public constructor() {
super(Model);
}

public async createScheduledMaintenanceLog(data: {
scheduledMaintenanceId: ObjectID,
logInMarkdown: string,
scheduledMaintenanceLogEvent: ScheduledMaintenanceLogEvent,
projectId: ObjectID,
moreInformationInMarkdown?: string | undefined,
logSeverity?: LogSeverity | undefined,
}): Promise<Model> {


if(!data.logSeverity) {
data.logSeverity = LogSeverity.Unspecified;
}

const scheduledMaintenanceLog: Model = new Model();

scheduledMaintenanceLog.scheduledMaintenanceLogSeverity = data.logSeverity;
scheduledMaintenanceLog.scheduledMaintenanceId = data.scheduledMaintenanceId;
scheduledMaintenanceLog.logInMarkdown = data.logInMarkdown;
scheduledMaintenanceLog.scheduledMaintenanceLogEvent = data.scheduledMaintenanceLogEvent;
scheduledMaintenanceLog.projectId = data.projectId;


if (data.moreInformationInMarkdown) {
scheduledMaintenanceLog.moreInformationInMarkdown = data.moreInformationInMarkdown;
}

return await this.create({
data: scheduledMaintenanceLog,
props: {
isRoot: true,
}
})
}
}

export default new Service();

0 comments on commit e737444

Please sign in to comment.