Skip to content

Commit

Permalink
Merge pull request #400 from bcgov/report-changes-Viet
Browse files Browse the repository at this point in the history
CCFRI-2418 - add deleteChangeAction and update change request history table
  • Loading branch information
jenbeckett authored Aug 9, 2023
2 parents 556a617 + ee36697 commit fcfbf2a
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 34 deletions.
13 changes: 12 additions & 1 deletion backend/src/components/changeRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async function getChangeRequest(req, res) {
log.info('get changeRequest called');

try {
let operation = `ccof_change_requests(${req.params.changeRequestId})?$expand=ccof_change_action_change_request($select=ccof_change_actionid,statuscode,ccof_changetype)`;
let operation = `ccof_change_requests(${req.params.changeRequestId})?$expand=ccof_change_action_change_request($select=ccof_change_actionid,statuscode,ccof_changetype,createdon)`;
let changeRequest = await getOperation(operation);
changeRequest = await mapChangeRequestObjectForFront(changeRequest);
changeRequest.providerType = getLabelFromValue(changeRequest.providerType , ORGANIZATION_PROVIDER_TYPES);
Expand Down Expand Up @@ -158,6 +158,16 @@ async function createChangeAction(req, res, changeType) {
}
}

async function deleteChangeAction(req, res) {
log.info('deleteChangeAction called - changeActionId = ' + req.params.changeActionId);
try {
await deleteOperationWithObjectId('ccof_change_actions', req.params.changeActionId);
return res.status(HttpStatus.OK).end();
} catch (e) {
log.error('error', e);
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status);
}
}

function buildNewFacilityPayload(req) {
let facility = req.body;
Expand Down Expand Up @@ -275,4 +285,5 @@ module.exports = {
saveChangeRequestDocs,
updateChangeRequest,
createChangeAction,
deleteChangeAction,
};
12 changes: 10 additions & 2 deletions backend/src/routes/changeRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const router = express.Router();
const auth = require('../components/auth');

const isValidBackendToken = auth.isValidBackendToken();
const { getChangeRequest, updateChangeRequest, createChangeRequest, createChangeRequestFacility, deleteChangeRequest, getChangeRequestDocs, saveChangeRequestDocs, createChangeAction } = require('../components/changeRequest');
const { getChangeRequest, updateChangeRequest, createChangeRequest, createChangeRequestFacility, deleteChangeRequest, getChangeRequestDocs, saveChangeRequestDocs, createChangeAction, deleteChangeAction } = require('../components/changeRequest');
const { param, validationResult, checkSchema } = require('express-validator');
const { CHANGE_REQUEST_TYPES } = require('../util/constants');

Expand Down Expand Up @@ -108,9 +108,17 @@ router.post('/:changeRequestId/documents', passport.authenticate('jwt', {session
});

/**
* Delete a change request
* Delete a change action
*/
router.delete('/changeAction/:changeActionId', passport.authenticate('jwt', {session: false}),isValidBackendToken,
[param('changeActionId', 'URL param: [changeActionId] is required').not().isEmpty()], (req, res) => {
validationResult(req).throw();
return deleteChangeAction(req, res);
});

/**
* Delete a change request
*/
router.delete('/:changeRequestId', passport.authenticate('jwt', {session: false}),isValidBackendToken,
[param('changeRequestId', 'URL param: [changeRequestId] is required').not().isEmpty()], (req, res) => {
validationResult(req).throw();
Expand Down
1 change: 1 addition & 0 deletions backend/src/util/mapping/ChangeRequestMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const ChangeActionRequestMappings = [
{ back: 'ccof_change_actionid', front: 'changeActionId'}, // 6,
{ back: 'ccof_changetype', front: 'changeType'}, // 100000013,
{ back: '_ccof_change_request_value', front: 'changeRequestId'}, // 6,
{ back: 'createdon', front: 'createdOn'},
// { back: '_ccof_facility_value', front: 'facilityId'},
];

Expand Down
54 changes: 39 additions & 15 deletions frontend/src/components/SupportingDocumentUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@
</v-card>
</v-row>
<v-row v-if="isChangeRequest">
<v-card class="px-0 py-0 mx-auto mb-4 rounded-lg cc-top-level-card" width="1200">
<v-card class="mx-auto mb-4 rounded-lg cc-top-level-card" width="1200" v-if="isLoading">
<v-skeleton-loader v-if="isLoading" :loading="isLoading" type="card-heading"></v-skeleton-loader>
<v-skeleton-loader v-if="isLoading" :loading="isLoading" type="list-item-avatar"></v-skeleton-loader>
<v-skeleton-loader v-if="isLoading" :loading="isLoading" type="list-item-avatar"></v-skeleton-loader>
</v-card>
<v-card class="px-0 py-0 mx-auto mb-4 rounded-lg cc-top-level-card" width="1200" v-else>
<v-card-text class="pt-7 pa-0">
<div class="px-md-12 px-7">
<p class="text-h5 text--primary">
Expand All @@ -134,7 +139,7 @@
<GroupChangeDialogueContent style="max-width: 1200px;" class="pb-4"/>
</v-row>
<NavButton :isNextDisplayed="true" :isSaveDisplayed="true"
:isSaveDisabled="!isSaveDisabled || isLocked" :isNextDisabled="!isNextEnabled" :isProcessing="isProcessing"
:isSaveDisabled="!isSaveDisabled || isLocked" :isNextDisabled="!isNextEnabled" :isProcessing="isProcessing || isLoading"
@previous="previous" @next="next" @validateForm="validateForm()" @save="save(true)"></NavButton>
</v-container>
</v-form>
Expand Down Expand Up @@ -288,25 +293,44 @@ export default {
methods: {
...mapActions('supportingDocumentUpload', ['saveUploadedDocuments', 'getDocuments', 'deleteDocuments']),
...mapActions('reportChanges', ['createChangeAction']),
...mapMutations('reportChanges', ['addChangeNotificationId']),
...mapActions('reportChanges', ['createChangeAction', 'deleteChangeAction']),
...mapMutations('reportChanges', ['addChangeNotificationId','deleteChangeNotificationId']),
...mapMutations('navBar', ['forceNavBarRefresh']),
previous() {
this.$router.push(this.previousPath);
},
async next() {
if (this.isChangeRequest && this.otherChanges == 'Yes') {
let changeNotificationId = this.getChangeNotificationActionId;
if (!changeNotificationId) {
const results = await this.createChangeAction({changeRequestId: this.changeRequestId, type: 'documents' });
console.log('change action id: ', results.changeActionId);
this.addChangeNotificationId({changeRequestId: this.changeRequestId, changeNotificationActionId: results.changeActionId});
changeNotificationId = results.changeActionId;
this.isProcessing = true;
try {
if (this.isChangeRequest) {
if (this.otherChanges == 'Yes') {
let changeNotificationId = this.getChangeNotificationActionId;
if (!changeNotificationId) {
const results = await this.createChangeAction({changeRequestId: this.changeRequestId, type: 'documents' });
console.log('change action id: ', results.changeActionId);
this.addChangeNotificationId({changeRequestId: this.changeRequestId, changeNotificationActionId: results.changeActionId});
changeNotificationId = results.changeActionId
}
this.$router.push(changeUrlGuid(PATHS.CHANGE_NEW_FACILITY_OTHER, this.changeRequestId, changeNotificationId));
} else {
let changeActionId = this.getChangeNotificationActionId;
if (changeActionId) {
await this.deleteChangeAction(changeActionId);
this.deleteChangeNotificationId({changeRequestId: this.changeRequestId});
await this.forceNavBarRefresh();
}
this.$router.push(this.nextPath);
}
} else {
console.log('next path: ', this.nextPath);
this.$router.push(this.nextPath);
}
this.$router.push(changeUrlGuid(PATHS.CHANGE_NEW_FACILITY_OTHER, this.changeRequestId, changeNotificationId));
} else {
console.log('next path: ', this.nextPath);
this.$router.push(this.nextPath);
} catch (e) {
this.setFailureAlert('An error occurred while saving. Please try again later.');
} finally {
this.isProcessing = false;
}
},
validateForm() {
Expand Down
37 changes: 22 additions & 15 deletions frontend/src/components/requestChanges/ReportChanges.vue
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,23 @@ export default {
if (this.changeRequestStore?.length > 0) {
// FUTURE RELEASE - filter by Program Year
// allChangeRequests = this.changeRequestStore?.filter(changeRequest => this.isCurrentOrFuture(changeRequest.programYearId));
allChangeRequests = this.changeRequestStore?.map((changeRequest, index) => ({
index: index,
changeRequestId: changeRequest.changeActions[0]?.changeRequestId,
changeActionId: changeRequest.changeActions[0]?.changeActionId,
changeType: changeRequest.changeActions[0]?.changeType,
changeTypeString: this.getChangeTypeString(changeRequest.changeActions[0]?.changeType),
fiscalYear: this.getProgramYearString(changeRequest.programYearId),
facilityNames: this.createFacilityNameString(changeRequest.changeActions),
internalStatus: this.getInternalStatusString(changeRequest.status),
externalStatus: this.getExternalStatusString(changeRequest.externalStatus),
submissionDate: changeRequest?.firstSubmissionDate,
submissionDateString: this.getSubmissionDateString(changeRequest?.firstSubmissionDate),
priority: changeRequest?.priority
}));
allChangeRequests = this.changeRequestStore?.map((changeRequest, index) => {
let sortedChangeActions = this.sortChangeActions(changeRequest, 'desc');
return {
index: index,
changeRequestId: changeRequest?.changeRequestId,
changeActionId: sortedChangeActions[0]?.changeActionId,
changeType: sortedChangeActions[0]?.changeType,
changeTypeString: this.getChangeTypeString(sortedChangeActions[0]?.changeType),
fiscalYear: this.getProgramYearString(changeRequest.programYearId),
facilityNames: this.createFacilityNameString(changeRequest.changeActions),
internalStatus: this.getInternalStatusString(changeRequest.status),
externalStatus: this.getExternalStatusString(changeRequest.externalStatus),
submissionDate: changeRequest?.firstSubmissionDate,
submissionDateString: this.getSubmissionDateString(changeRequest?.firstSubmissionDate),
priority: changeRequest?.priority
}
});
}
return allChangeRequests;
},
Expand Down Expand Up @@ -409,13 +412,14 @@ export default {
this.$router.push(PATHS.ROOT.CHANGE_NEW_FACILITY);
},
continueButton(changeType, changeActionId = null, changeRequestId = null, index){
let sortedChangeActions = this.sortChangeActions(this.changeRequestStore[index], 'desc');
if (changeType == 'PDF_CHANGE'){
this.goToChangeForm(changeActionId, changeRequestId);
}
else if (changeType == 'NEW_FACILITY'){
this.setChangeRequestId(changeRequestId);
this.setChangeActionId(changeActionId);
this.$router.push(changeUrlGuid(PATHS.CCOF_GROUP_FACILITY, changeRequestId, this.changeRequestStore[index].changeActions[0].facilities[0].facilityId));
this.$router.push(changeUrlGuid(PATHS.CCOF_GROUP_FACILITY, changeRequestId, sortedChangeActions[0].facilities[0].facilityId));
}
else if (changeType == 'PARENT_FEE_CHANGE'){
this.setChangeRequestId(changeRequestId);
Expand Down Expand Up @@ -546,6 +550,9 @@ export default {
isUpdateButtonDisplayed(externalStatus) {
return ['Action Required'].includes(externalStatus);
},
sortChangeActions(changeRequest, order) {
return _.sortBy(changeRequest.changeActions, 'createdOn', order);
},
},
async mounted() {
this.processing = true;
Expand Down
21 changes: 20 additions & 1 deletion frontend/src/store/modules/reportChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ export default {
item.changeNotificationActionId = value.changeNotificationActionId;
state.userProfileChangeRequests.splice(index, 1, item); // done to trigger reactive getter
}
}
},
deleteChangeNotificationId:(state, value) => {
const index = state.userProfileChangeRequests.findIndex(el => el.changeRequestId === value.changeRequestId);
if (index > -1) {
let item = state.userProfileChangeRequests[index];
delete item.changeNotificationActionId;
state.userProfileChangeRequests.splice(index, 1, item); // done to trigger reactive getter
}
},

},
actions: {
Expand Down Expand Up @@ -255,6 +263,17 @@ export default {

},

async deleteChangeAction({state, commit}, changeActionId) {
console.log('trying to delete changeActionId: ', changeActionId);
checkSession();
try {
await ApiService.apiAxios.delete(ApiRoutes.CHANGE_REQUEST + '/changeAction/' + changeActionId);
} catch(e) {
console.log(`Failed to delete change action with error - ${e}`);
throw e;
}
},

async cancelChangeRequest({state, commit}, changeRequestId) {
console.log('CANCEL Change request: ', changeRequestId);
checkSession();
Expand Down

0 comments on commit fcfbf2a

Please sign in to comment.