Skip to content

Commit

Permalink
refactor: clean up code formatting and remove unnecessary whitespace …
Browse files Browse the repository at this point in the history
…in various files
  • Loading branch information
simlarsen committed Jan 14, 2025
1 parent 1ff4bde commit 4d1797e
Show file tree
Hide file tree
Showing 23 changed files with 669 additions and 560 deletions.
1 change: 0 additions & 1 deletion Common/Models/DatabaseModels/AlertFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ export default class AlertFeed extends BaseModel {
})
public userId?: ObjectID = undefined;


@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Expand Down
4 changes: 0 additions & 4 deletions Common/Models/DatabaseModels/IncidentFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,6 @@ export default class IncidentFeed extends BaseModel {
})
public userId?: ObjectID = undefined;



@ColumnAccessControl({
create: [
Permission.ProjectOwner,
Expand All @@ -525,6 +523,4 @@ export default class IncidentFeed extends BaseModel {
unique: false,
})
public postedAt?: Date = undefined;


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

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "IncidentFeed" ADD "postedAt" TIMESTAMP WITH TIME ZONE`);
await queryRunner.query(`ALTER TABLE "AlertFeed" ADD "postedAt" TIMESTAMP WITH TIME ZONE`);
await queryRunner.query(`ALTER TABLE "ScheduledMaintenanceFeed" ADD "postedAt" TIMESTAMP WITH TIME ZONE`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "ScheduledMaintenanceFeed" DROP COLUMN "postedAt"`);
await queryRunner.query(`ALTER TABLE "AlertFeed" DROP COLUMN "postedAt"`);
await queryRunner.query(`ALTER TABLE "IncidentFeed" DROP COLUMN "postedAt"`);
}
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "IncidentFeed" ADD "postedAt" TIMESTAMP WITH TIME ZONE`,
);
await queryRunner.query(
`ALTER TABLE "AlertFeed" ADD "postedAt" TIMESTAMP WITH TIME ZONE`,
);
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenanceFeed" ADD "postedAt" TIMESTAMP WITH TIME ZONE`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "ScheduledMaintenanceFeed" DROP COLUMN "postedAt"`,
);
await queryRunner.query(`ALTER TABLE "AlertFeed" DROP COLUMN "postedAt"`);
await queryRunner.query(
`ALTER TABLE "IncidentFeed" DROP COLUMN "postedAt"`,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,5 @@ export default [
MigrationName1736787495707,
MigrationName1736787985322,
MigrationName1736788706141,
MigrationName1736856662868
MigrationName1736856662868,
];
5 changes: 2 additions & 3 deletions Common/Server/Services/AlertFeedService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ export class Service extends DatabaseService<Model> {
alertFeed.alertFeedEventType = data.alertFeedEventType;
alertFeed.projectId = data.projectId;

if(!data.postedAt){
if (!data.postedAt) {
alertFeed.postedAt = OneUptimeDate.getCurrentDate();
}

}

if (data.moreInformationInMarkdown) {
alertFeed.moreInformationInMarkdown = data.moreInformationInMarkdown;
Expand Down
2 changes: 1 addition & 1 deletion Common/Server/Services/IncidentFeedService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class Service extends DatabaseService<Model> {
incidentFeed.incidentFeedEventType = data.incidentFeedEventType;
incidentFeed.projectId = data.projectId;

if(!data.postedAt){
if (!data.postedAt) {
incidentFeed.postedAt = OneUptimeDate.getCurrentDate();
}

Expand Down
1 change: 0 additions & 1 deletion Common/Server/Services/IncidentInternalNoteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class Service extends DatabaseService<Model> {
): Promise<Model> {
const userId: ObjectID | null | undefined =
createdItem.createdByUserId || createdItem.createdByUser?.id;


await IncidentFeedService.createIncidentFeed({
incidentId: createdItem.incidentId!,
Expand Down
66 changes: 30 additions & 36 deletions Common/Server/Services/IncidentOwnerTeamService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,57 +14,57 @@ export class Service extends DatabaseService<Model> {
super(Model);
}


protected override async onBeforeDelete(deleteBy: DeleteBy<Model>): Promise<OnDelete<Model>> {
protected override async onBeforeDelete(
deleteBy: DeleteBy<Model>,
): Promise<OnDelete<Model>> {
const itemsToDelete: Model[] = await this.findBy({
query: deleteBy.query,
limit: deleteBy.limit,
skip: deleteBy.skip,
props: {
isRoot: true
isRoot: true,
},
select: {
incidentId: true,
projectId: true,
teamId: true,
}
})
},
});

return {
carryForward: {
itemsToDelete: itemsToDelete
itemsToDelete: itemsToDelete,
},
deleteBy: deleteBy
}
deleteBy: deleteBy,
};
}

protected override async onDeleteSuccess(onDelete: OnDelete<Model>, _itemIdsBeforeDelete: Array<ObjectID>): Promise<OnDelete<Model>> {

const deleteByUserId: ObjectID | undefined = onDelete.deleteBy.deletedByUser?.id || onDelete.deleteBy.props.userId;
protected override async onDeleteSuccess(
onDelete: OnDelete<Model>,
_itemIdsBeforeDelete: Array<ObjectID>,
): Promise<OnDelete<Model>> {
const deleteByUserId: ObjectID | undefined =
onDelete.deleteBy.deletedByUser?.id || onDelete.deleteBy.props.userId;

const itemsToDelete: Model[] = onDelete.carryForward.itemsToDelete;

for (const item of itemsToDelete) {

const incidentId: ObjectID | undefined = item.incidentId;
const projectId: ObjectID | undefined = item.projectId;
const teamId: ObjectID | undefined = item.teamId;


if (incidentId && teamId && projectId) {

const team: Team | null = await TeamService.findOneById({
id: teamId,
select: {
name: true
name: true,
},
props: {
isRoot: true
}
})
isRoot: true,
},
});

if (team && team.name) {

await IncidentFeedService.createIncidentFeed({
incidentId: incidentId,
projectId: projectId,
Expand All @@ -78,50 +78,44 @@ export class Service extends DatabaseService<Model> {
}

return onDelete;

}

public override async onCreateSuccess(onCreate: OnCreate<Model>, createdItem: Model): Promise<Model> {
// add incident feed.
public override async onCreateSuccess(
onCreate: OnCreate<Model>,
createdItem: Model,
): Promise<Model> {
// add incident feed.

const incidentId: ObjectID | undefined = createdItem.incidentId;
const projectId: ObjectID | undefined = createdItem.projectId;
const teamId: ObjectID | undefined = createdItem.teamId;
const createdByUserId: ObjectID | undefined = createdItem.createdByUserId || onCreate.createBy.props.userId;

const createdByUserId: ObjectID | undefined =
createdItem.createdByUserId || onCreate.createBy.props.userId;

if (incidentId && teamId && projectId) {


const team: Team | null = await TeamService.findOneById({
id: teamId,
select: {
name: true
name: true,
},
props: {
isRoot: true
}
})
isRoot: true,
},
});

if (team && team.name) {


await IncidentFeedService.createIncidentFeed({

incidentId: incidentId,
projectId: projectId,
incidentFeedEventType: IncidentFeedEventType.OwnerTeamAdded,
displayColor: Gray500,
feedInfoInMarkdown: `**Team ${team.name}** was added to the incident as the owner.`,
userId: createdByUserId || undefined,
});

}

}

return createdItem;

}
}

Expand Down
64 changes: 30 additions & 34 deletions Common/Server/Services/IncidentOwnerUserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,57 +14,58 @@ export class Service extends DatabaseService<Model> {
super(Model);
}

protected override async onBeforeDelete(deleteBy: DeleteBy<Model>): Promise<OnDelete<Model>> {
protected override async onBeforeDelete(
deleteBy: DeleteBy<Model>,
): Promise<OnDelete<Model>> {
const itemsToDelete: Model[] = await this.findBy({
query: deleteBy.query,
limit: deleteBy.limit,
skip: deleteBy.skip,
props: {
isRoot: true
isRoot: true,
},
select: {
incidentId: true,
projectId: true,
userId: true,
}
})
},
});

return {
carryForward: {
itemsToDelete: itemsToDelete
itemsToDelete: itemsToDelete,
},
deleteBy: deleteBy
}
deleteBy: deleteBy,
};
}

protected override async onDeleteSuccess(onDelete: OnDelete<Model>, _itemIdsBeforeDelete: Array<ObjectID>): Promise<OnDelete<Model>> {

const deleteByUserId: ObjectID | undefined = onDelete.deleteBy.deletedByUser?.id || onDelete.deleteBy.props.userId;
protected override async onDeleteSuccess(
onDelete: OnDelete<Model>,
_itemIdsBeforeDelete: Array<ObjectID>,
): Promise<OnDelete<Model>> {
const deleteByUserId: ObjectID | undefined =
onDelete.deleteBy.deletedByUser?.id || onDelete.deleteBy.props.userId;

const itemsToDelete: Model[] = onDelete.carryForward.itemsToDelete;

for (const item of itemsToDelete) {

const incidentId: ObjectID | undefined = item.incidentId;
const projectId: ObjectID | undefined = item.projectId;
const userId: ObjectID | undefined = item.userId;


if (incidentId && userId && projectId) {

const user: User | null = await UserService.findOneById({
id: userId,
select: {
name: true,
email: true
email: true,
},
props: {
isRoot: true
}
})
isRoot: true,
},
});

if (user && user.name) {

await IncidentFeedService.createIncidentFeed({
incidentId: incidentId,
projectId: projectId,
Expand All @@ -78,35 +79,33 @@ export class Service extends DatabaseService<Model> {
}

return onDelete;

}


public override async onCreateSuccess(onCreate: OnCreate<Model>, createdItem: Model): Promise<Model> {
// add incident feed.
public override async onCreateSuccess(
onCreate: OnCreate<Model>,
createdItem: Model,
): Promise<Model> {
// add incident feed.

const incidentId: ObjectID | undefined = createdItem.incidentId;
const projectId: ObjectID | undefined = createdItem.projectId;
const userId: ObjectID | undefined = createdItem.userId;
const createdByUserId: ObjectID | undefined = createdItem.createdByUserId || onCreate.createBy.props.userId;

const createdByUserId: ObjectID | undefined =
createdItem.createdByUserId || onCreate.createBy.props.userId;

if (incidentId && userId && projectId) {


const user: User | null = await UserService.findOneById({
id: userId,
select: {
name: true,
email: true
email: true,
},
props: {
isRoot: true
}
})
isRoot: true,
},
});

if (user && user.name) {

await IncidentFeedService.createIncidentFeed({
incidentId: incidentId,
projectId: projectId,
Expand All @@ -115,13 +114,10 @@ export class Service extends DatabaseService<Model> {
feedInfoInMarkdown: `**${user.name.toString()}** (${user.email?.toString()}) was added to the incident as the owner.`,
userId: createdByUserId || undefined,
});

}

}

return createdItem;

}
}

Expand Down
Loading

0 comments on commit 4d1797e

Please sign in to comment.