diff --git a/Common/Server/Infrastructure/Postgres/SchemaMigrations/1747305098533-MigrationName.ts b/Common/Server/Infrastructure/Postgres/SchemaMigrations/1747305098533-MigrationName.ts index 81e4332912..635607aaac 100644 --- a/Common/Server/Infrastructure/Postgres/SchemaMigrations/1747305098533-MigrationName.ts +++ b/Common/Server/Infrastructure/Postgres/SchemaMigrations/1747305098533-MigrationName.ts @@ -1,32 +1,69 @@ import { MigrationInterface, QueryRunner } from "typeorm"; export class MigrationName1747305098533 implements MigrationInterface { - public name = 'MigrationName1747305098533' + public name = "MigrationName1747305098533"; - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE TABLE "OnCallDutyPolicyTimeLog" ("_id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP WITH TIME ZONE, "version" integer NOT NULL, "projectId" uuid NOT NULL, "onCallDutyPolicyId" uuid, "onCallDutyPolicyScheduleId" uuid, "onCallDutyPolicyEscalationRuleId" uuid, "teamId" uuid, "moreInfo" text, "createdByUserId" uuid, "userId" uuid NOT NULL, "startsAt" TIMESTAMP WITH TIME ZONE NOT NULL, "endsAt" TIMESTAMP WITH TIME ZONE, "deletedByUserId" uuid, CONSTRAINT "PK_11ce033bf855cf2dd0b86daa681" PRIMARY KEY ("_id"))`); - await queryRunner.query(`CREATE INDEX "IDX_7eed77389b6085ae0065ab3705" ON "OnCallDutyPolicyTimeLog" ("projectId") `); - await queryRunner.query(`CREATE INDEX "IDX_523a7b776b41de5bb5405d6431" ON "OnCallDutyPolicyTimeLog" ("onCallDutyPolicyId") `); - await queryRunner.query(`CREATE INDEX "IDX_86e4f4be85b87ff796fe84b90a" ON "OnCallDutyPolicyTimeLog" ("onCallDutyPolicyScheduleId") `); - await queryRunner.query(`CREATE INDEX "IDX_0843b3b966754970c779f61b0a" ON "OnCallDutyPolicyTimeLog" ("onCallDutyPolicyEscalationRuleId") `); - await queryRunner.query(`CREATE INDEX "IDX_47ff7c8bdaf4e733077b3ceca7" ON "OnCallDutyPolicyTimeLog" ("teamId") `); - await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyTimeLog" ADD CONSTRAINT "FK_7eed77389b6085ae0065ab37059" FOREIGN KEY ("projectId") REFERENCES "Project"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyTimeLog" ADD CONSTRAINT "FK_99c1e72b99f1fbedeb650357026" FOREIGN KEY ("createdByUserId") REFERENCES "User"("_id") ON DELETE SET NULL ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyTimeLog" ADD CONSTRAINT "FK_43da7ffeee531e9452d36a89ba5" FOREIGN KEY ("userId") REFERENCES "User"("_id") ON DELETE SET NULL ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyTimeLog" ADD CONSTRAINT "FK_b6476633034478def5e6f435cc7" FOREIGN KEY ("deletedByUserId") REFERENCES "User"("_id") ON DELETE SET NULL ON UPDATE NO ACTION`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyTimeLog" DROP CONSTRAINT "FK_b6476633034478def5e6f435cc7"`); - await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyTimeLog" DROP CONSTRAINT "FK_43da7ffeee531e9452d36a89ba5"`); - await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyTimeLog" DROP CONSTRAINT "FK_99c1e72b99f1fbedeb650357026"`); - await queryRunner.query(`ALTER TABLE "OnCallDutyPolicyTimeLog" DROP CONSTRAINT "FK_7eed77389b6085ae0065ab37059"`); - await queryRunner.query(`DROP INDEX "public"."IDX_47ff7c8bdaf4e733077b3ceca7"`); - await queryRunner.query(`DROP INDEX "public"."IDX_0843b3b966754970c779f61b0a"`); - await queryRunner.query(`DROP INDEX "public"."IDX_86e4f4be85b87ff796fe84b90a"`); - await queryRunner.query(`DROP INDEX "public"."IDX_523a7b776b41de5bb5405d6431"`); - await queryRunner.query(`DROP INDEX "public"."IDX_7eed77389b6085ae0065ab3705"`); - await queryRunner.query(`DROP TABLE "OnCallDutyPolicyTimeLog"`); - } + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE TABLE "OnCallDutyPolicyTimeLog" ("_id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP WITH TIME ZONE, "version" integer NOT NULL, "projectId" uuid NOT NULL, "onCallDutyPolicyId" uuid, "onCallDutyPolicyScheduleId" uuid, "onCallDutyPolicyEscalationRuleId" uuid, "teamId" uuid, "moreInfo" text, "createdByUserId" uuid, "userId" uuid NOT NULL, "startsAt" TIMESTAMP WITH TIME ZONE NOT NULL, "endsAt" TIMESTAMP WITH TIME ZONE, "deletedByUserId" uuid, CONSTRAINT "PK_11ce033bf855cf2dd0b86daa681" PRIMARY KEY ("_id"))`, + ); + await queryRunner.query( + `CREATE INDEX "IDX_7eed77389b6085ae0065ab3705" ON "OnCallDutyPolicyTimeLog" ("projectId") `, + ); + await queryRunner.query( + `CREATE INDEX "IDX_523a7b776b41de5bb5405d6431" ON "OnCallDutyPolicyTimeLog" ("onCallDutyPolicyId") `, + ); + await queryRunner.query( + `CREATE INDEX "IDX_86e4f4be85b87ff796fe84b90a" ON "OnCallDutyPolicyTimeLog" ("onCallDutyPolicyScheduleId") `, + ); + await queryRunner.query( + `CREATE INDEX "IDX_0843b3b966754970c779f61b0a" ON "OnCallDutyPolicyTimeLog" ("onCallDutyPolicyEscalationRuleId") `, + ); + await queryRunner.query( + `CREATE INDEX "IDX_47ff7c8bdaf4e733077b3ceca7" ON "OnCallDutyPolicyTimeLog" ("teamId") `, + ); + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyTimeLog" ADD CONSTRAINT "FK_7eed77389b6085ae0065ab37059" FOREIGN KEY ("projectId") REFERENCES "Project"("_id") ON DELETE CASCADE ON UPDATE NO ACTION`, + ); + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyTimeLog" ADD CONSTRAINT "FK_99c1e72b99f1fbedeb650357026" FOREIGN KEY ("createdByUserId") REFERENCES "User"("_id") ON DELETE SET NULL ON UPDATE NO ACTION`, + ); + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyTimeLog" ADD CONSTRAINT "FK_43da7ffeee531e9452d36a89ba5" FOREIGN KEY ("userId") REFERENCES "User"("_id") ON DELETE SET NULL ON UPDATE NO ACTION`, + ); + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyTimeLog" ADD CONSTRAINT "FK_b6476633034478def5e6f435cc7" FOREIGN KEY ("deletedByUserId") REFERENCES "User"("_id") ON DELETE SET NULL ON UPDATE NO ACTION`, + ); + } + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyTimeLog" DROP CONSTRAINT "FK_b6476633034478def5e6f435cc7"`, + ); + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyTimeLog" DROP CONSTRAINT "FK_43da7ffeee531e9452d36a89ba5"`, + ); + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyTimeLog" DROP CONSTRAINT "FK_99c1e72b99f1fbedeb650357026"`, + ); + await queryRunner.query( + `ALTER TABLE "OnCallDutyPolicyTimeLog" DROP CONSTRAINT "FK_7eed77389b6085ae0065ab37059"`, + ); + await queryRunner.query( + `DROP INDEX "public"."IDX_47ff7c8bdaf4e733077b3ceca7"`, + ); + await queryRunner.query( + `DROP INDEX "public"."IDX_0843b3b966754970c779f61b0a"`, + ); + await queryRunner.query( + `DROP INDEX "public"."IDX_86e4f4be85b87ff796fe84b90a"`, + ); + await queryRunner.query( + `DROP INDEX "public"."IDX_523a7b776b41de5bb5405d6431"`, + ); + await queryRunner.query( + `DROP INDEX "public"."IDX_7eed77389b6085ae0065ab3705"`, + ); + await queryRunner.query(`DROP TABLE "OnCallDutyPolicyTimeLog"`); + } } diff --git a/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts b/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts index 56e4ec67b2..b8ce839882 100644 --- a/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +++ b/Common/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts @@ -267,5 +267,5 @@ export default [ MigrationName1743714801105, MigrationName1744804990712, MigrationName1744809770336, - MigrationName1747305098533 + MigrationName1747305098533, ]; diff --git a/Common/Server/Services/OnCallDutyPolicyEscalationRuleScheduleService.ts b/Common/Server/Services/OnCallDutyPolicyEscalationRuleScheduleService.ts index 3b17558aeb..f77e0b201d 100644 --- a/Common/Server/Services/OnCallDutyPolicyEscalationRuleScheduleService.ts +++ b/Common/Server/Services/OnCallDutyPolicyEscalationRuleScheduleService.ts @@ -138,8 +138,6 @@ export class Service extends DatabaseService { NotificationSettingEventType.SEND_WHEN_USER_IS_ADDED_TO_ON_CALL_POLICY, }); - - // add workspace message. const onCallDutyPolicyId: ObjectID | undefined | null = @@ -168,9 +166,6 @@ export class Service extends DatabaseService { notifyUserId: createdByUserId || undefined, }, }); - - - } return createdItem; diff --git a/Common/Server/Services/OnCallDutyPolicyEscalationRuleTeamService.ts b/Common/Server/Services/OnCallDutyPolicyEscalationRuleTeamService.ts index 55784698dc..cccb7a0015 100644 --- a/Common/Server/Services/OnCallDutyPolicyEscalationRuleTeamService.ts +++ b/Common/Server/Services/OnCallDutyPolicyEscalationRuleTeamService.ts @@ -137,7 +137,7 @@ export class Service extends DatabaseService { NotificationSettingEventType.SEND_WHEN_USER_IS_ADDED_TO_ON_CALL_POLICY, }); - // add start log + // add start log OnCallDutyPolicyTimeLogService.startTimeLogForUser({ userId: sendEmailToUserId, onCallDutyPolicyId: createdModel.onCallDutyPolicy!.id!, @@ -240,8 +240,6 @@ export class Service extends DatabaseService { notifyUserId: deleteByUserId || undefined, }, }); - - } } @@ -320,17 +318,16 @@ export class Service extends DatabaseService { NotificationSettingEventType.SEND_WHEN_USER_IS_REMOVED_FROM_ON_CALL_POLICY, }); - // end time log await OnCallDutyPolicyTimeLogService.endTimeLogForUser({ userId: sendEmailToUserId, onCallDutyPolicyId: deletedItem.onCallDutyPolicy!.id!, onCallDutyPolicyEscalationRuleId: - deletedItem.onCallDutyPolicyEscalationRule!.id!, + deletedItem.onCallDutyPolicyEscalationRule!.id!, projectId: deletedItem.projectId!, teamId: deletedItem.teamId!, - endsAt: OneUptimeDate.getCurrentDate() + endsAt: OneUptimeDate.getCurrentDate(), }); } } diff --git a/Common/Server/Services/OnCallDutyPolicyEscalationRuleUserService.ts b/Common/Server/Services/OnCallDutyPolicyEscalationRuleUserService.ts index 6cfbeaeb63..3a74f9a93c 100644 --- a/Common/Server/Services/OnCallDutyPolicyEscalationRuleUserService.ts +++ b/Common/Server/Services/OnCallDutyPolicyEscalationRuleUserService.ts @@ -20,6 +20,7 @@ import UserService from "./UserService"; import User from "../../Models/DatabaseModels/User"; import OnCallDutyPolicyTimeLogService from "./OnCallDutyPolicyTimeLogService"; import OneUptimeDate from "../../Types/Date"; +import logger from "../Utils/Logger"; export class Service extends DatabaseService { public constructor() { @@ -28,7 +29,7 @@ export class Service extends DatabaseService { protected override async onCreateSuccess( _onCreate: OnCreate, - createdItem: Model + createdItem: Model, ): Promise { const createdItemId: ObjectID = createdItem.id!; @@ -85,7 +86,7 @@ export class Service extends DatabaseService { onCallPolicyViewLink: ( await OnCallDutyPolicyService.getOnCallDutyPolicyLinkInDashboard( createdModel!.projectId!, - createdModel.onCallDutyPolicy!.id! + createdModel.onCallDutyPolicy!.id!, ) ).toString(), }; @@ -119,8 +120,6 @@ export class Service extends DatabaseService { NotificationSettingEventType.SEND_WHEN_USER_IS_ADDED_TO_ON_CALL_POLICY, }); - - // add workspace message. const onCallDutyPolicyId: ObjectID | undefined | null = @@ -137,7 +136,7 @@ export class Service extends DatabaseService { { userId: createdModel.user!.id!, projectId: projectId!, - } + }, )}** to the [On-Call Policy ${createdModel.onCallDutyPolicy?.name}](${(await OnCallDutyPolicyService.getOnCallDutyPolicyLinkInDashboard(projectId!, onCallDutyPolicyId!)).toString()}) escalation rule **${createdModel.onCallDutyPolicyEscalationRule?.name}** with order **${createdModel.onCallDutyPolicyEscalationRule?.order}**.`, userId: createdModel.createdByUserId! || undefined, workspaceNotification: { @@ -150,23 +149,22 @@ export class Service extends DatabaseService { OnCallDutyPolicyTimeLogService.startTimeLogForUser({ projectId: projectId!, onCallDutyPolicyId: onCallDutyPolicyId!, - onCallDutyPolicyEscalationRuleId: createdModel.onCallDutyPolicyEscalationRule!.id!, + onCallDutyPolicyEscalationRuleId: + createdModel.onCallDutyPolicyEscalationRule!.id!, userId: createdModel.user!.id!, startsAt: OneUptimeDate.getCurrentDate(), - }).catch((error) => { - console.error( - `Error starting time log for user ${createdModel.user?.id}: ${error}` + }).catch((error: Error) => { + logger.error( + `Error starting time log for user ${createdModel.user?.id}: ${error}`, ); }); - - } return createdItem; } protected override async onBeforeDelete( - deleteBy: DeleteBy + deleteBy: DeleteBy, ): Promise> { const itemsToFetchBeforeDelete: Array = await this.findBy({ query: deleteBy.query, @@ -241,12 +239,9 @@ export class Service extends DatabaseService { item.onCallDutyPolicyEscalationRule!.id!, userId: userId, endsAt: OneUptimeDate.getCurrentDate(), - }).catch((error) => { - console.error( - `Error ending time log for user ${userId}: ${error}` - ); - } - ); + }).catch((error: Error) => { + logger.error(`Error ending time log for user ${userId}: ${error}`); + }); } } } @@ -261,7 +256,7 @@ export class Service extends DatabaseService { protected override async onDeleteSuccess( onDelete: OnDelete, - _itemIdsBeforeDelete: Array + _itemIdsBeforeDelete: Array, ): Promise> { const deletedItems: Array = onDelete.carryForward.deletedItems; @@ -287,7 +282,7 @@ export class Service extends DatabaseService { onCallPolicyViewLink: ( await OnCallDutyPolicyService.getOnCallDutyPolicyLinkInDashboard( deletedItem!.projectId!, - deletedItem.onCallDutyPolicy!.id! + deletedItem.onCallDutyPolicy!.id!, ) ).toString(), }; diff --git a/Common/Server/Services/OnCallDutyPolicyScheduleService.ts b/Common/Server/Services/OnCallDutyPolicyScheduleService.ts index 85db80df5d..3baf3064e7 100644 --- a/Common/Server/Services/OnCallDutyPolicyScheduleService.ts +++ b/Common/Server/Services/OnCallDutyPolicyScheduleService.ts @@ -186,7 +186,7 @@ export class Service extends DatabaseService { rosterEndsAt: OneUptimeDate.getDateAsFormattedHTMLInMultipleTimezones({ date: OneUptimeDate.isInTheFuture( - previousInformation.rosterHandoffAt! + previousInformation.rosterHandoffAt!, ) ? OneUptimeDate.getCurrentDate() : previousInformation.rosterHandoffAt!, @@ -195,7 +195,7 @@ export class Service extends DatabaseService { onCallPolicyViewLink: ( await OnCallDutyPolicyService.getOnCallDutyPolicyLinkInDashboard( projectId, - onCallPolicy.id! + onCallPolicy.id!, ) ).toString(), }; @@ -234,11 +234,11 @@ export class Service extends DatabaseService { userId: sendEmailToUserId, onCallDutyPolicyScheduleId: data.scheduleId, onCallDutyPolicyEscalationRuleId: - escalationRule.onCallDutyPolicyEscalationRule?.id!, - onCallDutyPolicyId: escalationRule.onCallDutyPolicy?.id!, + escalationRule.onCallDutyPolicyEscalationRule!.id!, + onCallDutyPolicyId: escalationRule.onCallDutyPolicy!.id!, projectId: projectId, endsAt: OneUptimeDate.getCurrentDate(), - }).catch((err) => { + }).catch((err: Error) => { logger.error( "Error ending time log for user: " + sendEmailToUserId.toString() + @@ -262,7 +262,7 @@ export class Service extends DatabaseService { { userId: sendEmailToUserId, projectId: projectId!, - } + }, )}** is no longer on call for [On-Call Policy ${escalationRule.onCallDutyPolicy?.name}](${(await OnCallDutyPolicyService.getOnCallDutyPolicyLinkInDashboard(projectId!, onCallDutyPolicyId!)).toString()}) escalation rule **${escalationRule.onCallDutyPolicyEscalationRule?.name}** with order **${escalationRule.onCallDutyPolicyEscalationRule?.order}** because your on-call roster on schedule **${onCallSchedule.name}** just ended.`, userId: sendEmailToUserId || undefined, workspaceNotification: { @@ -303,7 +303,7 @@ export class Service extends DatabaseService { onCallPolicyViewLink: ( await OnCallDutyPolicyService.getOnCallDutyPolicyLinkInDashboard( projectId, - onCallPolicy.id! + onCallPolicy.id!, ) ).toString(), }; @@ -341,11 +341,11 @@ export class Service extends DatabaseService { userId: sendEmailToUserId, onCallDutyPolicyScheduleId: data.scheduleId, onCallDutyPolicyEscalationRuleId: - escalationRule.onCallDutyPolicyEscalationRule?.id!, - onCallDutyPolicyId: escalationRule.onCallDutyPolicy?.id!, + escalationRule.onCallDutyPolicyEscalationRule!.id!, + onCallDutyPolicyId: escalationRule.onCallDutyPolicy!.id!, projectId: projectId, startsAt: OneUptimeDate.getCurrentDate(), - }).catch((err) => { + }).catch((err: Error) => { logger.error( "Error starting time log for user: " + sendEmailToUserId.toString() + @@ -369,17 +369,17 @@ export class Service extends DatabaseService { { userId: sendEmailToUserId, projectId: projectId!, - } + }, )}** is currently on call for [On-Call Policy ${escalationRule.onCallDutyPolicy?.name}](${(await OnCallDutyPolicyService.getOnCallDutyPolicyLinkInDashboard(projectId!, onCallDutyPolicyId!)).toString()}) escalation rule **${escalationRule.onCallDutyPolicyEscalationRule?.name}** with order **${escalationRule.onCallDutyPolicyEscalationRule?.order}** because of schedule **${onCallSchedule.name}** and your on-call roster starts at **${OneUptimeDate.getDateAsFormattedStringInMultipleTimezones( { date: newInformation.rosterStartAt!, timezones: userTimezone ? [userTimezone] : [Timezone.GMT], - } + }, )}** and ends at **${OneUptimeDate.getDateAsFormattedStringInMultipleTimezones( { date: newInformation.rosterHandoffAt!, timezones: userTimezone ? [userTimezone] : [Timezone.GMT], - } + }, )}**.`, userId: sendEmailToUserId || undefined, workspaceNotification: { @@ -430,7 +430,7 @@ export class Service extends DatabaseService { onCallPolicyViewLink: ( await OnCallDutyPolicyService.getOnCallDutyPolicyLinkInDashboard( projectId, - onCallPolicy.id! + onCallPolicy.id!, ) ).toString(), }; @@ -477,17 +477,17 @@ export class Service extends DatabaseService { { userId: sendEmailToUserId, projectId: projectId!, - } + }, )}** is next on call for [On-Call Policy ${escalationRule.onCallDutyPolicy?.name}](${(await OnCallDutyPolicyService.getOnCallDutyPolicyLinkInDashboard(projectId!, onCallDutyPolicyId!)).toString()}) escalation rule **${escalationRule.onCallDutyPolicyEscalationRule?.name}** with order **${escalationRule.onCallDutyPolicyEscalationRule?.order}**. The on-call roster on schedule **${onCallSchedule.name}** will start when the next handoff happens which is at **${OneUptimeDate.getDateAsFormattedStringInMultipleTimezones( { date: newInformation.nextRosterStartAt!, timezones: userTimezone ? [userTimezone] : [Timezone.GMT], - } + }, )}** and will end at **${OneUptimeDate.getDateAsFormattedStringInMultipleTimezones( { date: newInformation.nextHandOffTimeAt!, timezones: userTimezone ? [userTimezone] : [Timezone.GMT], - } + }, )}**.`, userId: sendEmailToUserId || undefined, workspaceNotification: { @@ -501,7 +501,7 @@ export class Service extends DatabaseService { } public async refreshCurrentUserIdAndHandoffTimeInSchedule( - scheduleId: ObjectID + scheduleId: ObjectID, ): Promise<{ currentUserId: ObjectID | null; handOffTimeAt: Date | null; @@ -512,13 +512,13 @@ export class Service extends DatabaseService { }> { logger.debug( "refreshCurrentUserIdAndHandoffTimeInSchedule called with scheduleId: " + - scheduleId.toString() + scheduleId.toString(), ); // get previoius result. logger.debug( "Fetching previous schedule information for scheduleId: " + - scheduleId.toString() + scheduleId.toString(), ); const onCallSchedule: OnCallDutyPolicySchedule | null = await this.findOneById({ @@ -538,14 +538,14 @@ export class Service extends DatabaseService { if (!onCallSchedule) { logger.debug( - "Schedule not found for scheduleId: " + scheduleId.toString() + "Schedule not found for scheduleId: " + scheduleId.toString(), ); throw new BadDataException("Schedule not found"); } logger.debug( "Previous schedule information fetched for scheduleId: " + - scheduleId.toString() + scheduleId.toString(), ); const previousInformation: { @@ -568,7 +568,7 @@ export class Service extends DatabaseService { logger.debug( "Fetching new schedule information for scheduleId: " + - scheduleId.toString() + scheduleId.toString(), ); const newInformation: { @@ -584,7 +584,7 @@ export class Service extends DatabaseService { logger.debug( "Updating schedule with new information for scheduleId: " + - scheduleId.toString() + scheduleId.toString(), ); await this.updateOneById({ @@ -605,7 +605,7 @@ export class Service extends DatabaseService { logger.debug( "Sending notifications for schedule handoff for scheduleId: " + - scheduleId.toString() + scheduleId.toString(), ); // send notification to the users. @@ -624,14 +624,14 @@ export class Service extends DatabaseService { logger.debug( "Returning new schedule information for scheduleId: " + - scheduleId.toString() + scheduleId.toString(), ); return newInformation; } public async getCurrrentUserIdAndHandoffTimeInSchedule( - scheduleId: ObjectID + scheduleId: ObjectID, ): Promise<{ rosterStartAt: Date | null; currentUserId: ObjectID | null; @@ -642,7 +642,7 @@ export class Service extends DatabaseService { }> { logger.debug( "getCurrrentUserIdAndHandoffTimeInSchedule called with scheduleId: " + - scheduleId.toString() + scheduleId.toString(), ); const resultReturn: { @@ -679,7 +679,7 @@ export class Service extends DatabaseService { // if the current event start time in the future then the current event is the next event. if (currentEvent && OneUptimeDate.isInTheFuture(currentEvent.start)) { logger.debug( - "Current event is in the future, treating it as next event." + "Current event is in the future, treating it as next event.", ); nextEvent = currentEvent; currentEvent = null; @@ -825,7 +825,7 @@ export class Service extends DatabaseService { getNumberOfEvents: number; // which event would you like to get. First event, second event, etc. }): Promise> { logger.debug( - "getEventByIndexInSchedule called with data: " + JSON.stringify(data) + "getEventByIndexInSchedule called with data: " + JSON.stringify(data), ); const layerProps: Array = await this.getScheduleLayerProps({ @@ -836,7 +836,7 @@ export class Service extends DatabaseService { if (layerProps.length === 0) { logger.debug( - "No layers found for scheduleId: " + data.scheduleId.toString() + "No layers found for scheduleId: " + data.scheduleId.toString(), ); return []; } @@ -846,7 +846,7 @@ export class Service extends DatabaseService { const currentEndTime: Date = OneUptimeDate.addRemoveYears( currentStartTime, - 1 + 1, ); logger.debug("Current end time: " + currentEndTime.toISOString()); @@ -861,7 +861,7 @@ export class Service extends DatabaseService { }, { getNumberOfEvents: numberOfEventsToGet, - } + }, ); logger.debug("Events fetched: " + JSON.stringify(events)); @@ -871,7 +871,7 @@ export class Service extends DatabaseService { @CaptureSpan() public async getCurrentUserIdInSchedule( - scheduleId: ObjectID + scheduleId: ObjectID, ): Promise { const layerProps: Array = await this.getScheduleLayerProps({ scheduleId: scheduleId, @@ -884,7 +884,7 @@ export class Service extends DatabaseService { const currentStartTime: Date = OneUptimeDate.getCurrentDate(); const currentEndTime: Date = OneUptimeDate.addRemoveSeconds( currentStartTime, - 1 + 1, ); const events: Array = this.layerUtil.getMultiLayerEvents( @@ -895,7 +895,7 @@ export class Service extends DatabaseService { }, { getNumberOfEvents: 1, - } + }, ); const currentEvent: CalendarEvent | null = events[0] || null; diff --git a/Common/Server/Services/OnCallDutyPolicyTimeLogService.ts b/Common/Server/Services/OnCallDutyPolicyTimeLogService.ts index d73f977238..11053a5d3d 100644 --- a/Common/Server/Services/OnCallDutyPolicyTimeLogService.ts +++ b/Common/Server/Services/OnCallDutyPolicyTimeLogService.ts @@ -9,61 +9,74 @@ export class Service extends DatabaseService { public async startTimeLogForUser(data: { projectId: ObjectID; - onCallDutyPolicyId: ObjectID; + onCallDutyPolicyId: ObjectID; onCallDutyPolicyEscalationRuleId: ObjectID; userId: ObjectID; teamId?: ObjectID; onCallDutyPolicyScheduleId?: ObjectID; startsAt: Date; - }){ - const { onCallDutyPolicyId, userId, teamId, onCallDutyPolicyScheduleId, startsAt } = data; - const timeLog = new Model(); + }): Promise { + const { + onCallDutyPolicyId, + userId, + teamId, + onCallDutyPolicyScheduleId, + startsAt, + } = data; + const timeLog: Model = new Model(); timeLog.onCallDutyPolicyId = onCallDutyPolicyId; timeLog.userId = userId; - if(teamId) timeLog.teamId = teamId; - timeLog.onCallDutyPolicyEscalationRuleId = data.onCallDutyPolicyEscalationRuleId; - if(onCallDutyPolicyScheduleId) timeLog.onCallDutyPolicyScheduleId = onCallDutyPolicyScheduleId; + if (teamId) { + timeLog.teamId = teamId; + } + timeLog.onCallDutyPolicyEscalationRuleId = + data.onCallDutyPolicyEscalationRuleId; + if (onCallDutyPolicyScheduleId) { + timeLog.onCallDutyPolicyScheduleId = onCallDutyPolicyScheduleId; + } timeLog.startsAt = startsAt; - return await this.create({ data: timeLog, props: { isRoot: true, - } + }, }); } - public async endTimeLogForUser(data: { projectId: ObjectID; - onCallDutyPolicyId: ObjectID; + onCallDutyPolicyId: ObjectID; onCallDutyPolicyEscalationRuleId: ObjectID; userId: ObjectID; teamId?: ObjectID; onCallDutyPolicyScheduleId?: ObjectID; endsAt: Date; - }){ - const { onCallDutyPolicyId, userId, teamId, onCallDutyPolicyScheduleId, endsAt } = data; + }): Promise { + const { + onCallDutyPolicyId, + userId, + teamId, + onCallDutyPolicyScheduleId, + endsAt, + } = data; - return await this.updateOneBy({ + await this.updateOneBy({ query: { onCallDutyPolicyId, onCallDutyPolicyEscalationRuleId: data.onCallDutyPolicyEscalationRuleId, userId, ...(teamId && { teamId }), ...(onCallDutyPolicyScheduleId && { onCallDutyPolicyScheduleId }), - }, data: { endsAt: endsAt, }, props: { isRoot: true, - } + }, }); } - } export default new Service(); diff --git a/Common/Server/Services/WorkspaceNotificationRuleService.ts b/Common/Server/Services/WorkspaceNotificationRuleService.ts index c6b5ea1db5..cf46cee501 100644 --- a/Common/Server/Services/WorkspaceNotificationRuleService.ts +++ b/Common/Server/Services/WorkspaceNotificationRuleService.ts @@ -1541,7 +1541,7 @@ export class Service extends DatabaseService { [NotificationRuleConditionCheckOn.ScheduledMaintenanceLabels]: undefined, [NotificationRuleConditionCheckOn.Monitors]: [ - alert.monitor?.id!.toString() || "", + alert.monitor!.id!.toString() || "", ], [NotificationRuleConditionCheckOn.OnCallDutyPolicyName]: undefined,