Skip to content
This repository was archived by the owner on Nov 21, 2020. It is now read-only.

Commit ed239cc

Browse files
khangaridbBattulga BatAmar
authored andcommitted
feat(notification): show stage names on notifications
close #1124
1 parent cb74519 commit ed239cc

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

src/data/resolvers/boardUtils.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,25 @@ export const sendNotifications = async ({
120120
});
121121
};
122122

123-
export const itemsChange = async (collection: any, item: any, type: string, destinationStageId: string) => {
124-
const oldItem = await collection.findOne({ _id: item._id });
125-
const oldStageId = oldItem ? oldItem.stageId || '' : '';
123+
export const itemsChange = async (item: any, type: string, destinationStageId: string) => {
124+
const oldStageId = item ? item.stageId || '' : '';
126125

127126
let action = `changed order of your ${type}:`;
128127
let content = `'${item.name}'`;
129128

130129
if (oldStageId !== destinationStageId) {
131-
const stage = await Stages.findOne({ _id: destinationStageId });
130+
const stage = await Stages.getStage(destinationStageId);
131+
const oldStage = await Stages.getStage(oldStageId);
132132

133-
if (!stage) {
134-
throw new Error('Stage not found');
135-
}
133+
const pipeline = await Pipelines.getPipeline(stage.pipelineId || '');
134+
const oldPipeline = await Pipelines.getPipeline(oldStage.pipelineId || '');
136135

137-
action = `moved your`;
136+
const board = await Boards.getBoard(pipeline.boardId || '');
137+
const oldBoard = await Boards.getBoard(oldPipeline.boardId || '');
138138

139-
content = `${type} '${item.name}' to the '${stage.name}'.`;
139+
action = `moved '${item.name}' from ${oldBoard.name}-${oldPipeline.name}-${oldStage.name} to `;
140+
141+
content = `${board.name}-${pipeline.name}-${stage.name}`;
140142
}
141143

142144
return { content, action };

src/data/resolvers/mutations/deals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const dealMutations = {
114114
stageId: destinationStageId,
115115
});
116116

117-
const { content, action } = await itemsChange(Deals, deal, 'deal', destinationStageId);
117+
const { content, action } = await itemsChange(deal, 'deal', destinationStageId);
118118

119119
await sendNotifications({
120120
item: deal,

src/data/resolvers/mutations/tasks.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ const taskMutations = {
7676
{ _id, destinationStageId }: { _id: string; destinationStageId: string },
7777
{ user }: IContext,
7878
) {
79-
const task = await Tasks.updateTask(_id, {
79+
const task = await Tasks.getTask(_id);
80+
81+
await Tasks.updateTask(_id, {
8082
modifiedAt: new Date(),
8183
modifiedBy: user._id,
8284
stageId: destinationStageId,
8385
});
8486

85-
const { content, action } = await itemsChange(Tasks, task, 'task', destinationStageId);
87+
const { content, action } = await itemsChange(task, 'task', destinationStageId);
8688

8789
await sendNotifications({
8890
item: task,

src/data/resolvers/mutations/tickets.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ const ticketMutations = {
7676
{ _id, destinationStageId }: { _id: string; destinationStageId: string },
7777
{ user }: IContext,
7878
) {
79-
const ticket = await Tickets.updateTicket(_id, {
79+
const ticket = await Tickets.getTicket(_id);
80+
81+
await Tickets.updateTicket(_id, {
8082
modifiedAt: new Date(),
8183
modifiedBy: user._id,
8284
stageId: destinationStageId,
8385
});
8486

85-
const { content, action } = await itemsChange(Tickets, ticket, 'ticket', destinationStageId);
87+
const { content, action } = await itemsChange(ticket, 'ticket', destinationStageId);
8688

8789
await sendNotifications({
8890
item: ticket,

src/db/models/Boards.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,27 @@ const createOrUpdatePipelineStages = async (stages: IPipelineStage[], pipelineId
9191
};
9292

9393
export interface IBoardModel extends Model<IBoardDocument> {
94+
getBoard(_id: string): Promise<IBoardDocument>;
9495
createBoard(doc: IBoard): Promise<IBoardDocument>;
9596
updateBoard(_id: string, doc: IBoard): Promise<IBoardDocument>;
9697
removeBoard(_id: string): void;
9798
}
9899

99100
export const loadBoardClass = () => {
100101
class Board {
102+
/*
103+
* Get a Board
104+
*/
105+
public static async getBoard(_id: string) {
106+
const board = await Boards.findOne({ _id });
107+
108+
if (!board) {
109+
throw new Error('Board not found');
110+
}
111+
112+
return board;
113+
}
114+
101115
/**
102116
* Create a board
103117
*/

0 commit comments

Comments
 (0)