Skip to content

Commit

Permalink
fix(condo): DOMA-5956 offline status change history (#3233)
Browse files Browse the repository at this point in the history
* feat(condo): DOMA-6681 added TicketMultipleUpdateService

* feat(condo): DOMA-5956 added actualCreationDate to TicketChange

* feat(condo): DOMA-5956 display ticket status change with actualCreationDate

* feat(condo): DOMA-6762 discard not valid status transitions in ticketMultipleUpdate

* fix(condo): DOMA-5956 set actualCreationDate to all TicketChanges, sort ticket changes by actualCreationDate in ticket card
  • Loading branch information
nomerdvadcatpyat authored Aug 10, 2023
1 parent 0236b4c commit 14af11b
Show file tree
Hide file tree
Showing 17 changed files with 875 additions and 376 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useLayoutContext } from '@condo/domains/common/components/LayoutContext

export type BaseChangesType = {
createdAt?: Maybe<string>
actualCreationDate?: Maybe<string>
id: string
}

Expand All @@ -35,8 +36,9 @@ export const HistoricalChange = <ChangesType extends BaseChangesType> (props: Hi
const changedFieldMessages = useChangedFieldMessagesOf(changesValue)
const { breakpoints } = useLayoutContext()

const formattedDate = useMemo(() => dayjs(changesValue.createdAt).format('DD.MM.YYYY'), [changesValue.createdAt])
const formattedTime = useMemo(() => dayjs(changesValue.createdAt).format('HH:mm'), [changesValue.createdAt])
const dateToShow = changesValue.actualCreationDate || changesValue.createdAt
const formattedDate = useMemo(() => dayjs(dateToShow).format('DD.MM.YYYY'), [dateToShow])
const formattedTime = useMemo(() => dayjs(dateToShow).format('HH:mm'), [dateToShow])

return (
<Row gutter={HISTORICAL_CHANGE_GUTTER}>
Expand Down
32 changes: 32 additions & 0 deletions apps/condo/domains/ticket/access/TicketMultipleUpdateService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Generated by `createservice ticket.TicketMultipleUpdateService --type mutations`
*/
const get = require('lodash/get')

const { throwAuthenticationError } = require('@open-condo/keystone/apolloErrorFormatter')
const { getById } = require('@open-condo/keystone/schema')

const { checkPermissionInUserOrganizationOrRelatedOrganization } = require('@condo/domains/organization/utils/accessSchema')

async function canTicketMultipleUpdate (data) {
const { authentication: { item: user } } = data

if (!user) return throwAuthenticationError()
if (user.deletedAt) return false
if (user.isAdmin || user.isSupport) return true

const ticketId = get(data, 'args.data.id')
if (!ticketId) return false

const ticket = await getById('Ticket', ticketId)

return await checkPermissionInUserOrganizationOrRelatedOrganization(user.id, ticket.organization, 'canManageTickets')
}

/*
Rules are logical functions that used for list access, and may return a boolean (meaning
all or no items are available) or a set of filters that limit the available items.
*/
module.exports = {
canTicketMultipleUpdate,
}
12 changes: 9 additions & 3 deletions apps/condo/domains/ticket/gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const TICKET_CHANGE_DATA_FIELDS = [
'qualityControlAdditionalOptionsFrom',
'qualityControlAdditionalOptionsTo',
]
const TICKET_CHANGE_FIELDS = `{ ticket { id property { address } organization { id country } } ${COMMON_CHANGE_HISTORY_FIELDS} ${TICKET_CHANGE_DATA_FIELDS.join(' ')} }`
const TICKET_CHANGE_FIELDS = `{ ticket { id property { address } organization { id country } } actualCreationDate ${COMMON_CHANGE_HISTORY_FIELDS} ${TICKET_CHANGE_DATA_FIELDS.join(' ')} }`
const TicketChange = generateGqlQueries('TicketChange', TICKET_CHANGE_FIELDS)
const TICKET_FILE_FIELDS = `{ id file { id originalFilename publicUrl mimetype } organization { id } ticket { id } ${COMMON_FIELDS} }`
const TicketFile = generateGqlQueries('TicketFile', TICKET_FILE_FIELDS)
Expand Down Expand Up @@ -163,7 +163,6 @@ const TICKET_FILTER_FIELDS = '{ type completedAt lastCommentAt organization numb
const TICKET_FILTER_TEMPLATE_FIELDS = `{ name employee { id } fields ${TICKET_FILTER_FIELDS} ${COMMON_FIELDS} }`
const TicketFilterTemplate = generateGqlQueries('TicketFilterTemplate', TICKET_FILTER_TEMPLATE_FIELDS)


const PREDICT_TICKET_CLASSIFICATION_QUERY = gql`
query predictTicketClassification ($data: PredictTicketClassificationInput!) {
obj: predictTicketClassification(data: $data) { id place { id name } category { id name } }
Expand Down Expand Up @@ -243,6 +242,12 @@ const CallRecord = generateGqlQueries('CallRecord', CALL_RECORD_FIELDS)
const CALL_RECORD_FRAGMENT_FIELDS = `{ ticket { id number clientName property { ${TICKET_PROPERTY_FIELDS} } } callRecord ${CALL_RECORD_FIELDS} organization { id name } startedAt ${COMMON_FIELDS} }`
const CallRecordFragment = generateGqlQueries('CallRecordFragment', CALL_RECORD_FRAGMENT_FIELDS)

const TICKET_MULTIPLE_UPDATE_MUTATION = gql`
mutation ticketMultipleUpdate ($data: TicketMultipleUpdateInput!) {
result: ticketMultipleUpdate(data: $data) ${TICKET_FIELDS}
}
`

/* AUTOGENERATE MARKER <CONST> */
module.exports = {
Ticket,
Expand Down Expand Up @@ -279,5 +284,6 @@ module.exports = {
IncidentExportTask,
CallRecord,
CallRecordFragment,
/* AUTOGENERATE MARKER <EXPORTS> */
TICKET_MULTIPLE_UPDATE_MUTATION,
/* AUTOGENERATE MARKER <EXPORTS> */
}
4 changes: 2 additions & 2 deletions apps/condo/domains/ticket/schema/Ticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,8 @@ const Ticket = new GQLListSchema('Ticket', {
*/
const { property, unitName, sectionName, sectionType, unitType, floorName, classifier } = Ticket.schema.fields

const [requestData] = args

await storeChangesIfUpdated(
buildSetOfFieldsToTrackFrom(Ticket.schema, { except: OMIT_TICKET_CHANGE_TRACKABLE_FIELDS }),
createTicketChange,
Expand All @@ -895,8 +897,6 @@ const Ticket = new GQLListSchema('Ticket', {
]
)(...args)

const [requestData] = args

await manageAssigneeScope(...args)

/* NOTE: this sends different kinds of notifications on ticket create/update */
Expand Down
15 changes: 14 additions & 1 deletion apps/condo/domains/ticket/schema/TicketChange.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Generated by `createschema ticket.TicketChange 'ticket:Relationship:Ticket:CASCADE;'`
*/

const { Relationship, Virtual } = require('@keystonejs/fields')
const { Relationship, Virtual, DateTimeUtc } = require('@keystonejs/fields')
const get = require('lodash/get')

const conf = require('@open-condo/config')
Expand Down Expand Up @@ -56,6 +56,10 @@ const TicketChange = new GQLListSchema('TicketChange', {
relatedManyToManyResolvers,
keysOfLocalizedTextFields,
),
actualCreationDate: {
schemaDoc: 'Actual creation ticket change date, for case when ticket updated from offline',
type: DateTimeUtc,
},
changedByRole: {
schemaDoc: 'Type of user who changed the ticket, can be employee role from same organization or related, resident or deleted employee',
type: Virtual,
Expand Down Expand Up @@ -110,6 +114,15 @@ const TicketChange = new GQLListSchema('TicketChange', {
},
},
},
hooks: {
resolveInput: ({ resolvedData }) => {
if (!resolvedData.actualCreationDate) {
resolvedData.actualCreationDate = new Date().toISOString()
}

return resolvedData
},
},
plugins: [uuided(), versioned(), tracked(), dvAndSender()],
access: {
read: access.canReadTicketChanges,
Expand Down
Loading

0 comments on commit 14af11b

Please sign in to comment.