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

Commit

Permalink
fix(deal/ticket/task): copy customer, companies when copy
Browse files Browse the repository at this point in the history
close #626
  • Loading branch information
Buyantogtokh authored and batamar committed Nov 19, 2019
1 parent 009ff18 commit 50969f0
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"graphql": "^14.0.2",
"graphql-redis-subscriptions": "^1.4.0",
"graphql-tools": "^4.0.3",
"handlebars": "^4.5.1",
"handlebars": "^4.5.2",
"ioredis": "^3.2.2",
"jsonwebtoken": "^8.1.0",
"meteor-random": "^0.0.3",
Expand Down
32 changes: 31 additions & 1 deletion src/data/resolvers/boardUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Boards, Pipelines, Stages } from '../../db/models';
import { Boards, Conformities, Pipelines, Stages } from '../../db/models';
import { NOTIFICATION_TYPES } from '../../db/models/definitions/constants';
import { IDealDocument } from '../../db/models/definitions/deals';
import { IUserDocument } from '../../db/models/definitions/users';
Expand Down Expand Up @@ -217,3 +217,33 @@ export const checkPermission = async (type: string, user: IUserDocument, mutatio

return;
};

export const createConformity = async ({
companyIds = [],
customerIds = [],
mainType,
mainTypeId,
}: {
companyIds?: string[];
customerIds?: string[];
mainType: string;
mainTypeId: string;
}) => {
for (const companyId of companyIds) {
await Conformities.addConformity({
mainType,
mainTypeId,
relType: 'company',
relTypeId: companyId,
});
}

for (const customerId of customerIds) {
await Conformities.addConformity({
mainType,
mainTypeId,
relType: 'customer',
relTypeId: customerId,
});
}
};
9 changes: 8 additions & 1 deletion src/data/resolvers/mutations/deals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IDeal } from '../../../db/models/definitions/deals';
import { checkPermission } from '../../permissions/wrappers';
import { IContext } from '../../types';
import { putCreateLog, putDeleteLog, putUpdateLog } from '../../utils';
import { IBoardNotificationParams, itemsChange, sendNotifications } from '../boardUtils';
import { createConformity, IBoardNotificationParams, itemsChange, sendNotifications } from '../boardUtils';
import { checkUserIds } from './notifications';

interface IDealsEdit extends IDeal {
Expand All @@ -26,6 +26,13 @@ const dealMutations = {
userId: user._id,
});

await createConformity({
mainType: 'deal',
mainTypeId: deal._id,
customerIds: doc.customerIds,
companyIds: doc.companyIds,
});

await sendNotifications({
item: deal,
user,
Expand Down
9 changes: 8 additions & 1 deletion src/data/resolvers/mutations/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NOTIFICATION_TYPES } from '../../../db/models/definitions/constants';
import { checkPermission } from '../../permissions/wrappers';
import { IContext } from '../../types';
import { putCreateLog } from '../../utils';
import { IBoardNotificationParams, itemsChange, sendNotifications } from '../boardUtils';
import { createConformity, IBoardNotificationParams, itemsChange, sendNotifications } from '../boardUtils';
import { checkUserIds } from './notifications';

interface ITasksEdit extends ITask {
Expand All @@ -24,6 +24,13 @@ const taskMutations = {
userId: user._id,
});

await createConformity({
mainType: 'task',
mainTypeId: task._id,
companyIds: doc.companyIds,
customerIds: doc.customerIds,
});

await sendNotifications({
item: task,
user,
Expand Down
9 changes: 8 additions & 1 deletion src/data/resolvers/mutations/tickets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ITicket } from '../../../db/models/definitions/tickets';
import { checkPermission } from '../../permissions/wrappers';
import { IContext } from '../../types';
import { putCreateLog } from '../../utils';
import { IBoardNotificationParams, itemsChange, sendNotifications } from '../boardUtils';
import { createConformity, IBoardNotificationParams, itemsChange, sendNotifications } from '../boardUtils';
import { checkUserIds } from './notifications';

interface ITicketsEdit extends ITicket {
Expand All @@ -25,6 +25,13 @@ const ticketMutations = {
userId: user._id,
});

await createConformity({
mainType: 'ticket',
mainTypeId: ticket._id,
customerIds: doc.customerIds,
companyIds: doc.companyIds,
});

await sendNotifications({
item: ticket,
user,
Expand Down
2 changes: 1 addition & 1 deletion src/data/schema/deal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const queries = `
`;

export const mutations = `
dealsAdd(name: String!, ${commonMutationParams}): Deal
dealsAdd(name: String!, companyIds: [String], customerIds: [String], ${commonMutationParams}): Deal
dealsEdit(_id: String!, name: String, ${commonMutationParams}): Deal
dealsChange( _id: String!, destinationStageId: String): Deal
dealsUpdateOrder(stageId: String!, orders: [OrderItem]): [Deal]
Expand Down
2 changes: 1 addition & 1 deletion src/data/schema/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const commonParams = `
`;

export const mutations = `
tasksAdd(name: String!, ${commonParams}): Task
tasksAdd(name: String!, customerIds: [String], companyIds: [String], ${commonParams}): Task
tasksEdit(_id: String!, name: String, ${commonParams}): Task
tasksChange( _id: String!, destinationStageId: String): Task
tasksUpdateOrder(stageId: String!, orders: [OrderItem]): [Task]
Expand Down
2 changes: 1 addition & 1 deletion src/data/schema/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const commonParams = `
`;

export const mutations = `
ticketsAdd(name: String!, ${commonParams}): Ticket
ticketsAdd(name: String!, companyIds: [String], customerIds: [String], ${commonParams}): Ticket
ticketsEdit(_id: String!, name: String, ${commonParams}): Ticket
ticketsChange( _id: String!, destinationStageId: String): Ticket
ticketsUpdateOrder(stageId: String!, orders: [OrderItem]): [Ticket]
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4401,10 +4401,10 @@ handlebars@^4.1.0:
optionalDependencies:
uglify-js "^3.1.4"

handlebars@^4.5.1:
version "4.5.1"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.5.1.tgz#8a01c382c180272260d07f2d1aa3ae745715c7ba"
integrity sha512-C29UoFzHe9yM61lOsIlCE5/mQVGrnIOrOq7maQl76L7tYPCgC1og0Ajt6uWnX4ZTxBPnjw+CUvawphwCfJgUnA==
handlebars@^4.5.2:
version "4.5.2"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.5.2.tgz#5a4eb92ab5962ca3415ac188c86dc7f784f76a0f"
integrity sha512-29Zxv/cynYB7mkT1rVWQnV7mGX6v7H/miQ6dbEpYTKq5eJBN7PsRB+ViYJlcT6JINTSu4dVB9kOqEun78h6Exg==
dependencies:
neo-async "^2.6.0"
optimist "^0.6.1"
Expand Down

0 comments on commit 50969f0

Please sign in to comment.