Skip to content

Commit

Permalink
Address code QA feedback, finished 522 outstanding functionality on d…
Browse files Browse the repository at this point in the history
…isplay of 'from' in conversation threads.
  • Loading branch information
jgstorey committed Nov 17, 2023
1 parent fb91d54 commit 54f7416
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 67 deletions.
24 changes: 12 additions & 12 deletions backend/src/components/message.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'
const { getOperation, patchOperationWithObjectId, postOperation } = require('./utils')
const { MappableObjectForFront, MappableObjectForBack } = require('../util/mapping/MappableObject')
const { AssistanceRequestMappings, AssistanceRequestFacilityMappings, AssistanceRequestMessagesMappings } = require('../util/mapping/Mappings')
const { AssistanceRequestMappings, AssistanceRequestFacilityMappings, AssistanceRequestConversationMappings } = require('../util/mapping/Mappings')
const HttpStatus = require('http-status-codes')
const { ASSISTANCE_REQUEST_STATUS_CODES } = require('../util/constants')
const log = require('./logger')
Expand Down Expand Up @@ -72,11 +72,11 @@ async function createAssistanceRequest(req, res) {

async function replyToAssistanceRequest(req, res) {
try {
let payload = `{
const payload = `{
"ofm_message": "${req.body?.message}",
"[email protected]": "/ofm_assistance_requests(${req.body?.assistanceRequestId})"
}`
let response = await postOperation('ofm_conversations', payload)
const response = await postOperation('ofm_conversations', payload)
return res.status(HttpStatus.OK).json(response)
} catch (e) {
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status)
Expand All @@ -85,10 +85,10 @@ async function replyToAssistanceRequest(req, res) {

async function getAssistanceRequests(req, res) {
try {
log.info('getAssistanceRequests: ', req.params.contactId)
log.debug('getAssistanceRequests: ', req.params.contactId)
let assistanceRequests = []
let operation = `ofm_assistance_requests?$select=modifiedon,ofm_assistance_requestid,ofm_last_opened_time,ofm_name,_ofm_request_category_value,ofm_subject,statecode,statuscode,ofm_is_read&$expand=ofm_facility_request_request($select=_ofm_facility_value),ofm_conversation_request($select=modifiedon)&$filter=(_ofm_contact_value eq ${req.params.contactId}) and (ofm_facility_request_request/any(o1:(o1/ofm_facility_requestid ne null))) and (ofm_conversation_request/any(o2:(o2/ofm_conversationid ne null)))`
log.info('operation: ', operation)
log.debug('operation: ', operation)
let response = await getOperation(operation)
response?.value?.forEach((item) => assistanceRequests.push(mapAssistanceRequestObjectForFront(item)))
return res.status(HttpStatus.OK).json(assistanceRequests)
Expand All @@ -100,7 +100,7 @@ async function getAssistanceRequests(req, res) {
async function getAssistanceRequest(req, res) {
try {
let operation = `ofm_assistance_requests(${req.params.assistanceRequestId})?$select=modifiedon,ofm_assistance_requestid,ofm_last_opened_time,ofm_name,_ofm_request_category_value,ofm_subject,statecode,statuscode,ofm_is_read&$expand=ofm_facility_request_request($select=_ofm_facility_value),ofm_conversation_request($select=modifiedon)`
log.info('operation: ', operation)
log.debug('operation: ', operation)
let response = await getOperation(operation)
return res.status(HttpStatus.OK).json(mapAssistanceRequestObjectForFront(response))
} catch (e) {
Expand All @@ -118,16 +118,16 @@ async function updateAssistanceRequest(req, res) {
}
}

async function getAssistanceRequestMessages(req, res) {
async function getAssistanceRequestConversation(req, res) {
try {
let operation = `ofm_conversations?$select=ofm_conversationid,ofm_name,createdon,ofm_message,_ofm_request_value,_ownerid_value,statecode,statuscode&$expand=createdby($select=firstname,lastname)&$filter=(_ofm_request_value eq ${req.params.assistanceRequestId})&$orderby=createdon desc`
log.info('operation: ', operation)
let operation = `ofm_conversations?$select=ofm_conversationid,ofm_name,createdon,ofm_message,ofm_source_system,_ofm_request_value,_ownerid_value,statecode,statuscode&$expand=createdby($select=firstname,lastname)&$filter=(_ofm_request_value eq ${req.params.assistanceRequestId})&$orderby=createdon desc`
log.debug('operation: ', operation)
let response = await getOperation(operation)
const messages = []

for (const item of response.value) {
let assistanceRequestMessage = new MappableObjectForFront(item, AssistanceRequestMessagesMappings).toJSON()
messages.push(assistanceRequestMessage)
let assistanceRequestConversation = new MappableObjectForFront(item, AssistanceRequestConversationMappings).toJSON()
messages.push(assistanceRequestConversation)
}
return res.status(HttpStatus.OK).json(messages)
} catch (e) {
Expand All @@ -140,6 +140,6 @@ module.exports = {
getAssistanceRequests,
getAssistanceRequest,
updateAssistanceRequest,
getAssistanceRequestMessages,
getAssistanceRequestConversation,
replyToAssistanceRequest,
}
4 changes: 2 additions & 2 deletions backend/src/routes/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const passport = require('passport')
const router = express.Router()
const auth = require('../components/auth')
const isValidBackendToken = auth.isValidBackendToken()
const { updateAssistanceRequest, createAssistanceRequest, getAssistanceRequests, getAssistanceRequest, getAssistanceRequestMessages, replyToAssistanceRequest } = require('../components/message')
const { updateAssistanceRequest, createAssistanceRequest, getAssistanceRequests, getAssistanceRequest, getAssistanceRequestConversation, replyToAssistanceRequest } = require('../components/message')
const { param, validationResult, checkSchema } = require('express-validator')

module.exports = router
Expand Down Expand Up @@ -100,7 +100,7 @@ router.get(
[param('assistanceRequestId', 'URL param: [assistanceRequestId] is required').not().isEmpty()],
(req, res) => {
validationResult(req).throw()
return getAssistanceRequestMessages(req, res)
return getAssistanceRequestConversation(req, res)
},
)

Expand Down
5 changes: 3 additions & 2 deletions backend/src/util/mapping/Mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ const AssistanceRequestMappings = [
{ back: 'ofm_is_read', front: 'isRead' },
]

const AssistanceRequestMessagesMappings = [
const AssistanceRequestConversationMappings = [
{ back: 'ofm_conversationid', front: 'conversationId' },
{ back: 'ofm_name', front: 'subject' },
{ back: '_ownerid_value', front: 'from' },
{ back: 'createdon', front: 'sentDate' },
{ back: 'ofm_message', front: 'message' },
{ back: 'ofm_source_system', front: 'ofmSourceSystem' },
{ back: '_ofm_request_value', front: 'requestValue' },
{ back: 'statuscode', front: 'statusCode' },
]
Expand All @@ -85,5 +86,5 @@ module.exports = {
RequestCategoryMappings,
AssistanceRequestMappings,
AssistanceRequestFacilityMappings,
AssistanceRequestMessagesMappings
AssistanceRequestConversationMappings,
}
29 changes: 17 additions & 12 deletions frontend/src/components/messages/NewRequestDialog.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<v-container>
<AppDialog v-model="isDisplayed" title="New request" :isLoading="isLoading" persistent max-width="70%" @close="closeNewRequestDialog">
<AppDialog v-model="isDisplayed" title="New request" :isLoading="isLoading" persistent max-width="70%"
@close="closeNewRequestDialog">
<template #content>
<v-form ref="newRequestForm" v-model="newRequestModel.isFormComplete" class="px-12 mx-8">
<v-row no-gutters class="mt-4">
Expand All @@ -23,15 +24,17 @@
<strong>Subject:</strong>
</v-col>
<v-col class="v-col-12 v-col-md-9 v-col-xl-10">
<v-text-field v-model="newRequestModel.subject" placeholder="Brief summary of request" counter maxlength="100" variant="outlined" :rules="rules.required"></v-text-field>
<v-text-field v-model="newRequestModel.subject" placeholder="Brief summary of request" counter
maxlength="100" variant="outlined" :rules="rules.required"></v-text-field>
</v-col>
</v-row>
<v-row no-gutters class="mt-2">
<v-col class="v-col-12 blue-text pb-0">
<strong>Request description:</strong>
</v-col>
<v-col class="v-col-12">
<v-textarea v-model="newRequestModel.description" placeholder="Detailed description of request" counter maxlength="1000" variant="outlined" :rules="rules.required"></v-textarea>
<v-textarea v-model="newRequestModel.description" placeholder="Detailed description of request" counter
maxlength="1000" variant="outlined" :rules="rules.required"></v-textarea>
</v-col>
</v-row>
<v-row no-gutters class="mt-2">
Expand Down Expand Up @@ -76,19 +79,23 @@
<strong>Business phone:</strong>
</v-col>
<v-col class="v-col-12 v-col-md-9 v-col-xl-10">
<v-text-field v-model="newRequestModel.phone" variant="outlined" :rules="[...rules.required, rules.phone]" />
<v-text-field v-model="newRequestModel.phone" variant="outlined"
:rules="[...rules.required, rules.phone]" />
</v-col>
</v-row>
</v-form>
</template>
<template #button>
<v-row justify="space-around">
<AppButton id="cancel-new-request" :primary="false" size="large" width="200px" @click="closeNewRequestDialog()" :loading="isLoading">Cancel</AppButton>
<AppButton id="submit-new-request" size="large" width="200px" @click="submit()" :loading="isLoading">Submit</AppButton>
<AppButton id="cancel-new-request" :primary="false" size="large" width="200px" @click="closeNewRequestDialog()"
:loading="isLoading">Cancel</AppButton>
<AppButton id="submit-new-request" size="large" width="200px" @click="submit()" :loading="isLoading">Submit
</AppButton>
</v-row>
</template>
</AppDialog>
<NewRequestConfirmationDialog :referenceNumber="referenceNumber" :show="showNewRequestConfirmationDialog" @close="toggleNewRequestConfirmationDialog" />
<NewRequestConfirmationDialog :referenceNumber="referenceNumber" :show="showNewRequestConfirmationDialog"
@close="toggleNewRequestConfirmationDialog" />
</v-container>
</template>

Expand Down Expand Up @@ -187,9 +194,7 @@ export default {
}
</script>
<style scoped>
.blue-text {
<style scoped>.blue-text {
color: #003366;
font-size: 125%;
}
</style>
font-size: 1.25em;
}</style>
2 changes: 1 addition & 1 deletion frontend/src/components/messages/ReplyRequestDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ export default {
<style scoped>
.blue-text {
color: #003366;
font-size: 125%;
font-size: 1.25em;
}
</style>
53 changes: 27 additions & 26 deletions frontend/src/components/messages/RequestConversations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@
</v-row>
<v-row v-if="assistanceRequest">
<v-col cols="12" class="border-right pa-0">
<v-data-table-virtual :headers="headers" :items="assistanceRequestMessages" item-key="messageId"
<v-data-table-virtual :headers="headers" :items="assistanceRequestConversation" item-key="messageId"
class="data-table">
<template #headers>
</template>
<template #item="{ item }">
<v-row class="border-bottom mr-0">
<v-col>
<div><span class="font-weight-bold">From:</span> {{ item.from }}</div>
<div><span class="font-weight-bold">From:</span> {{ deriveFromDisplay(item) }}</div>
<div><span class="font-weight-bold">Sent:</span> {{ format.formatDate(item.sentDate) }}</div>
<div class="pt-1">{{ item.message }}</div>
</v-col>
Expand All @@ -77,11 +77,12 @@

<script>
import { mapState, mapActions } from 'pinia'
import { useAuthStore } from '@/stores/auth'
import { useMessagesStore } from '@/stores/messages'
import ReplyRequestDialog from '@/components/messages/ReplyRequestDialog.vue'
import alertMixin from '@/mixins/alertMixin'
import format from '@/utils/format'
import { ASSISTANCE_REQUEST_REPLY_DISABLED_TEXT, ASSISTANCE_REQUEST_STATUSES } from '@/utils/constants'
import { ASSISTANCE_REQUEST_REPLY_DISABLED_TEXT, ASSISTANCE_REQUEST_STATUS_CODES, OFM_PROGRAM } from '@/utils/constants'
export default {
mixins: [alertMixin],
Expand Down Expand Up @@ -111,28 +112,29 @@ export default {
}
},
computed: {
...mapState(useMessagesStore, ['assistanceRequests', 'assistanceRequestMessages']),
...mapState(useMessagesStore, ['assistanceRequests', 'assistanceRequestConversation']),
...mapState(useAuthStore, ['userInfo']),
isReplyDisabled() {
return this.assistanceRequest &&
(this.assistanceRequest.status !== ASSISTANCE_REQUEST_STATUSES.WITH_PROVIDER &&
this.assistanceRequest.status !== ASSISTANCE_REQUEST_STATUSES.READY_TO_RESOLVE);
(this.assistanceRequest.statusCode !== ASSISTANCE_REQUEST_STATUS_CODES.WITH_PROVIDER &&
this.assistanceRequest.statusCode !== ASSISTANCE_REQUEST_STATUS_CODES.READY_TO_RESOLVE);
}
},
watch: {
// When assistanceRequestId changes, get the messages for the new assistance request.
// When assistanceRequestId changes, get the conversation for the new assistance request.
assistanceRequestId: async function (newVal) {
await this.getAssistanceRequestMessages(this.assistanceRequestId)
await this.getAssistanceRequestConversation(this.assistanceRequestId)
this.assistanceRequest = this.assistanceRequests.find(item => item.assistanceRequestId === newVal)
},
},
methods: {
...mapActions(useMessagesStore, ['getAssistanceRequestMessages']),
...mapActions(useMessagesStore, ['getAssistanceRequestConversation']),
/**
* Sorts the messages by date received based on isSortedDesc.
* Sorts the conversation by date received based on isSortedDesc.
*/
sortMessages() {
this.assistanceRequestMessages.sort((a, b) => {
sortConversation() {
this.assistanceRequestConversation.sort((a, b) => {
if (this.isSortedDesc) {
return (a.dateReceived < b.dateReceived) ? 1 : -1;
} else {
Expand All @@ -142,11 +144,11 @@ export default {
},
/**
* Toggles the sort order of the messages.
* Toggles the sort order of the conversation.
*/
toggleSort() {
this.isSortedDesc = !this.isSortedDesc
this.sortMessages()
this.sortConversation()
},
/**
Expand All @@ -157,13 +159,13 @@ export default {
},
/**
* Called when the reply request dialog emits a reply-success-event. Gets the messages for the
* Called when the reply request dialog emits a reply-success-event. Gets the conversation for the
* assistance request and sorts them.
*/
async replySuccessEvent(isSuccess) {
if (isSuccess) {
await this.getAssistanceRequestMessages(this.assistanceRequestId);
this.sortMessages();
await this.getAssistanceRequestConversation(this.assistanceRequestId);
this.sortConversation();
this.setSuccessAlert('Reply sent successfully');
}
},
Expand All @@ -173,6 +175,13 @@ export default {
*/
getReplyDisabledText() {
return ASSISTANCE_REQUEST_REPLY_DISABLED_TEXT;
},
/**
* Returns the sent by value for the conversation depending on the source system.
*/
deriveFromDisplay(item) {
return (item.ofmSourceSystem) ? this.userInfo?.firstName + ' ' + this.userInfo?.lastName : OFM_PROGRAM
}
}
Expand All @@ -185,16 +194,8 @@ export default {
color: #ffffff !important;
}
th {
padding: 0px 0px 0px 4px !important;
}
td {
padding: 0px 3px 0px 4px !important;
}
.data-table {
height: 635px;
max-height: 635px;
}
.subject-header {
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/stores/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const useMessagesStore = defineStore('messages', {
namespaced: true,
state: () => ({
assistanceRequests: null,
assistanceRequestMessages: null,
assistanceRequestConversation: null,
}),
getters: {
unreadMessageCount: (state) => (state.assistanceRequests ? state.assistanceRequests.filter((message) => !message.isRead).length : 0),
Expand Down Expand Up @@ -67,18 +67,18 @@ export const useMessagesStore = defineStore('messages', {
sortAssistanceRequests(this.assistanceRequests)
}
},
async getAssistanceRequestMessages(assistanceRequestId) {
async getAssistanceRequestConversation(assistanceRequestId) {
try {
let response = await ApiService.apiAxios.get(ApiRoutes.MESSAGES + '/conversations' + '/' + assistanceRequestId)
this.assistanceRequestMessages = response.data
const response = await ApiService.apiAxios.get(ApiRoutes.MESSAGES + '/conversations' + '/' + assistanceRequestId)
this.assistanceRequestConversation = response.data
} catch (error) {
console.log(`Failed to get the list of assistance request messages - ${error}`)
throw error
}
},
async replyToAssistanceRequest(payload) {
try {
let response = await ApiService.apiAxios.post(ApiRoutes.MESSAGES + '/replyToAssistanceRequest', payload)
const response = await ApiService.apiAxios.post(ApiRoutes.MESSAGES + '/replyToAssistanceRequest', payload)
return response?.data
} catch (error) {
console.log(`Failed to create a reply for the Assistance Request - ${error}`)
Expand Down
12 changes: 5 additions & 7 deletions frontend/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ export const PAGE_TITLES = Object.freeze({
MAINTENANCE_REQUEST_EXCEPTION_STREAM: 'Maint Request Exp Stream',
})

export const ASSISTANCE_REQUEST_STATUSES = Object.freeze({
SUBMITTED: 'Submitted',
ASSIGNED: 'Assigned',
WITH_PROVIDER: 'With Provider',
READY_TO_RESOLVE: 'Ready to resolve',
CLOSED_COMPLETE: 'Closed Complete',
CLOSED_CANCELLED: 'Closed Cancelled',
export const ASSISTANCE_REQUEST_STATUS_CODES = Object.freeze({
WITH_PROVIDER: 3,
READY_TO_RESOLVE: 4,
})

export const ASSISTANCE_REQUEST_REPLY_DISABLED_TEXT = 'Your request is still in the queue. If this is an urgent request, you can call the program at 1-888-338-6622 (Option 7).'

export const OFM_PROGRAM = 'OFM Program'

0 comments on commit 54f7416

Please sign in to comment.