@@ -17,11 +17,9 @@ const { RESIDENT, STAFF } = require('@condo/domains/user/constants/common')
1717const CREATE_RESIDENT_VISIBLE_COMMENT_BY_STAFF_TYPE = 'CREATE_RESIDENT_VISIBLE_COMMENT_BY_STAFF'
1818const CREATE_RESIDENT_COMMENT_BY_RESIDENT_TYPE = 'CREATE_RESIDENT_COMMENT_BY_RESIDENT'
1919
20- const detectTicketCommentEventTypes = async ( { operation, updatedItem , ticket } ) => {
20+ const detectTicketCommentEventTypes = async ( { operation, createdById , commentType , ticket } ) => {
2121 const isCreateOperation = operation === 'create'
22- const createdById = get ( updatedItem , 'createdBy' )
2322 const canReadByResident = get ( ticket , 'canReadByResident' )
24- const commentType = get ( updatedItem , 'type' )
2523 const isResidentComment = commentType === RESIDENT_COMMENT_TYPE
2624 const isCreateResidentCommentOperation = isCreateOperation && isResidentComment
2725
@@ -41,11 +39,11 @@ const detectTicketCommentEventTypes = async ({ operation, updatedItem, ticket })
4139/**
4240 * Sends notifications after ticket comment created
4341 */
44- const sendTicketCommentNotifications = async ( { operation, updatedItem } ) => {
42+ const sendTicketCommentNotifications = async ( { operation, ticketId , createdById , commentId , commentType , sender } ) => {
4543 const { keystone : context } = await getSchemaCtx ( 'TicketComment' )
4644
47- const ticket = await Ticket . getOne ( context , { id : updatedItem . ticket } )
48- const eventTypes = await detectTicketCommentEventTypes ( { operation, updatedItem , ticket } )
45+ const ticket = await Ticket . getOne ( context , { id : ticketId } )
46+ const eventTypes = await detectTicketCommentEventTypes ( { operation, createdById , commentType , ticket } )
4947 const clientId = get ( ticket , 'client.id' )
5048 const organizationId = get ( ticket , 'organization.id' )
5149 const propertyId = get ( ticket , 'property.id' )
@@ -82,12 +80,13 @@ const sendTicketCommentNotifications = async ({ operation, updatedItem }) => {
8280 ticketId : ticket . id ,
8381 ticketNumber : ticket . number ,
8482 userId : clientId ,
85- commentId : updatedItem . id ,
83+ commentId,
8684 url : `${ conf . SERVER_URL } /ticket/${ ticket . id } ` ,
8785 residentId : get ( resident , 'id' , null ) ,
86+ organizationId : organization . id ,
8887 } ,
8988 } ,
90- sender : updatedItem . sender ,
89+ sender,
9190 organization : { id : organization . id } ,
9291 } )
9392 }
@@ -108,12 +107,13 @@ const sendTicketCommentNotifications = async ({ operation, updatedItem }) => {
108107 ticketId : ticket . id ,
109108 ticketNumber : ticket . number ,
110109 userId : userId ,
111- commentId : updatedItem . id ,
110+ commentId,
112111 url : `${ conf . SERVER_URL } /ticket/${ ticket . id } ` ,
113112 residentId : get ( resident , 'id' , null ) ,
113+ organizationId : organization . id ,
114114 } ,
115115 } ,
116- sender : updatedItem . sender ,
116+ sender,
117117 organization : { id : organization . id } ,
118118 } )
119119 }
0 commit comments