-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update incident feed event types for owner additions and enhanc…
…e related services
- Loading branch information
Showing
6 changed files
with
107 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,60 @@ | ||
import ObjectID from "../../Types/ObjectID"; | ||
import { OnCreate } from "../Types/Database/Hooks"; | ||
import DatabaseService from "./DatabaseService"; | ||
import Model from "Common/Models/DatabaseModels/IncidentOwnerTeam"; | ||
import IncidentFeedService from "./IncidentFeedService"; | ||
import { IncidentFeedEventType } from "../../Models/DatabaseModels/IncidentFeed"; | ||
import { Blue500 } from "../../Types/BrandColors"; | ||
import TeamService from "./TeamService"; | ||
import Team from "../../Models/DatabaseModels/Team"; | ||
|
||
export class Service extends DatabaseService<Model> { | ||
public constructor() { | ||
super(Model); | ||
} | ||
|
||
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; | ||
|
||
|
||
if (incidentId && teamId && projectId) { | ||
|
||
|
||
const team: Team | null = await TeamService.findOneById({ | ||
id: teamId, | ||
select: { | ||
name: true | ||
}, | ||
props: { | ||
isRoot: true | ||
} | ||
}) | ||
|
||
if (team && team.name) { | ||
|
||
|
||
await IncidentFeedService.createIncidentFeed({ | ||
|
||
incidentId: incidentId, | ||
projectId: projectId, | ||
incidentFeedEventType: IncidentFeedEventType.OwnerTeamAdded, | ||
displayColor: Blue500, | ||
feedInfoInMarkdown: `Team ${team.name} was added to the incident as the owner.`, | ||
userId: createdByUserId || undefined, | ||
}); | ||
|
||
} | ||
|
||
} | ||
|
||
return createdItem; | ||
|
||
} | ||
} | ||
|
||
export default new Service(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,60 @@ | ||
import ObjectID from "../../Types/ObjectID"; | ||
import DatabaseService from "./DatabaseService"; | ||
import Model from "Common/Models/DatabaseModels/IncidentOwnerUser"; | ||
import IncidentFeedService from "./IncidentFeedService"; | ||
import { IncidentFeedEventType } from "../../Models/DatabaseModels/IncidentFeed"; | ||
import { Blue500 } from "../../Types/BrandColors"; | ||
import User from "../../Models/DatabaseModels/User"; | ||
import UserService from "./UserService"; | ||
import { OnCreate } from "../Types/Database/Hooks"; | ||
|
||
export class Service extends DatabaseService<Model> { | ||
public constructor() { | ||
super(Model); | ||
} | ||
|
||
|
||
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; | ||
|
||
|
||
if (incidentId && userId && projectId) { | ||
|
||
|
||
const user: User | null = await UserService.findOneById({ | ||
id: userId, | ||
select: { | ||
name: true, | ||
email: true | ||
}, | ||
props: { | ||
isRoot: true | ||
} | ||
}) | ||
|
||
if (user && user.name) { | ||
|
||
await IncidentFeedService.createIncidentFeed({ | ||
incidentId: incidentId, | ||
projectId: projectId, | ||
incidentFeedEventType: IncidentFeedEventType.OwnerUserAdded, | ||
displayColor: Blue500, | ||
feedInfoInMarkdown: `${user.name.toString()} (${user.email?.toString()}) was added to the incident as the owner.`, | ||
userId: createdByUserId || undefined, | ||
}); | ||
|
||
} | ||
|
||
} | ||
|
||
return createdItem; | ||
|
||
} | ||
} | ||
|
||
export default new Service(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters