diff --git a/packages/plugin-meetings-api/src/graphql/resolvers/mutations/meeting.ts b/packages/plugin-meetings-api/src/graphql/resolvers/mutations/meeting.ts index 1341931eb4..19209b280e 100644 --- a/packages/plugin-meetings-api/src/graphql/resolvers/mutations/meeting.ts +++ b/packages/plugin-meetings-api/src/graphql/resolvers/mutations/meeting.ts @@ -1,11 +1,29 @@ -import { IContext } from '../../../messageBroker'; +import { IContext, sendCommonMessage } from '../../../messageBroker'; const meetingMutations = { // /** // * Creates a new meetings // */ - async meetingAdd(_root, doc, { models, user }: IContext) { - const { participantIds } = doc; + async meetingAdd(_root, doc, { models, subdomain, user }: IContext) { + const { participantIds, companyId, title } = doc; + + if (!title && companyId) { + const company = await sendCommonMessage({ + subdomain, + serviceName: 'contacts', + action: 'companies.findOne', + data: { + _id: companyId + }, + isRPC: true + }); + + if (company) { + doc.title = company.primaryName; + } else { + throw new Error('Company not found'); + } + } const allParticipantIds = participantIds && participantIds.includes(user._id) ? participantIds @@ -16,7 +34,25 @@ const meetingMutations = { // /** // * Edits a meetings // */ - async meetingEdit(_root, doc, { models, user }: IContext) { + async meetingEdit(_root, doc, { models, subdomain, user }: IContext) { + const { companyId, title } = doc; + if (!title && companyId) { + const company = await sendCommonMessage({ + subdomain, + serviceName: 'contacts', + action: 'companies.findOne', + data: { + _id: companyId + }, + isRPC: true + }); + + if (company) { + doc.title = company.primaryName; + } else { + throw new Error('Company not found'); + } + } return models.Meetings.updateMeeting(doc, user); }, /**