From 9b8ce6850113075e8bbe615bd95d7e9947d8d7fd Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 11 Aug 2023 18:24:58 +0500 Subject: [PATCH] fix(condo): DOMA-6834 added organizationId to ticket comment pushes --- .../notification/constants/constants.js | 1 + .../tasks/sendTicketCommentNotifications.js | 20 +++++++++---------- apps/condo/domains/ticket/utils/handlers.js | 9 ++++++++- apps/condo/schema.graphql | 4 ++++ apps/condo/schema.ts | 4 ++++ 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/apps/condo/domains/notification/constants/constants.js b/apps/condo/domains/notification/constants/constants.js index 743dccc7839..e8410e24bf2 100644 --- a/apps/condo/domains/notification/constants/constants.js +++ b/apps/condo/domains/notification/constants/constants.js @@ -251,6 +251,7 @@ const MESSAGE_META = { commentId: { defaultValue: '', required: true }, url: { defaultValue: '', required: true }, residentId: { defaultValue: '', required: true }, + organizationId: { defaultValue: '', required: true }, }, }, [METER_VERIFICATION_DATE_REMINDER_TYPE]: { diff --git a/apps/condo/domains/ticket/tasks/sendTicketCommentNotifications.js b/apps/condo/domains/ticket/tasks/sendTicketCommentNotifications.js index fabad1cc2fe..896192d7da8 100644 --- a/apps/condo/domains/ticket/tasks/sendTicketCommentNotifications.js +++ b/apps/condo/domains/ticket/tasks/sendTicketCommentNotifications.js @@ -17,11 +17,9 @@ const { RESIDENT, STAFF } = require('@condo/domains/user/constants/common') const CREATE_RESIDENT_VISIBLE_COMMENT_BY_STAFF_TYPE = 'CREATE_RESIDENT_VISIBLE_COMMENT_BY_STAFF' const CREATE_RESIDENT_COMMENT_BY_RESIDENT_TYPE = 'CREATE_RESIDENT_COMMENT_BY_RESIDENT' -const detectTicketCommentEventTypes = async ({ operation, updatedItem, ticket }) => { +const detectTicketCommentEventTypes = async ({ operation, createdById, commentType, ticket }) => { const isCreateOperation = operation === 'create' - const createdById = get(updatedItem, 'createdBy') const canReadByResident = get(ticket, 'canReadByResident') - const commentType = get(updatedItem, 'type') const isResidentComment = commentType === RESIDENT_COMMENT_TYPE const isCreateResidentCommentOperation = isCreateOperation && isResidentComment @@ -41,11 +39,11 @@ const detectTicketCommentEventTypes = async ({ operation, updatedItem, ticket }) /** * Sends notifications after ticket comment created */ -const sendTicketCommentNotifications = async ({ operation, updatedItem }) => { +const sendTicketCommentNotifications = async ({ operation, ticketId, createdById, commentId, commentType, sender }) => { const { keystone: context } = await getSchemaCtx('TicketComment') - const ticket = await Ticket.getOne(context, { id: updatedItem.ticket }) - const eventTypes = await detectTicketCommentEventTypes({ operation, updatedItem, ticket }) + const ticket = await Ticket.getOne(context, { id: ticketId }) + const eventTypes = await detectTicketCommentEventTypes({ operation, createdById, commentType, ticket }) const clientId = get(ticket, 'client.id') const organizationId = get(ticket, 'organization.id') const propertyId = get(ticket, 'property.id') @@ -82,12 +80,13 @@ const sendTicketCommentNotifications = async ({ operation, updatedItem }) => { ticketId: ticket.id, ticketNumber: ticket.number, userId: clientId, - commentId: updatedItem.id, + commentId, url: `${conf.SERVER_URL}/ticket/${ticket.id}`, residentId: get(resident, 'id', null), + organizationId: organization.id, }, }, - sender: updatedItem.sender, + sender, organization: { id: organization.id }, }) } @@ -108,12 +107,13 @@ const sendTicketCommentNotifications = async ({ operation, updatedItem }) => { ticketId: ticket.id, ticketNumber: ticket.number, userId: userId, - commentId: updatedItem.id, + commentId, url: `${conf.SERVER_URL}/ticket/${ticket.id}`, residentId: get(resident, 'id', null), + organizationId: organization.id, }, }, - sender: updatedItem.sender, + sender, organization: { id: organization.id }, }) } diff --git a/apps/condo/domains/ticket/utils/handlers.js b/apps/condo/domains/ticket/utils/handlers.js index 573dd79feaa..fbbfd979c69 100644 --- a/apps/condo/domains/ticket/utils/handlers.js +++ b/apps/condo/domains/ticket/utils/handlers.js @@ -267,7 +267,14 @@ const sendTicketNotifications = async (requestData) => { const sendTicketCommentNotifications = async (requestData) => { const { operation, updatedItem } = requestData - await sendTicketCommentNotificationsTask.delay({ operation, updatedItem }) + await sendTicketCommentNotificationsTask.delay({ + operation, + ticketId: get(updatedItem, 'ticket'), + createdById: get(updatedItem, 'createdBy'), + commentId: updatedItem.id, + commentType: get(updatedItem, 'type'), + sender: updatedItem.sender, + }) } const createOrUpdateTicketCommentsTime = async (context, updatedItem, userType) => { diff --git a/apps/condo/schema.graphql b/apps/condo/schema.graphql index 763a9cfc67b..6e6bd3c6914 100644 --- a/apps/condo/schema.graphql +++ b/apps/condo/schema.graphql @@ -73710,6 +73710,10 @@ type Mutation { "residentId": { "defaultValue": "", "required": true + }, + "organizationId": { + "defaultValue": "", + "required": true } } }, diff --git a/apps/condo/schema.ts b/apps/condo/schema.ts index 841aa422204..c9c86e11128 100644 --- a/apps/condo/schema.ts +++ b/apps/condo/schema.ts @@ -34433,6 +34433,10 @@ export type Mutation = { * "residentId": { * "defaultValue": "", * "required": true + * }, + * "organizationId": { + * "defaultValue": "", + * "required": true * } * } * },