Skip to content

Commit

Permalink
refactor: clean up whitespace and improve code readability in various…
Browse files Browse the repository at this point in the history
… models and services
  • Loading branch information
simlarsen committed Jan 17, 2025
1 parent af77d19 commit 8b30413
Show file tree
Hide file tree
Showing 14 changed files with 273 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ export default class OnCallDutyPolicyExecutionLogTimeline extends BaseModel {
})
public triggeredByIncidentId?: ObjectID = undefined;



@ColumnAccessControl({
create: [],
read: [
Expand Down
4 changes: 1 addition & 3 deletions Common/Models/DatabaseModels/UserNotificationRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,7 @@ class UserNotificationRule extends BaseModel {
})
public incidentSeverityId?: ObjectID = undefined;


// alert severity.
// alert severity.

@ColumnAccessControl({
create: [Permission.CurrentUser],
Expand Down Expand Up @@ -501,7 +500,6 @@ class UserNotificationRule extends BaseModel {
transformer: ObjectID.getDatabaseTransformer(),
})
public alertSeverityId?: ObjectID = undefined;

}

export default UserNotificationRule;
5 changes: 1 addition & 4 deletions Common/Models/DatabaseModels/UserOnCallLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,6 @@ export default class UserOnCallLog extends BaseModel {
})
public triggeredByIncidentId?: ObjectID = undefined;



@ColumnAccessControl({
create: [],
read: [Permission.CurrentUser],
Expand All @@ -391,8 +389,7 @@ export default class UserOnCallLog extends BaseModel {
type: TableColumnType.Entity,
modelType: Alert,
title: "Triggered By Alert",
description:
"Relation to Alert which triggered this on-call duty policy.",
description: "Relation to Alert which triggered this on-call duty policy.",
})
@ManyToOne(
() => {
Expand Down
2 changes: 0 additions & 2 deletions Common/Models/DatabaseModels/UserOnCallLogTimeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,6 @@ export default class UserOnCallLogTimeline extends BaseModel {
})
public triggeredByIncidentId?: ObjectID = undefined;



@ColumnAccessControl({
create: [],
read: [Permission.CurrentUser],
Expand Down
2 changes: 0 additions & 2 deletions Common/Server/API/UserOnCallLogTimelineAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ export default class UserNotificationLogTimelineAPI extends BaseAPI<
const httpProtocol: Protocol = await DatabaseConfig.getHttpProtocol();

if (timelineItem.triggeredByIncidentId) {

return Response.redirect(
req,
res,
Expand All @@ -165,7 +164,6 @@ export default class UserNotificationLogTimelineAPI extends BaseAPI<
}

if (timelineItem.triggeredByAlertId) {

return Response.redirect(
req,
res,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,131 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class MigrationName1737141420441 implements MigrationInterface {
public name = 'MigrationName1737141420441'
public name = "MigrationName1737141420441";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ADD "triggeredByAlertId" uuid`);
await queryRunner.query(`ALTER TABLE "UserNotificationRule" ADD "alertSeverityId" uuid`);
await queryRunner.query(`ALTER TABLE "UserOnCallLog" ADD "triggeredByAlertId" uuid`);
await queryRunner.query(`ALTER TABLE "UserOnCallLogTimeline" ADD "triggeredByAlertId" uuid`);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" DROP CONSTRAINT "FK_90119ec7f77fa2efd82261e0448"`);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ALTER COLUMN "triggeredByIncidentId" DROP NOT NULL`);
await queryRunner.query(`ALTER TABLE "UserOnCallLog" DROP CONSTRAINT "FK_eeb0dd05d1dec542c3de5fb5074"`);
await queryRunner.query(`ALTER TABLE "UserOnCallLog" ALTER COLUMN "triggeredByIncidentId" DROP NOT NULL`);
await queryRunner.query(`ALTER TABLE "UserOnCallLogTimeline" DROP CONSTRAINT "FK_58a44736718a5ec4fe41526289a"`);
await queryRunner.query(`ALTER TABLE "UserOnCallLogTimeline" ALTER COLUMN "triggeredByIncidentId" DROP NOT NULL`);
await queryRunner.query(`CREATE INDEX "IDX_30358ab25e4c6c9ad72e74f201" ON "OnCallDutyPolicyExecutionLogTimeline" ("triggeredByAlertId") `);
await queryRunner.query(`CREATE INDEX "IDX_d73339f6c26fd6ebd0326badcd" ON "UserNotificationRule" ("alertSeverityId") `);
await queryRunner.query(`CREATE INDEX "IDX_42d9916277fcbefa0cdd3904c6" ON "UserOnCallLogTimeline" ("triggeredByAlertId") `);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ADD CONSTRAINT "FK_90119ec7f77fa2efd82261e0448" FOREIGN KEY ("triggeredByIncidentId") REFERENCES "Incident"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ADD CONSTRAINT "FK_30358ab25e4c6c9ad72e74f201c" FOREIGN KEY ("triggeredByAlertId") REFERENCES "Alert"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "UserNotificationRule" ADD CONSTRAINT "FK_d73339f6c26fd6ebd0326badcd7" FOREIGN KEY ("alertSeverityId") REFERENCES "AlertSeverity"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "UserOnCallLog" ADD CONSTRAINT "FK_eeb0dd05d1dec542c3de5fb5074" FOREIGN KEY ("triggeredByIncidentId") REFERENCES "Incident"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "UserOnCallLog" ADD CONSTRAINT "FK_0ee3711cdc64957845d9d028c31" FOREIGN KEY ("triggeredByAlertId") REFERENCES "Alert"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "UserOnCallLogTimeline" ADD CONSTRAINT "FK_58a44736718a5ec4fe41526289a" FOREIGN KEY ("triggeredByIncidentId") REFERENCES "Incident"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "UserOnCallLogTimeline" ADD CONSTRAINT "FK_42d9916277fcbefa0cdd3904c63" FOREIGN KEY ("triggeredByAlertId") REFERENCES "Alert"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "UserOnCallLogTimeline" DROP CONSTRAINT "FK_42d9916277fcbefa0cdd3904c63"`);
await queryRunner.query(`ALTER TABLE "UserOnCallLogTimeline" DROP CONSTRAINT "FK_58a44736718a5ec4fe41526289a"`);
await queryRunner.query(`ALTER TABLE "UserOnCallLog" DROP CONSTRAINT "FK_0ee3711cdc64957845d9d028c31"`);
await queryRunner.query(`ALTER TABLE "UserOnCallLog" DROP CONSTRAINT "FK_eeb0dd05d1dec542c3de5fb5074"`);
await queryRunner.query(`ALTER TABLE "UserNotificationRule" DROP CONSTRAINT "FK_d73339f6c26fd6ebd0326badcd7"`);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" DROP CONSTRAINT "FK_30358ab25e4c6c9ad72e74f201c"`);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" DROP CONSTRAINT "FK_90119ec7f77fa2efd82261e0448"`);
await queryRunner.query(`DROP INDEX "public"."IDX_42d9916277fcbefa0cdd3904c6"`);
await queryRunner.query(`DROP INDEX "public"."IDX_d73339f6c26fd6ebd0326badcd"`);
await queryRunner.query(`DROP INDEX "public"."IDX_30358ab25e4c6c9ad72e74f201"`);
await queryRunner.query(`ALTER TABLE "UserOnCallLogTimeline" ALTER COLUMN "triggeredByIncidentId" SET NOT NULL`);
await queryRunner.query(`ALTER TABLE "UserOnCallLogTimeline" ADD CONSTRAINT "FK_58a44736718a5ec4fe41526289a" FOREIGN KEY ("triggeredByIncidentId") REFERENCES "Incident"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "UserOnCallLog" ALTER COLUMN "triggeredByIncidentId" SET NOT NULL`);
await queryRunner.query(`ALTER TABLE "UserOnCallLog" ADD CONSTRAINT "FK_eeb0dd05d1dec542c3de5fb5074" FOREIGN KEY ("triggeredByIncidentId") REFERENCES "Incident"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ALTER COLUMN "triggeredByIncidentId" SET NOT NULL`);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ADD CONSTRAINT "FK_90119ec7f77fa2efd82261e0448" FOREIGN KEY ("triggeredByIncidentId") REFERENCES "Incident"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "UserOnCallLogTimeline" DROP COLUMN "triggeredByAlertId"`);
await queryRunner.query(`ALTER TABLE "UserOnCallLog" DROP COLUMN "triggeredByAlertId"`);
await queryRunner.query(`ALTER TABLE "UserNotificationRule" DROP COLUMN "alertSeverityId"`);
await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" DROP COLUMN "triggeredByAlertId"`);
}
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ADD "triggeredByAlertId" uuid`,
);
await queryRunner.query(
`ALTER TABLE "UserNotificationRule" ADD "alertSeverityId" uuid`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLog" ADD "triggeredByAlertId" uuid`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLogTimeline" ADD "triggeredByAlertId" uuid`,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" DROP CONSTRAINT "FK_90119ec7f77fa2efd82261e0448"`,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ALTER COLUMN "triggeredByIncidentId" DROP NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLog" DROP CONSTRAINT "FK_eeb0dd05d1dec542c3de5fb5074"`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLog" ALTER COLUMN "triggeredByIncidentId" DROP NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLogTimeline" DROP CONSTRAINT "FK_58a44736718a5ec4fe41526289a"`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLogTimeline" ALTER COLUMN "triggeredByIncidentId" DROP NOT NULL`,
);
await queryRunner.query(
`CREATE INDEX "IDX_30358ab25e4c6c9ad72e74f201" ON "OnCallDutyPolicyExecutionLogTimeline" ("triggeredByAlertId") `,
);
await queryRunner.query(
`CREATE INDEX "IDX_d73339f6c26fd6ebd0326badcd" ON "UserNotificationRule" ("alertSeverityId") `,
);
await queryRunner.query(
`CREATE INDEX "IDX_42d9916277fcbefa0cdd3904c6" ON "UserOnCallLogTimeline" ("triggeredByAlertId") `,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ADD CONSTRAINT "FK_90119ec7f77fa2efd82261e0448" FOREIGN KEY ("triggeredByIncidentId") REFERENCES "Incident"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ADD CONSTRAINT "FK_30358ab25e4c6c9ad72e74f201c" FOREIGN KEY ("triggeredByAlertId") REFERENCES "Alert"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "UserNotificationRule" ADD CONSTRAINT "FK_d73339f6c26fd6ebd0326badcd7" FOREIGN KEY ("alertSeverityId") REFERENCES "AlertSeverity"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLog" ADD CONSTRAINT "FK_eeb0dd05d1dec542c3de5fb5074" FOREIGN KEY ("triggeredByIncidentId") REFERENCES "Incident"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLog" ADD CONSTRAINT "FK_0ee3711cdc64957845d9d028c31" FOREIGN KEY ("triggeredByAlertId") REFERENCES "Alert"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLogTimeline" ADD CONSTRAINT "FK_58a44736718a5ec4fe41526289a" FOREIGN KEY ("triggeredByIncidentId") REFERENCES "Incident"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLogTimeline" ADD CONSTRAINT "FK_42d9916277fcbefa0cdd3904c63" FOREIGN KEY ("triggeredByAlertId") REFERENCES "Alert"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "UserOnCallLogTimeline" DROP CONSTRAINT "FK_42d9916277fcbefa0cdd3904c63"`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLogTimeline" DROP CONSTRAINT "FK_58a44736718a5ec4fe41526289a"`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLog" DROP CONSTRAINT "FK_0ee3711cdc64957845d9d028c31"`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLog" DROP CONSTRAINT "FK_eeb0dd05d1dec542c3de5fb5074"`,
);
await queryRunner.query(
`ALTER TABLE "UserNotificationRule" DROP CONSTRAINT "FK_d73339f6c26fd6ebd0326badcd7"`,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" DROP CONSTRAINT "FK_30358ab25e4c6c9ad72e74f201c"`,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" DROP CONSTRAINT "FK_90119ec7f77fa2efd82261e0448"`,
);
await queryRunner.query(
`DROP INDEX "public"."IDX_42d9916277fcbefa0cdd3904c6"`,
);
await queryRunner.query(
`DROP INDEX "public"."IDX_d73339f6c26fd6ebd0326badcd"`,
);
await queryRunner.query(
`DROP INDEX "public"."IDX_30358ab25e4c6c9ad72e74f201"`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLogTimeline" ALTER COLUMN "triggeredByIncidentId" SET NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLogTimeline" ADD CONSTRAINT "FK_58a44736718a5ec4fe41526289a" FOREIGN KEY ("triggeredByIncidentId") REFERENCES "Incident"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLog" ALTER COLUMN "triggeredByIncidentId" SET NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLog" ADD CONSTRAINT "FK_eeb0dd05d1dec542c3de5fb5074" FOREIGN KEY ("triggeredByIncidentId") REFERENCES "Incident"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ALTER COLUMN "triggeredByIncidentId" SET NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" ADD CONSTRAINT "FK_90119ec7f77fa2efd82261e0448" FOREIGN KEY ("triggeredByIncidentId") REFERENCES "Incident"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLogTimeline" DROP COLUMN "triggeredByAlertId"`,
);
await queryRunner.query(
`ALTER TABLE "UserOnCallLog" DROP COLUMN "triggeredByAlertId"`,
);
await queryRunner.query(
`ALTER TABLE "UserNotificationRule" DROP COLUMN "alertSeverityId"`,
);
await queryRunner.query(
`ALTER TABLE "OnCallDutyPolicyExecutionLogTimeline" DROP COLUMN "triggeredByAlertId"`,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,5 @@ export default [
MigrationName1736787985322,
MigrationName1736788706141,
MigrationName1736856662868,
MigrationName1737141420441
MigrationName1737141420441,
];
63 changes: 30 additions & 33 deletions Common/Server/Services/OnCallDutyPolicyExecutionLogService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,33 @@ export class Service extends DatabaseService<Model> {
},
});

if (onCallPolicy && onCallPolicy.id) {
const feedInfoInMarkdown: string = `**On Call Policy Started Executing:** On Call Policy **${onCallPolicy.name}** started executing. Users on call on this policy will now be notified.`;

if(onCallPolicy && onCallPolicy.id){
const feedInfoInMarkdown: string = `**On Call Policy Started Executing:** On Call Policy **${onCallPolicy.name}** started executing. Users on call on this policy will now be notified.`;

if (onCallPolicy && onCallPolicy.id && createdItem.triggeredByIncidentId) {
await IncidentFeedService.createIncidentFeed({
incidentId: createdItem.triggeredByIncidentId,
projectId: createdItem.projectId!,
incidentFeedEventType: IncidentFeedEventType.OnCallPolicy,
displayColor: Yellow500,
feedInfoInMarkdown:feedInfoInMarkdown,
});
}

if (onCallPolicy && onCallPolicy.id && createdItem.triggeredByAlertId) {
await AlertFeedService.createAlertFeed({
alertId: createdItem.triggeredByAlertId,
projectId: createdItem.projectId!,
alertFeedEventType: AlertFeedEventType.OnCallPolicy,
displayColor: Yellow500,
feedInfoInMarkdown: feedInfoInMarkdown,
});
}
if (
onCallPolicy &&
onCallPolicy.id &&
createdItem.triggeredByIncidentId
) {
await IncidentFeedService.createIncidentFeed({
incidentId: createdItem.triggeredByIncidentId,
projectId: createdItem.projectId!,
incidentFeedEventType: IncidentFeedEventType.OnCallPolicy,
displayColor: Yellow500,
feedInfoInMarkdown: feedInfoInMarkdown,
});
}


if (onCallPolicy && onCallPolicy.id && createdItem.triggeredByAlertId) {
await AlertFeedService.createAlertFeed({
alertId: createdItem.triggeredByAlertId,
projectId: createdItem.projectId!,
alertFeedEventType: AlertFeedEventType.OnCallPolicy,
displayColor: Yellow500,
feedInfoInMarkdown: feedInfoInMarkdown,
});
}
}
}

// get execution rules in this policy adn execute the first rule.
Expand Down Expand Up @@ -195,7 +196,8 @@ export class Service extends DatabaseService<Model> {

if (
onCalldutyPolicyExecutionLog &&
(onCalldutyPolicyExecutionLog.triggeredByIncidentId || onCalldutyPolicyExecutionLog.triggeredByAlertId)
(onCalldutyPolicyExecutionLog.triggeredByIncidentId ||
onCalldutyPolicyExecutionLog.triggeredByAlertId)
) {
const onCallPolicy: OnCallDutyPolicy | null =
await OnCallDutyPolicyService.findOneById({
Expand All @@ -209,10 +211,8 @@ export class Service extends DatabaseService<Model> {
isRoot: true,
},
});


if (onCallPolicy && onCallPolicy.id) {

const moreInformationInMarkdown: string = `**Status:** ${onCalldutyPolicyExecutionLog.status}
**Message:** ${onCalldutyPolicyExecutionLog.statusMessage}`;
Expand All @@ -221,16 +221,15 @@ export class Service extends DatabaseService<Model> {
On-call policy **${onCallPolicy.name}** status updated to **${onCalldutyPolicyExecutionLog.status}**`;


if (onCalldutyPolicyExecutionLog.triggeredByIncidentId) {
await IncidentFeedService.createIncidentFeed({
incidentId: onCalldutyPolicyExecutionLog.triggeredByIncidentId,
projectId: onCalldutyPolicyExecutionLog.projectId!,
incidentFeedEventType: IncidentFeedEventType.OnCallPolicy,
displayColor: onCalldutyPolicyExecutionLog.status
? this.getDisplayColorByStatus(
onCalldutyPolicyExecutionLog.status,
)
onCalldutyPolicyExecutionLog.status,
)
: Blue500,
moreInformationInMarkdown: moreInformationInMarkdown,
feedInfoInMarkdown: feedInfoInMarkdown,
Expand All @@ -244,15 +243,13 @@ On-call policy **${onCallPolicy.name}** status updated to **${onCalldutyPolicyEx
alertFeedEventType: AlertFeedEventType.OnCallPolicy,
displayColor: onCalldutyPolicyExecutionLog.status
? this.getDisplayColorByStatus(
onCalldutyPolicyExecutionLog.status,
)
onCalldutyPolicyExecutionLog.status,
)
: Blue500,
moreInformationInMarkdown: moreInformationInMarkdown,
feedInfoInMarkdown: feedInfoInMarkdown,

});
}

}
}
}
Expand Down
Loading

0 comments on commit 8b30413

Please sign in to comment.