-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from bcgov/ofmcc-364-raise-request
Ofmcc 364 - Raise request
- Loading branch information
Showing
15 changed files
with
717 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
'use strict' | ||
const { getOperation, patchOperationWithObjectId } = require('./utils') | ||
const { MappableObjectForFront } = require('../util/mapping/MappableObject') | ||
const { MessageMappings } = require('../util/mapping/Mappings') | ||
const { getOperation, patchOperationWithObjectId, postOperation } = require('./utils') | ||
const { MappableObjectForFront, MappableObjectForBack } = require('../util/mapping/MappableObject') | ||
const { MessageMappings, AssistanceRequestMappings } = require('../util/mapping/Mappings') | ||
const HttpStatus = require('http-status-codes') | ||
const moment = require('moment') | ||
const log = require('./logger') | ||
|
@@ -14,6 +14,20 @@ function mapMessageObjectForFront(data) { | |
return new MappableObjectForFront(data, MessageMappings).toJSON() | ||
} | ||
|
||
function mapAssistanceRequestObjectForBack(data) { | ||
let assistanceRequest = new MappableObjectForBack(data, AssistanceRequestMappings).toJSON() | ||
if (assistanceRequest['ofm_contact_method'] === '1') delete assistanceRequest['ofm_telephone'] | ||
assistanceRequest['[email protected]'] = `/ofm_request_categories(${data?.requestCategoryId})` | ||
assistanceRequest['[email protected]'] = `/contacts(${data?.contactId})` | ||
assistanceRequest['ofm_facility_request_request'] = [] | ||
data?.facilities?.forEach((facility) => { | ||
assistanceRequest['ofm_facility_request_request'].push({ | ||
'[email protected]': `/accounts(${facility.facilityId})`, | ||
}) | ||
}) | ||
return assistanceRequest | ||
} | ||
|
||
function sortByPropertyDesc(property) { | ||
return function (a, b) { | ||
if (a[property] < b[property]) return 1 | ||
|
@@ -56,7 +70,19 @@ async function updateMessageLastOpenedTime(req, res) { | |
} | ||
} | ||
|
||
async function createNewAssistanceRequest(req, res) { | ||
try { | ||
let payload = mapAssistanceRequestObjectForBack(req.body) | ||
let response = await postOperation('ofm_assistance_requests?$select=ofm_name', payload) | ||
response = new MappableObjectForFront(response, AssistanceRequestMappings).toJSON() | ||
return res.status(HttpStatus.OK).json(response) | ||
} catch (e) { | ||
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status) | ||
} | ||
} | ||
|
||
module.exports = { | ||
getMessages, | ||
updateMessageLastOpenedTime, | ||
createNewAssistanceRequest, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.