notification log -> on call log

This commit is contained in:
Simon Larsen
2023-07-21 14:15:33 +01:00
parent 4dda09b406
commit d86f3a0a33
20 changed files with 127 additions and 127 deletions

View File

@@ -1,7 +1,7 @@
import UserNotificationLogTimeline from 'Model/Models/UserNotificationLogTimeline';
import UserNotificationLogTimelineService, {
import UserOnCallLogTimeline from 'Model/Models/UserOnCallLogTimeline';
import UserOnCallLogTimelineService, {
Service as UserNotificationLogTimelineServiceType,
} from '../Services/UserNotificationLogTimelineService';
} from '../Services/UserOnCallLogTimelineService';
import BaseAPI from './BaseAPI';
import {
ExpressRequest,
@@ -19,11 +19,11 @@ import { DashboardRoute, Domain, HttpProtocol } from '../Config';
import UserNotificationStatus from 'Common/Types/UserNotification/UserNotificationStatus';
export default class UserNotificationLogTimelineAPI extends BaseAPI<
UserNotificationLogTimeline,
UserOnCallLogTimeline,
UserNotificationLogTimelineServiceType
> {
public constructor() {
super(UserNotificationLogTimeline, UserNotificationLogTimelineService);
super(UserOnCallLogTimeline, UserOnCallLogTimelineService);
this.router.post(
`${new this.entityType()
@@ -45,7 +45,7 @@ export default class UserNotificationLogTimelineAPI extends BaseAPI<
const itemId: ObjectID = new ObjectID(req.params['itemId']);
const timelineItem: UserNotificationLogTimeline | null =
const timelineItem: UserOnCallLogTimeline | null =
await this.service.findOneById({
id: itemId,
select: {
@@ -109,7 +109,7 @@ export default class UserNotificationLogTimelineAPI extends BaseAPI<
const itemId: ObjectID = new ObjectID(req.params['itemId']);
const timelineItem: UserNotificationLogTimeline | null =
const timelineItem: UserOnCallLogTimeline | null =
await this.service.findOneById({
id: itemId,
select: {

View File

@@ -12,9 +12,9 @@ import UserEmailService from './UserEmailService';
import UserEmail from 'Model/Models/UserEmail';
import NotificationRuleType from 'Common/Types/NotificationRule/NotificationRuleType';
import UserNotificationEventType from 'Common/Types/UserNotification/UserNotificationEventType';
import UserNotificationLog from 'Model/Models/UserNotificationLog';
import UserNotificationLogService from './UserNotificationLogService';
import UserNotificationLogTimeline from 'Model/Models/UserNotificationLogTimeline';
import UserOnCallLog from 'Model/Models/UserOnCallLog';
import UserOnCallLogService from './UserOnCallLogService';
import UserOnCallLogTimeline from 'Model/Models/UserOnCallLogTimeline';
import UserNotificationStatus from 'Common/Types/UserNotification/UserNotificationStatus';
import CallRequest from 'Common/Types/Call/CallRequest';
import EmailMessage from 'Common/Types/Email/EmailMessage';
@@ -29,7 +29,7 @@ import Dictionary from 'Common/Types/Dictionary';
import Markdown from '../Types/Markdown';
import IncidentService from './IncidentService';
import EmailTemplateType from 'Common/Types/Email/EmailTemplateType';
import UserNotificationLogTimelineService from './UserNotificationLogTimelineService';
import UserOnCallLogTimelineService from './UserOnCallLogTimelineService';
import MailService from './MailService';
import SmsService from './SmsService';
import CallService from './CallService';
@@ -58,8 +58,8 @@ export class Service extends DatabaseService<Model> {
): Promise<void> {
// get user notifcation log and see if this rule has already been executed. If so then skip.
const userNotificationLog: UserNotificationLog | null =
await UserNotificationLogService.findOneById({
const userOnCallLog: UserOnCallLog | null =
await UserOnCallLogService.findOneById({
id: options.userNotificationLogId,
props: {
isRoot: true,
@@ -70,32 +70,32 @@ export class Service extends DatabaseService<Model> {
},
});
if (!userNotificationLog) {
if (!userOnCallLog) {
throw new BadDataException('User notification log not found.');
}
if (
Object.keys(
userNotificationLog.executedNotificationRules || {}
userOnCallLog.executedNotificationRules || {}
).includes(userNotificationRuleId.toString())
) {
// already executed.
return;
}
if (!userNotificationLog.executedNotificationRules) {
userNotificationLog.executedNotificationRules = {};
if (!userOnCallLog.executedNotificationRules) {
userOnCallLog.executedNotificationRules = {};
}
userNotificationLog.executedNotificationRules[
userOnCallLog.executedNotificationRules[
userNotificationRuleId.toString()
] = OneUptimeDate.getCurrentDate();
await UserNotificationLogService.updateOneById({
id: userNotificationLog.id!,
await UserOnCallLogService.updateOneById({
id: userOnCallLog.id!,
data: {
executedNotificationRules: {
...userNotificationLog.executedNotificationRules,
...userOnCallLog.executedNotificationRules,
},
} as any,
props: {
@@ -131,8 +131,8 @@ export class Service extends DatabaseService<Model> {
throw new BadDataException('Notification rule item not found.');
}
const logTimelineItem: UserNotificationLogTimeline =
new UserNotificationLogTimeline();
const logTimelineItem: UserOnCallLogTimeline =
new UserOnCallLogTimeline();
logTimelineItem.projectId = options.projectId;
logTimelineItem.userNotificationLogId = options.userNotificationLogId;
logTimelineItem.userNotificationRuleId = userNotificationRuleId;
@@ -222,8 +222,8 @@ export class Service extends DatabaseService<Model> {
logTimelineItem.userEmailId =
notificationRuleItem.userEmail.id!;
const updatedLog: UserNotificationLogTimeline =
await UserNotificationLogTimelineService.create({
const updatedLog: UserOnCallLogTimeline =
await UserOnCallLogTimelineService.create({
data: logTimelineItem,
props: {
isRoot: true,
@@ -242,7 +242,7 @@ export class Service extends DatabaseService<Model> {
MailService.sendMail(emailMessage, undefined, {
userNotificationLogTimelineId: updatedLog.id!,
}).catch(async (err: Error) => {
await UserNotificationLogTimelineService.updateOneById({
await UserOnCallLogTimelineService.updateOneById({
id: updatedLog.id!,
data: {
status: UserNotificationStatus.Error,
@@ -266,7 +266,7 @@ export class Service extends DatabaseService<Model> {
logTimelineItem.status = UserNotificationStatus.Error;
logTimelineItem.statusMessage = `Email notification not sent because email ${notificationRuleItem.userEmail?.email.toString()} is not verified.`;
await UserNotificationLogTimelineService.create({
await UserOnCallLogTimelineService.create({
data: logTimelineItem,
props: {
isRoot: true,
@@ -290,8 +290,8 @@ export class Service extends DatabaseService<Model> {
logTimelineItem.statusMessage = `Sending SMS to ${notificationRuleItem.userSms?.phone.toString()}.`;
logTimelineItem.userSmsId = notificationRuleItem.userSms.id!;
const updatedLog: UserNotificationLogTimeline =
await UserNotificationLogTimelineService.create({
const updatedLog: UserOnCallLogTimeline =
await UserOnCallLogTimelineService.create({
data: logTimelineItem,
props: {
isRoot: true,
@@ -311,7 +311,7 @@ export class Service extends DatabaseService<Model> {
projectId: incident.projectId,
userNotificationLogTimelineId: updatedLog.id!,
}).catch(async (err: Error) => {
await UserNotificationLogTimelineService.updateOneById({
await UserOnCallLogTimelineService.updateOneById({
id: updatedLog.id!,
data: {
status: UserNotificationStatus.Error,
@@ -333,7 +333,7 @@ export class Service extends DatabaseService<Model> {
logTimelineItem.status = UserNotificationStatus.Error;
logTimelineItem.statusMessage = `SMS not sent because phone ${notificationRuleItem.userSms?.phone.toString()} is not verified.`;
await UserNotificationLogTimelineService.create({
await UserOnCallLogTimelineService.create({
data: logTimelineItem,
props: {
isRoot: true,
@@ -351,8 +351,8 @@ export class Service extends DatabaseService<Model> {
logTimelineItem.statusMessage = `Making a call to ${notificationRuleItem.userCall?.phone.toString()}.`;
logTimelineItem.userCallId = notificationRuleItem.userCall.id!;
const updatedLog: UserNotificationLogTimeline =
await UserNotificationLogTimelineService.create({
const updatedLog: UserOnCallLogTimeline =
await UserOnCallLogTimelineService.create({
data: logTimelineItem,
props: {
isRoot: true,
@@ -372,7 +372,7 @@ export class Service extends DatabaseService<Model> {
projectId: incident.projectId,
userNotificationLogTimelineId: updatedLog.id!,
}).catch(async (err: Error) => {
await UserNotificationLogTimelineService.updateOneById({
await UserOnCallLogTimelineService.updateOneById({
id: updatedLog.id!,
data: {
status: UserNotificationStatus.Error,
@@ -393,7 +393,7 @@ export class Service extends DatabaseService<Model> {
logTimelineItem.status = UserNotificationStatus.Error;
logTimelineItem.statusMessage = `Call not sent because phone ${notificationRuleItem.userCall?.phone.toString()} is not verified.`;
await UserNotificationLogTimelineService.create({
await UserOnCallLogTimelineService.create({
data: logTimelineItem,
props: {
isRoot: true,
@@ -438,7 +438,7 @@ export class Service extends DatabaseService<Model> {
Domain,
new Route(DashboardApiRoute.toString())
.addRoute(
new UserNotificationLogTimeline().crudApiPath!
new UserOnCallLogTimeline().crudApiPath!
)
.addRoute(
'/call/gather-input/' +
@@ -462,7 +462,7 @@ export class Service extends DatabaseService<Model> {
HttpProtocol,
Domain,
new Route(DashboardApiRoute.toString())
.addRoute(new UserNotificationLogTimeline().crudApiPath!)
.addRoute(new UserOnCallLogTimeline().crudApiPath!)
.addRoute(
'/acknowledge/' +
userNotificationLogTimelineId.toString()
@@ -505,7 +505,7 @@ export class Service extends DatabaseService<Model> {
HttpProtocol,
Domain,
new Route(DashboardApiRoute.toString())
.addRoute(new UserNotificationLogTimeline().crudApiPath!)
.addRoute(new UserOnCallLogTimeline().crudApiPath!)
.addRoute(
'/acknowledge/' +
userNotificationLogTimelineId.toString()
@@ -537,49 +537,49 @@ export class Service extends DatabaseService<Model> {
}
): Promise<void> {
// add user notification log.
const userNotificationLog: UserNotificationLog =
new UserNotificationLog();
const userOnCallLog: UserOnCallLog =
new UserOnCallLog();
userNotificationLog.userId = userId;
userNotificationLog.projectId = options.projectId;
userOnCallLog.userId = userId;
userOnCallLog.projectId = options.projectId;
if (options.triggeredByIncidentId) {
userNotificationLog.triggeredByIncidentId =
userOnCallLog.triggeredByIncidentId =
options.triggeredByIncidentId;
}
userNotificationLog.userNotificationEventType =
userOnCallLog.userNotificationEventType =
options.userNotificationEventType;
if (options.onCallPolicyExecutionLogId) {
userNotificationLog.onCallDutyPolicyExecutionLogId =
userOnCallLog.onCallDutyPolicyExecutionLogId =
options.onCallPolicyExecutionLogId;
}
if (options.onCallPolicyId) {
userNotificationLog.onCallDutyPolicyId = options.onCallPolicyId;
userOnCallLog.onCallDutyPolicyId = options.onCallPolicyId;
}
if (options.onCallDutyPolicyExecutionLogTimelineId) {
userNotificationLog.onCallDutyPolicyExecutionLogTimelineId =
userOnCallLog.onCallDutyPolicyExecutionLogTimelineId =
options.onCallDutyPolicyExecutionLogTimelineId;
}
if (options.onCallPolicyEscalationRuleId) {
userNotificationLog.onCallDutyPolicyEscalationRuleId =
userOnCallLog.onCallDutyPolicyEscalationRuleId =
options.onCallPolicyEscalationRuleId;
}
if (options.userBelongsToTeamId) {
userNotificationLog.userBelongsToTeamId =
userOnCallLog.userBelongsToTeamId =
options.userBelongsToTeamId;
}
userNotificationLog.status = UserNotificationExecutionStatus.Scheduled;
userNotificationLog.statusMessage = 'Scheduled';
userOnCallLog.status = UserNotificationExecutionStatus.Scheduled;
userOnCallLog.statusMessage = 'Scheduled';
await UserNotificationLogService.create({
data: userNotificationLog,
await UserOnCallLogService.create({
data: userOnCallLog,
props: {
isRoot: true,
},

View File

@@ -1,5 +1,5 @@
import PostgresDatabase from '../Infrastructure/PostgresDatabase';
import Model from 'Model/Models/UserNotificationLog';
import Model from 'Model/Models/UserOnCallLog';
import DatabaseService, { OnCreate, OnUpdate } from './DatabaseService';
import UserNotificationRule from 'Model/Models/UserNotificationRule';
import UserNotificationRuleService from './UserNotificationRuleService';

View File

@@ -1,9 +1,9 @@
import PostgresDatabase from '../Infrastructure/PostgresDatabase';
import Model from 'Model/Models/UserNotificationLogTimeline';
import Model from 'Model/Models/UserOnCallLogTimeline';
import DatabaseService, { OnUpdate } from './DatabaseService';
import ObjectID from 'Common/Types/ObjectID';
import { LIMIT_PER_PROJECT } from 'Common/Types/Database/LimitMax';
import UserNotificationLogService from './UserNotificationLogService';
import UserOnCallLogService from './UserOnCallLogService';
import OnCallDutyPolicyExecutionLogService from './OnCallDutyPolicyExecutionLogService';
import OnCallDutyPolicyExecutionLogTimelineService from './OnCallDutyPolicyExecutionLogTimelineService';
import IncidentService from './IncidentService';
@@ -66,7 +66,7 @@ export class Service extends DatabaseService<Model> {
throw new BadDataException('User not found.');
}
await UserNotificationLogService.updateOneById({
await UserOnCallLogService.updateOneById({
id: item.userNotificationLogId!,
data: {
acknowledgedAt: onUpdate.updateBy.data.acknowledgedAt,

View File

@@ -154,8 +154,8 @@ import PageComponentProps from './Pages/PageComponentProps';
import UserSettingsNotificationMethods from './Pages/UserSettings/NotificationMethods';
import UserSettingsNotificationRules from './Pages/UserSettings/OnCallRules';
import UserSettingsNotificationLogs from './Pages/UserSettings/NotificationLogs';
import UserSettingsNotificationLogsTimeline from './Pages/UserSettings/NotificationLogsTimeline';
import UserSettingsNotificationLogs from './Pages/UserSettings/OnCallLogs';
import UserSettingsNotificationLogsTimeline from './Pages/UserSettings/OnCallLogsTimeline';
import UserSettingsNotiifcationSetting from './Pages/UserSettings/NotificationSettings';
const App: FunctionComponent = () => {
@@ -2072,7 +2072,7 @@ const App: FunctionComponent = () => {
<PageRoute
path={
RouteMap[
PageMap.USER_SETTINGS_NOTIFICATION_LOGS
PageMap.USER_SETTINGS_ON_CALL_LOGS
]?.toString() || ''
}
element={
@@ -2080,7 +2080,7 @@ const App: FunctionComponent = () => {
{...commonPageProps}
pageRoute={
RouteMap[
PageMap.USER_SETTINGS_NOTIFICATION_LOGS
PageMap.USER_SETTINGS_ON_CALL_LOGS
] as Route
}
/>
@@ -2090,7 +2090,7 @@ const App: FunctionComponent = () => {
<PageRoute
path={
RouteMap[
PageMap.USER_SETTINGS_NOTIFICATION_LOGS_TIMELINE
PageMap.USER_SETTINGS_ON_CALL_LOGS_TIMELINE
]?.toString() || ''
}
element={
@@ -2099,7 +2099,7 @@ const App: FunctionComponent = () => {
pageRoute={
RouteMap[
PageMap
.USER_SETTINGS_NOTIFICATION_LOGS_TIMELINE
.USER_SETTINGS_ON_CALL_LOGS_TIMELINE
] as Route
}
/>

View File

@@ -6,7 +6,7 @@ import RouteMap, { RouteUtil } from '../../Utils/RouteMap';
import PageComponentProps from '../PageComponentProps';
import DashboardSideMenu from './SideMenu';
import ModelTable from 'CommonUI/src/Components/ModelTable/ModelTable';
import UserNotificationLog from 'Model/Models/UserNotificationLog';
import UserOnCallLog from 'Model/Models/UserOnCallLog';
import DashboardNavigation from '../../Utils/Navigation';
import User from 'CommonUI/src/Utils/User';
import IconProp from 'Common/Types/Icon/IconProp';
@@ -51,15 +51,15 @@ const Settings: FunctionComponent<PageComponentProps> = (
title: 'Notification Logs',
to: RouteUtil.populateRouteParams(
RouteMap[
PageMap.USER_SETTINGS_NOTIFICATION_LOGS
PageMap.USER_SETTINGS_ON_CALL_LOGS
] as Route
),
},
]}
sideMenu={<DashboardSideMenu />}
>
<ModelTable<UserNotificationLog>
modelType={UserNotificationLog}
<ModelTable<UserOnCallLog>
modelType={UserOnCallLog}
query={{
projectId: DashboardNavigation.getProjectId()?.toString(),
userId: User.getUserId()?.toString(),

View File

@@ -18,7 +18,7 @@ import { Green, Red, Yellow } from 'Common/Types/BrandColors';
import { ButtonStyleType } from 'CommonUI/src/Components/Button/Button';
import ConfirmModal from 'CommonUI/src/Components/Modal/ConfirmModal';
import ObjectID from 'Common/Types/ObjectID';
import UserNotificationLogTimeline from 'Model/Models/UserNotificationLogTimeline';
import UserOnCallLogTimeline from 'Model/Models/UserOnCallLogTimeline';
import BaseModel from 'Common/Models/BaseModel';
import NotificationMethodView from '../../Components/NotificationMethods/NotificationMethod';
import DropdownUtil from 'CommonUI/src/Utils/Dropdown';
@@ -34,8 +34,8 @@ const Settings: FunctionComponent<PageComponentProps> = (
const getModelTable: Function = (): ReactElement => {
return (
<ModelTable<UserNotificationLogTimeline>
modelType={UserNotificationLogTimeline}
<ModelTable<UserOnCallLogTimeline>
modelType={UserOnCallLogTimeline}
query={{
projectId: DashboardNavigation.getProjectId()?.toString(),
userNotificationLogId: modelId.toString(),
@@ -101,7 +101,7 @@ const Settings: FunctionComponent<PageComponentProps> = (
return (
<NotificationMethodView
item={item}
modelType={UserNotificationLogTimeline}
modelType={UserOnCallLogTimeline}
/>
);
},
@@ -201,7 +201,7 @@ const Settings: FunctionComponent<PageComponentProps> = (
title: 'Notification Logs',
to: RouteUtil.populateRouteParams(
RouteMap[
PageMap.USER_SETTINGS_NOTIFICATION_LOGS
PageMap.USER_SETTINGS_ON_CALL_LOGS
] as Route
),
},
@@ -209,7 +209,7 @@ const Settings: FunctionComponent<PageComponentProps> = (
title: 'Timeline',
to: RouteUtil.populateRouteParams(
RouteMap[
PageMap.USER_SETTINGS_NOTIFICATION_LOGS_TIMELINE
PageMap.USER_SETTINGS_ON_CALL_LOGS_TIMELINE
] as Route,
{
modelId,

View File

@@ -14,7 +14,7 @@ const DashboardSideMenu: FunctionComponent = (): ReactElement => {
if (
Navigation.isOnThisPage(
RouteMap[PageMap.USER_SETTINGS_NOTIFICATION_LOGS_TIMELINE]!
RouteMap[PageMap.USER_SETTINGS_ON_CALL_LOGS_TIMELINE]!
)
) {
subItemMenuLink = {
@@ -63,10 +63,10 @@ const DashboardSideMenu: FunctionComponent = (): ReactElement => {
<SideMenuSection title="Logs">
<SideMenuItem
link={{
title: 'Notification Logs',
title: 'On Call Logs',
to: RouteUtil.populateRouteParams(
RouteMap[
PageMap.USER_SETTINGS_NOTIFICATION_LOGS
PageMap.USER_SETTINGS_ON_CALL_LOGS
] as Route
),
}}

View File

@@ -93,8 +93,8 @@ enum PageMap {
USER_SETTINGS = 'USER_SETTINGS',
USER_SETTINGS_NOTIFICATION_METHODS = 'USER_SETTINGS_NOTIFICATION_METHODS',
USER_SETTINGS_ON_CALL_RULES = 'USER_SETTINGS_ON_CALL_RULES',
USER_SETTINGS_NOTIFICATION_LOGS = 'USER_SETTINGS_NOTIFICATION_LOGS',
USER_SETTINGS_NOTIFICATION_LOGS_TIMELINE = 'USER_SETTINGS_NOTIFICATION_LOGS_TIMELINE',
USER_SETTINGS_ON_CALL_LOGS = 'USER_SETTINGS_ON_CALL_LOGS',
USER_SETTINGS_ON_CALL_LOGS_TIMELINE = 'USER_SETTINGS_ON_CALL_LOGS_TIMELINE',
USER_SETTINGS_NOTIFICATION_SETTINGS = 'USER_SETTINGS_NOTIFICATION_SETTINGS',
// Settings Routes

View File

@@ -331,11 +331,11 @@ const RouteMap: Dictionary<Route> = {
`/dashboard/${RouteParams.ProjectID}/settings/on-call-rules`
),
[PageMap.USER_SETTINGS_NOTIFICATION_LOGS]: new Route(
[PageMap.USER_SETTINGS_ON_CALL_LOGS]: new Route(
`/dashboard/${RouteParams.ProjectID}/settings/notification-logs`
),
[PageMap.USER_SETTINGS_NOTIFICATION_LOGS_TIMELINE]: new Route(
[PageMap.USER_SETTINGS_ON_CALL_LOGS_TIMELINE]: new Route(
`/dashboard/${RouteParams.ProjectID}/settings/notification-logs/${RouteParams.ModelID}`
),

View File

@@ -332,10 +332,10 @@ import OnCallDutyPolicyCustomFieldService, {
import UserNotificaitonLogTimelineAPI from 'CommonServer/API/UserNotificationLogTimelineAPI';
import UserNotificationLog from 'Model/Models/UserNotificationLog';
import UserNotificationLogService, {
import UserOnCallLog from 'Model/Models/UserOnCallLog';
import UserOnCallLogService, {
Service as UserNotificationLogServiceType,
} from 'CommonServer/Services/UserNotificationLogService';
} from 'CommonServer/Services/UserOnCallLogService';
import UserNotificationSetting from 'Model/Models/UserNotificationSetting';
import UserNotificationSettingService, {
@@ -665,9 +665,9 @@ app.use(
app.use(
`/${APP_NAME.toLocaleLowerCase()}`,
new BaseAPI<UserNotificationLog, UserNotificationLogServiceType>(
UserNotificationLog,
UserNotificationLogService
new BaseAPI<UserOnCallLog, UserNotificationLogServiceType>(
UserOnCallLog,
UserOnCallLogService
).getRouter()
);

View File

@@ -102,8 +102,8 @@ import CallLog from './CallLog';
// User Notification Rules
import UserNotificationRule from './UserNotificationRule';
import UserNotificationLog from './UserNotificationLog';
import UserNotificationLogTimeline from './UserNotificationLogTimeline';
import UserOnCallLog from './UserOnCallLog';
import UserOnCallLogTimeline from './UserOnCallLogTimeline';
import UserNotificationSetting from './UserNotificationSetting';
// Date migration
@@ -200,8 +200,8 @@ export default [
UserCall,
UserNotificationRule,
UserNotificationLog,
UserNotificationLogTimeline,
UserOnCallLog,
UserOnCallLogTimeline,
UserNotificationSetting,
DataMigration,

View File

@@ -44,16 +44,16 @@ import { PlanSelect } from 'Common/Types/Billing/SubscriptionPlan';
})
@CrudApiEndpoint(new Route('/user-notification-log'))
@Entity({
name: 'UserNotificationLog',
name: 'UserOnCallLog',
})
@TableMetadata({
tableName: 'UserNotificationLog',
tableName: 'UserOnCallLog',
singularName: 'User Notification Log',
pluralName: 'User Notification Logs',
icon: IconProp.Logs,
tableDescription: 'Log events for user notifications',
})
export default class UserNotificationLog extends BaseModel {
export default class UserOnCallLog extends BaseModel {
@ColumnAccessControl({
create: [],
read: [Permission.CurrentUser],

View File

@@ -21,7 +21,7 @@ import Team from './Team';
import OnCallDutyPolicyEscalationRule from './OnCallDutyPolicyEscalationRule';
import Incident from './Incident';
import OnCallDutyPolicy from './OnCallDutyPolicy';
import UserNotificationLog from './UserNotificationLog';
import UserOnCallLog from './UserOnCallLog';
import UserNotificationRule from './UserNotificationRule';
import UserNotificationEventType from 'Common/Types/UserNotification/UserNotificationEventType';
import UserNotificationStatus from 'Common/Types/UserNotification/UserNotificationStatus';
@@ -48,16 +48,16 @@ import { PlanSelect } from 'Common/Types/Billing/SubscriptionPlan';
})
@CrudApiEndpoint(new Route('/user-notification-log-timeline'))
@Entity({
name: 'UserNotifiationLogTimeline',
name: 'UserOnCallLogTimeline',
})
@TableMetadata({
tableName: 'UserNotifiationLogTimeline',
singularName: 'User Notification Log Timeline',
pluralName: 'User Notification Log Timelines',
tableName: 'UserOnCallLogTimeline',
singularName: 'User On Call Log Timeline',
pluralName: 'User On Call Log Timelines',
icon: IconProp.Logs,
tableDescription: 'Timeline events for user notificaiton log.',
tableDescription: 'Timeline events for user on call log.',
})
export default class UserNotificationLogTimeline extends BaseModel {
export default class UserOnCallLogTimeline extends BaseModel {
@ColumnAccessControl({
create: [],
read: [Permission.CurrentUser],
@@ -157,14 +157,14 @@ export default class UserNotificationLogTimeline extends BaseModel {
@TableColumn({
manyToOneRelationColumn: 'userNotificationLogId',
type: TableColumnType.Entity,
modelType: UserNotificationLog,
modelType: UserOnCallLog,
title: 'User Notification Log',
description:
'Relation to User Notification Log Resource in which this object belongs',
})
@ManyToOne(
(_type: string) => {
return UserNotificationLog;
return UserOnCallLog;
},
{
eager: false,
@@ -174,7 +174,7 @@ export default class UserNotificationLogTimeline extends BaseModel {
}
)
@JoinColumn({ name: 'userNotificationLogId' })
public userNotificationLog?: UserNotificationLog = undefined;
public userOnCallLog?: UserOnCallLog = undefined;
@ColumnAccessControl({
create: [],

View File

@@ -21,7 +21,7 @@ import { CallInstance } from 'twilio/lib/rest/api/v2010/account/call';
import JSONWebToken from 'CommonServer/Utils/JsonWebToken';
import OneUptimeDate from 'Common/Types/Date';
import JSONFunctions from 'Common/Types/JSONFunctions';
import UserNotificationLogTimelineService from 'CommonServer/Services/UserNotificationLogTimelineService';
import UserOnCallLogTimelineService from 'CommonServer/Services/UserOnCallLogTimelineService';
import UserNotificationStatus from 'Common/Types/UserNotification/UserNotificationStatus';
export default class CallService {
@@ -263,7 +263,7 @@ export default class CallService {
}
if (options.userNotificationLogTimelineId) {
await UserNotificationLogTimelineService.updateOneById({
await UserOnCallLogTimelineService.updateOneById({
data: {
status:
callLog.status === CallStatus.Success

View File

@@ -18,7 +18,7 @@ import { IsDevelopment } from 'CommonServer/Config';
import { SendGridApiKey } from '../Config';
import SendgridMail, { MailDataRequired } from '@sendgrid/mail';
import ObjectID from 'Common/Types/ObjectID';
import UserNotificationLogTimelineService from 'CommonServer/Services/UserNotificationLogTimelineService';
import UserOnCallLogTimelineService from 'CommonServer/Services/UserOnCallLogTimelineService';
import UserNotificationStatus from 'Common/Types/UserNotification/UserNotificationStatus';
export default class MailService {
@@ -115,7 +115,7 @@ export default class MailService {
timelineId: ObjectID
): Promise<void> {
if (timelineId) {
await UserNotificationLogTimelineService.updateOneById({
await UserOnCallLogTimelineService.updateOneById({
data: {
status: UserNotificationStatus.Sent,
statusMessage: 'Email sent successfully',
@@ -256,7 +256,7 @@ export default class MailService {
} catch (err: any) {
logger.error(err);
if (options?.userNotificationLogTimelineId) {
await UserNotificationLogTimelineService.updateOneById({
await UserOnCallLogTimelineService.updateOneById({
data: {
status: UserNotificationStatus.Error,
statusMessage: err.message || 'Email failed to send',

View File

@@ -17,7 +17,7 @@ import { MessageInstance } from 'twilio/lib/rest/api/v2010/account/message';
import NotificationService from 'CommonServer/Services/NotificationService';
import logger from 'CommonServer/Utils/Logger';
import TwilioUtil from '../Utils/Twilio';
import UserNotificationLogTimelineService from 'CommonServer/Services/UserNotificationLogTimelineService';
import UserOnCallLogTimelineService from 'CommonServer/Services/UserOnCallLogTimelineService';
import UserNotificationStatus from 'Common/Types/UserNotification/UserNotificationStatus';
export default class SmsService {
@@ -253,7 +253,7 @@ export default class SmsService {
}
if (options.userNotificationLogTimelineId) {
await UserNotificationLogTimelineService.updateOneById({
await UserOnCallLogTimelineService.updateOneById({
data: {
status:
smsLog.status === SmsStatus.Success

View File

@@ -66,8 +66,8 @@ import './Jobs/OnCallDutyPolicyExecutionLog/ExecutePendingExecutions';
import './Jobs/OnCallDutyPolicyExecutionLog/TimeoutStuckExecutions';
// User Notifications Log
import './Jobs/UserNotificationLog/ExecutePendingExecutions';
import './Jobs/UserNotificationLog/TimeoutStuckExecutions';
import './Jobs/UserOnCallLog/ExecutePendingExecutions';
import './Jobs/UserOnCallLog/TimeoutStuckExecutions';
const APP_NAME: string = 'workers';

View File

@@ -1,8 +1,8 @@
import { IsDevelopment } from 'CommonServer/Config';
import RunCron from '../../Utils/Cron';
import { EVERY_MINUTE } from 'Common/Utils/CronTime';
import UserNotificationLog from 'Model/Models/UserNotificationLog';
import UserNotificationLogService from 'CommonServer/Services/UserNotificationLogService';
import UserOnCallLog from 'Model/Models/UserOnCallLog';
import UserOnCallLogService from 'CommonServer/Services/UserOnCallLogService';
import LIMIT_MAX, { LIMIT_PER_PROJECT } from 'Common/Types/Database/LimitMax';
import UserNotificationExecutionStatus from 'Common/Types/UserNotification/UserNotificationExecutionStatus';
import logger from 'CommonServer/Utils/Logger';
@@ -14,14 +14,14 @@ import Incident from 'Model/Models/Incident';
import IncidentService from 'CommonServer/Services/IncidentService';
RunCron(
'UserNotificationLog:ExecutePendingExecutions',
'UserOnCallLog:ExecutePendingExecutions',
{
schedule: IsDevelopment ? EVERY_MINUTE : EVERY_MINUTE,
runOnStartup: false,
},
async () => {
const pendingNotiifcationLogs: Array<UserNotificationLog> =
await UserNotificationLogService.findBy({
const pendingNotiifcationLogs: Array<UserOnCallLog> =
await UserOnCallLogService.findBy({
query: {
status: UserNotificationExecutionStatus.Executing,
},
@@ -59,11 +59,11 @@ RunCron(
);
const executePendingNotificationLog: Function = async (
pendingNotificationLog: UserNotificationLog
pendingNotificationLog: UserOnCallLog
): Promise<void> => {
try {
const ruleType: NotificationRuleType =
UserNotificationLogService.getNotificationRuleType(
UserOnCallLogService.getNotificationRuleType(
pendingNotificationLog.userNotificationEventType!
);
@@ -149,7 +149,7 @@ const executePendingNotificationLog: Function = async (
if (isAllExecuted) {
// mark this log as complete.
await UserNotificationLogService.updateOneById({
await UserOnCallLogService.updateOneById({
id: pendingNotificationLog.id!,
data: {
status: UserNotificationExecutionStatus.Completed,
@@ -165,7 +165,7 @@ const executePendingNotificationLog: Function = async (
err
);
await UserNotificationLogService.updateOneById({
await UserOnCallLogService.updateOneById({
id: pendingNotificationLog.id!,
data: {
status: UserNotificationExecutionStatus.Error,

View File

@@ -4,8 +4,8 @@ import { EVERY_MINUTE } from 'Common/Utils/CronTime';
import LIMIT_MAX from 'Common/Types/Database/LimitMax';
import OneUptimeDate from 'Common/Types/Date';
import QueryHelper from 'CommonServer/Types/Database/QueryHelper';
import UserNotificationLog from 'Model/Models/UserNotificationLog';
import UserNotificationLogService from 'CommonServer/Services/UserNotificationLogService';
import UserOnCallLog from 'Model/Models/UserOnCallLog';
import UserOnCallLogService from 'CommonServer/Services/UserOnCallLogService';
import UserNotificationExecutionStatus from 'Common/Types/UserNotification/UserNotificationExecutionStatus';
/**
@@ -13,7 +13,7 @@ import UserNotificationExecutionStatus from 'Common/Types/UserNotification/UserN
*/
RunCron(
'UserNotificationLog:TimeoutStuckExecutions',
'UserOnCallLog:TimeoutStuckExecutions',
{
schedule: IsDevelopment ? EVERY_MINUTE : EVERY_MINUTE,
runOnStartup: false,
@@ -22,8 +22,8 @@ RunCron(
// get all pending on call executions and execute them all at once.
const fiveMinsAgo: Date = OneUptimeDate.getSomeMinutesAgo(5);
const stuckExecutions: Array<UserNotificationLog> =
await UserNotificationLogService.findBy({
const stuckExecutions: Array<UserOnCallLog> =
await UserOnCallLogService.findBy({
query: {
status: UserNotificationExecutionStatus.Started,
createdAt: QueryHelper.lessThan(fiveMinsAgo),
@@ -40,7 +40,7 @@ RunCron(
});
for (const executionLog of stuckExecutions) {
await UserNotificationLogService.updateOneById({
await UserOnCallLogService.updateOneById({
id: executionLog.id!,
data: {
status: UserNotificationExecutionStatus.Error,