diff --git a/package.json b/package.json index 99ac489de..9587b452f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/data/resolvers/boardUtils.ts b/src/data/resolvers/boardUtils.ts index 7211b400d..07db89c4a 100644 --- a/src/data/resolvers/boardUtils.ts +++ b/src/data/resolvers/boardUtils.ts @@ -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'; @@ -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, + }); + } +}; diff --git a/src/data/resolvers/mutations/deals.ts b/src/data/resolvers/mutations/deals.ts index a175928f2..3f129e5a4 100644 --- a/src/data/resolvers/mutations/deals.ts +++ b/src/data/resolvers/mutations/deals.ts @@ -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 { @@ -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, diff --git a/src/data/resolvers/mutations/tasks.ts b/src/data/resolvers/mutations/tasks.ts index 2c3f68865..3ccffba98 100644 --- a/src/data/resolvers/mutations/tasks.ts +++ b/src/data/resolvers/mutations/tasks.ts @@ -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 { @@ -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, diff --git a/src/data/resolvers/mutations/tickets.ts b/src/data/resolvers/mutations/tickets.ts index 2dc4bba28..8c7906772 100644 --- a/src/data/resolvers/mutations/tickets.ts +++ b/src/data/resolvers/mutations/tickets.ts @@ -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 { @@ -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, diff --git a/src/data/schema/deal.ts b/src/data/schema/deal.ts index f5524e7a1..625ddd1b6 100644 --- a/src/data/schema/deal.ts +++ b/src/data/schema/deal.ts @@ -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] diff --git a/src/data/schema/task.ts b/src/data/schema/task.ts index 4803f4d3e..4405ced34 100644 --- a/src/data/schema/task.ts +++ b/src/data/schema/task.ts @@ -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] diff --git a/src/data/schema/ticket.ts b/src/data/schema/ticket.ts index 077129dac..9ccc33eb9 100644 --- a/src/data/schema/ticket.ts +++ b/src/data/schema/ticket.ts @@ -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] diff --git a/yarn.lock b/yarn.lock index 8f40140e9..b879f154f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"