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

Commit

Permalink
feat(notification): show stage names on notifications
Browse files Browse the repository at this point in the history
close #1124
  • Loading branch information
khangaridb authored and batamar committed Aug 30, 2019
1 parent cb74519 commit ed239cc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
20 changes: 11 additions & 9 deletions src/data/resolvers/boardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,25 @@ export const sendNotifications = async ({
});
};

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

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

if (oldStageId !== destinationStageId) {
const stage = await Stages.findOne({ _id: destinationStageId });
const stage = await Stages.getStage(destinationStageId);
const oldStage = await Stages.getStage(oldStageId);

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

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

content = `${type} '${item.name}' to the '${stage.name}'.`;
action = `moved '${item.name}' from ${oldBoard.name}-${oldPipeline.name}-${oldStage.name} to `;

content = `${board.name}-${pipeline.name}-${stage.name}`;
}

return { content, action };
Expand Down
2 changes: 1 addition & 1 deletion src/data/resolvers/mutations/deals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const dealMutations = {
stageId: destinationStageId,
});

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

await sendNotifications({
item: deal,
Expand Down
6 changes: 4 additions & 2 deletions src/data/resolvers/mutations/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ const taskMutations = {
{ _id, destinationStageId }: { _id: string; destinationStageId: string },
{ user }: IContext,
) {
const task = await Tasks.updateTask(_id, {
const task = await Tasks.getTask(_id);

await Tasks.updateTask(_id, {
modifiedAt: new Date(),
modifiedBy: user._id,
stageId: destinationStageId,
});

const { content, action } = await itemsChange(Tasks, task, 'task', destinationStageId);
const { content, action } = await itemsChange(task, 'task', destinationStageId);

await sendNotifications({
item: task,
Expand Down
6 changes: 4 additions & 2 deletions src/data/resolvers/mutations/tickets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ const ticketMutations = {
{ _id, destinationStageId }: { _id: string; destinationStageId: string },
{ user }: IContext,
) {
const ticket = await Tickets.updateTicket(_id, {
const ticket = await Tickets.getTicket(_id);

await Tickets.updateTicket(_id, {
modifiedAt: new Date(),
modifiedBy: user._id,
stageId: destinationStageId,
});

const { content, action } = await itemsChange(Tickets, ticket, 'ticket', destinationStageId);
const { content, action } = await itemsChange(ticket, 'ticket', destinationStageId);

await sendNotifications({
item: ticket,
Expand Down
14 changes: 14 additions & 0 deletions src/db/models/Boards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,27 @@ const createOrUpdatePipelineStages = async (stages: IPipelineStage[], pipelineId
};

export interface IBoardModel extends Model<IBoardDocument> {
getBoard(_id: string): Promise<IBoardDocument>;
createBoard(doc: IBoard): Promise<IBoardDocument>;
updateBoard(_id: string, doc: IBoard): Promise<IBoardDocument>;
removeBoard(_id: string): void;
}

export const loadBoardClass = () => {
class Board {
/*
* Get a Board
*/
public static async getBoard(_id: string) {
const board = await Boards.findOne({ _id });

if (!board) {
throw new Error('Board not found');
}

return board;
}

/**
* Create a board
*/
Expand Down

0 comments on commit ed239cc

Please sign in to comment.