Skip to content

Commit

Permalink
Merge pull request #152 from bcgov/develop-rl2
Browse files Browse the repository at this point in the history
Develop rl2
  • Loading branch information
roblo-cgi committed Jan 4, 2023
2 parents f432498 + de9dd32 commit 9607642
Show file tree
Hide file tree
Showing 16 changed files with 367 additions and 72 deletions.
53 changes: 48 additions & 5 deletions backend/src/components/application.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* eslint-disable quotes */
'use strict';
const { getOperation, postOperation, patchOperationWithObjectId, deleteOperationWithObjectId} = require('./utils');
const { getOperation, postOperation, patchOperationWithObjectId, deleteOperationWithObjectId, minify} = require('./utils');
const { CCOF_APPLICATION_TYPES, ORGANIZATION_PROVIDER_TYPES } = require('../util/constants');
const HttpStatus = require('http-status-codes');
const log = require('./logger');
const { MappableObjectForFront, MappableObjectForBack } = require('../util/mapping/MappableObject');
const { ECEWEApplicationMappings, ECEWEFacilityMappings } = require('../util/mapping/Mappings');
const { ECEWEApplicationMappings, ECEWEFacilityMappings, RFIApplicationMappings } = require('../util/mapping/Mappings');
const { getCCFRIClosureDates } = require('./facility');
const { loadFiles } = require('../config/index');

async function renewCCOFApplication(req, res) {
log.info('renew CCOF application called');
Expand All @@ -29,6 +28,47 @@ async function renewCCOFApplication(req, res) {
}
}

async function getRFIApplication(req, res) {
let query = `ccof_rfipfis?$filter=(statuscode eq 1) and (_ccof_applicationccfri_value eq ${req.params.ccfriId})`;
try {
const response = await getOperation(query);
console.log('response: ', minify(response.value));
console.log('response length: ', response.value.length);
if (response.value.length == 1) {
return res.status(HttpStatus.OK).json(new MappableObjectForFront(response.value[0], RFIApplicationMappings));
} else {
return res.status(HttpStatus.NOT_FOUND).json({message: 'No data'});
}
} catch (e) {
log.error(e);
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data? e.data : e?.status );
}
}

async function updateRFIApplication(req, res) {
try {
const friApplication = new MappableObjectForBack(req.body, RFIApplicationMappings).toJSON();
let friApplicationResponse = await patchOperationWithObjectId('ccof_rfipfis', req.params.rfipfiid, friApplication);
friApplicationResponse = new MappableObjectForFront(friApplicationResponse, RFIApplicationMappings);
return res.status(HttpStatus.OK).json(friApplicationResponse);
} catch (e) {
log.error('updateRFIApplication error:', e);
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data ? e.data : e?.status);
}
}

async function createRFIApplication(req, res) {
try {
const friApplication = new MappableObjectForBack(req.body, RFIApplicationMappings).toJSON();
friApplication['[email protected]'] = `/contacts(ccof_applicationccfris='${req.params.ccfriId}')`;
log.verbose('createRFIApplication payload:', friApplication);
const friApplicationGuid = await postOperation('ccof_rfipfis', friApplication);
return res.status(HttpStatus.CREATED).json({ friApplicationGuid: friApplicationGuid });
} catch (e) {
log.error('createRFIApplication error:', e);
return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(e.data? e.data : e?.status );
}
}


//creates or updates CCFRI application.
Expand Down Expand Up @@ -242,6 +282,7 @@ async function getECEWEApplication(req, res) {
}
}


async function updateECEWEApplication(req, res) {
let application = req.body;
application = new MappableObjectForBack(application, ECEWEApplicationMappings);
Expand Down Expand Up @@ -298,6 +339,8 @@ module.exports = {
getECEWEApplication,
updateECEWEApplication,
updateECEWEFacilityApplication,
renewCCOFApplication
//getCCFRIApplication
renewCCOFApplication,
getRFIApplication,
createRFIApplication,
updateRFIApplication,
};
2 changes: 1 addition & 1 deletion backend/src/components/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function getFacility(req, res) {
let results = {};
let approvedFeesByChildAgeCategory = [];

let operation = 'accounts('+req.params.facilityId+')?$select=accountid,address1_city,accountnumber,name&$expand=ccof_account_ccof_parent_fees_Facility($select=ccof_parent_feesid,ccof_apr,ccof_aug,_ccof_childcarecategory_value,ccof_dec,_ccof_facility_value,ccof_feb,ccof_jan,ccof_jul,ccof_jun,ccof_mar,ccof_may,ccof_nov,ccof_oct,_ccof_programyear_value,ccof_sep,ccof_frequency),ccof_facility_licenses_Facility_account($select=ccof_facility_licensesid,_ccof_facility_value,_ccof_licensecategory_value)';
let operation = `accounts(${req.params.facilityId})?$select=accountid,address1_city,accountnumber,name&$expand=ccof_account_ccof_parent_fees_Facility($select=ccof_availability,ccof_parent_feesid,ccof_apr,ccof_aug,_ccof_childcarecategory_value,ccof_dec,_ccof_facility_value,ccof_feb,ccof_jan,ccof_jul,ccof_jun,ccof_mar,ccof_may,ccof_nov,ccof_oct,_ccof_programyear_value,ccof_sep,ccof_frequency;$filter=(Microsoft.Dynamics.CRM.In(PropertyName='ccof_availability',PropertyValues=['100000001','100000002']))),ccof_facility_licenses_Facility_account($select=ccof_facility_licensesid,_ccof_facility_value,_ccof_licensecategory_value)`
let payLoad = await getOperation(operation);

results.facilityId = payLoad.accountnumber;
Expand Down
43 changes: 18 additions & 25 deletions backend/src/components/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ async function getUserInfo(req, res) {
message: 'No session data'
});
}
let isIdir = isIdirUser(req);
let userName = req.params?.userName;
const isIdir = isIdirUser(req);
const queryUserName = req.params?.queryUserName;
const userName = getUserName(req);

// if is idir user (ministry user), make sure they are a user in dynamics
if (isIdir) {
Expand All @@ -37,33 +38,23 @@ async function getUserInfo(req, res) {
}

let resData = {
displayName: (userName)? req.session.passport.user._json.display_name + '-' + userName : req.session.passport.user._json.display_name,
userName: getUserName(req),
displayName: (queryUserName)? req.session.passport.user._json.display_name + '-' + queryUserName : req.session.passport.user._json.display_name,
userName: userName,
email: req.session.passport.user._json.email,
isMinistryUser: isIdir,
serverTime: new Date(),
//TODO: unreadMessages is hardcoded. Remove this with API values when built out!
unreadMessages: false,
};
let userGuid = undefined;
// let userGuid = undefined;
let userResponse = undefined;
if (isIdir) {
if (userName) {
if (queryUserName) {
try {
let profileData = await getOperation(`contacts?$select=ccof_userid,firstname,lastname&$filter=ccof_username eq '${userName}'`);
if (profileData.value?.length > 0) {
//found something.
userGuid = profileData.value[0].ccof_userid;
if (!userGuid) {
//found the account but no user guid associated
return res.status(HttpStatus.CONFLICT).json({
message: 'User found but no User Guid associated'
});
}
} else {
//didn't find that user
return res.status(HttpStatus.NOT_FOUND).json({
message: 'No user found with that BCeID UserName'
});
log.info(`Ministry user [${userName}] is impersonating with username: [${queryUserName}].`);
userResponse = await getUserProfile('\'\'', queryUserName);
if (userResponse === null) {
return res.status(HttpStatus.NOT_FOUND).json({message: 'No user found with that BCeID UserName'});
}
} catch (e) {
log.error('getUserProfile Error', e.response ? e.response.status : e.message);
Expand All @@ -75,10 +66,11 @@ async function getUserInfo(req, res) {
}
} else {
//Not an idir user, so just get the guid from the header
userGuid = getUserGuid(req);
const userGuid = getUserGuid(req);
log.verbose('User Guid is: ', userGuid);
userResponse = await getUserProfile(userGuid, userName );
}
log.verbose('User Guid is: ', userGuid);
const userResponse = await getUserProfile(userGuid);


if (log.isVerboseEnabled) {
log.verbose('getUserProfile response:',minify(userResponse));
Expand Down Expand Up @@ -108,8 +100,9 @@ async function getUserInfo(req, res) {
return res.status(HttpStatus.OK).json(results);
}

async function getUserProfile(businessGuid) {
async function getUserProfile(businessGuid, userName) {
try {
const url = config.get('dynamicsApi:apiEndpoint') + `/api/UserProfile?userId=${businessGuid}&userName=${userName}`;
const url = config.get('dynamicsApi:apiEndpoint') + `/api/UserProfile?userId=${businessGuid}&userName=''`;
log.verbose('UserProfile Url is', url);
const response = await axios.get(url, getHttpHeader());
Expand Down
23 changes: 21 additions & 2 deletions backend/src/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const passport = require('passport');
const router = express.Router();
const auth = require('../components/auth');
const isValidBackendToken= auth.isValidBackendToken();
const { upsertParentFees, upsertCCFRIApplication, updateCCFRIApplication, renewCCOFApplication} = require('../components/application');
const { getECEWEApplication, updateECEWEApplication, updateECEWEFacilityApplication , getCCFRIApplication} = require('../components/application');
const { upsertParentFees, getRFIApplication, updateCCFRIApplication, renewCCOFApplication} = require('../components/application');
const { getECEWEApplication, updateECEWEApplication, updateECEWEFacilityApplication , getCCFRIApplication, createRFIApplication, updateRFIApplication} = require('../components/application');
const { param, validationResult, checkSchema} = require('express-validator');
const { log } = require('../components/logger');

Expand Down Expand Up @@ -53,6 +53,25 @@ router.get('/ccfri/:ccfriId', passport.authenticate('jwt', {session: false}),isV
return getCCFRIApplication(req, res);
});

router.get('/ccfri/:ccfriId/rfi', passport.authenticate('jwt', {session: false}),isValidBackendToken,
[param('ccfriId', 'URL param: [ccfriId] is required').not().isEmpty()], (req, res) => {
validationResult(req).throw();
return getRFIApplication(req, res);
});

router.post('/ccfriId/:ccfriId/rfi', passport.authenticate('jwt', {session: false}),isValidBackendToken,
[param('ccfriId', 'URL param: [ccfriId] is required').not().isEmpty()], (req, res) => {
validationResult(req).throw();
return createRFIApplication(req, res);
});

router.put('/rfi/:', passport.authenticate('jwt', {session: false}),isValidBackendToken,
[param('rfipfiid', 'URL param: [rfipfiid] is required').not().isEmpty()], (req, res) => {
validationResult(req).throw();
return updateRFIApplication(req, res);
});


router.patch('/ccfri', passport.authenticate('jwt', {session: false}),isValidBackendToken, [], (req, res) => {
//validationResult(req).throw();
//console.log(req.bpdy);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ const { getUserInfo} = require('../components/user');

router.get('/', passport.authenticate('jwt', {session: false}), isValidBackendToken, getUserInfo);

router.get('/:userName', passport.authenticate('jwt', {session: false}), isValidBackendToken, getUserInfo);
router.get('/:queryUserName', passport.authenticate('jwt', {session: false}), isValidBackendToken, getUserInfo);

module.exports = router;
24 changes: 24 additions & 0 deletions backend/src/util/mapping/Mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,29 @@ const CCFRIFacilityMappings = [
// XXXXXXXXXXXXX: 'hasReceivedFunding',
];

const RFIApplicationMappings = [
{ back: 'ccof_isthereanythingelseaboutyourchangeinhours', front: 'changeInHours'}, // "is there anything else about your change in hours",
{ back: 'ccof_rfipfiid', front: 'rfiId'}, // "df27e229-0b88-ed11-81ac-000d3af48db8",
{ back: 'ccof_feeincreasedduetoaincreasedconnection', front: 'feeIncrease' }, // 1 or 0
{ back: 'ccof_appliedforanyothersources', front: 'otherSources' }, // 1 or 0
{ back: 'ccof_howwillyourfeeincreasecontributetotheover', front: 'contributionOverall'}, // "how will your fee increase contribute to the overall?",
{ back: 'ccof_feeincreasedduetoaincreaseinhoursdays', front: 'increaseDueToHours' }, // 1 or 0
{ back: 'ccof_describewhetherparentsoutofpocketmonthlyc', front: 'outOfPocket'}, // "describe whether parents out of pocket monthly",
{ back: 'ccof_isthereanythingelseaboutyourexpensesyouw', front: 'anythingElse'}, // "is there anything else about your expenses",
{ back: 'ccof_meetalloftheabovecriteria', front: 'meetCriteria' }, // 1 or 0
{ back: 'statuscode', front: 'status' }, // 1 or 0
{ back: 'ccof_feeincreasedduetoanexceptionalcircumstance', front: 'exceptionalCircumstances'}, // 0,
{ back: 'ccof_pleaseexplainwhyyouhaveincurredorwillincu', front: 'xxx1'}, // "Please explain why you have incurred or will incur",
{ back: 'ccof_feeincreasedduetoawageincrease', front: 'feeIncreaseDueToWage' }, // 1 or 0
{ back: 'ccof_name', front: 'xxx3'}, // "RFI-22000025",
{ back: 'ccof_pleasedescribehowthemajorityofchildrenyou', front: 'xxx4'}, // "please describe how the majority of children you provide",
{ back: '_ccof_applicationccfri_value@OData.Community.Display.V1.FormattedValue', front: 'xxx5'}, // "ID-22000522",
{ back: '_ccof_applicationccfri_value', front: 'ccfriApplicationId'}, // "1d261039-0e7c-ed11-81ad-000d3af4f277",
{ back: 'ccof_increasedparentfeesbefore', front: 'xxx6' }, // 1 or 0
{ back: 'ccof_exceptionalcircumstanceoccurwithin6m', front: 'circumstanceOccurWithin6Month'}, // null,
];


const CCFRIClosureDateMappings = [
{ back: 'ccof_startdate', front: 'startDate' },
{ back: 'ccof_enddate', front: 'endDate' },
Expand Down Expand Up @@ -237,4 +260,5 @@ module.exports = {
CCFRIFacilityMappings,
CCFRIClosureDateMappings,
OrganizationFacilityMappings,
RFIApplicationMappings,
};
2 changes: 1 addition & 1 deletion frontend/src/components/RFI/NMF.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@



</div> <!--end show if yes / yes selected-->


<v-row justify="space-around">
<v-btn color="info" outlined x-large @click="previous()">
Expand Down
51 changes: 34 additions & 17 deletions frontend/src/components/RFI/RFILanding.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,47 +30,43 @@
</li>
</ul>
<br>
<p>Is your fee increase due to an exceptional circumstance?</p>
<v-radio-group
required
row
v-model="model.q1"
label=""
v-model.number="model.exceptionalCircumstances"
label="Is your fee increase due to an exceptional circumstance?"
>
<v-radio
label="Yes"
value="Yes"
:value="1"
></v-radio>
<v-radio
label="No"
value="No"
:value="0"
></v-radio>
</v-radio-group>
<br>
<div v-if="model.q1 === 'Yes'">
<p>Does the exceptional circumstance occur within 6 months of the fee increase?</p>
<div v-if="model.exceptionalCircumstances == 1">
<v-radio-group
required
row
v-model="model.q2"
label=""
v-model.number="model.circumstanceOccurWithin6Month"
label="Does the exceptional circumstance occur within 6 months of the fee increase?"
>
<v-radio
label="Yes"
value="Yes"
:value="1"
></v-radio>
<v-radio
label="No"
value="No"
:value="0"
></v-radio>
</v-radio-group>
</div>
</div>
</v-card-text>
</v-card>

<div v-if="model.q1 === 'Yes' && model.q2 === 'Yes' ">

<div v-if="model.exceptionalCircumstances == 1 && model.circumstanceOccurWithin6Month == 1 ">
<v-card elevation="6" class="px-0 py-0 mx-auto my-10 rounded-lg col-12 "
min-height="230"
rounded
Expand Down Expand Up @@ -340,7 +336,7 @@
<script>
import { PATHS } from '@/utils/constants';
import { mapActions, mapState } from 'vuex';
let q1 = '';
let q2 = '';
let q3 = '';
Expand Down Expand Up @@ -372,6 +368,7 @@ export default {
data() {
return {
model,
test: 1,
input : '',
expenseList,
fundingList,
Expand All @@ -395,11 +392,31 @@ export default {
next();
},
computed: {
...mapState('rfiApp', ['rfiModel']),
},
watch: {
'$route.params.urlGuid': {
handler() {
let ccfriId = this.$route.params.urlGuid;
this.loadRfi(ccfriId);
},
immediate: true,
deep: true
},
rfiModel: {
handler() {
this.model = { ...this.rfiModel };
this.$refs.form?.resetValidation();
},
immediate: true,
deep: true
}
},
methods : {
...mapActions('rfiApp', ['loadRfi', 'saveRfi']),
next(){
this.$router.push(PATHS.WageIncrease);
this.$router.push(PATHS.WageIncrease + '/' + '2dd4af36-9688-ed11-81ac-000d3a09ce90');
// if (this.model.q1 === 'Yes'){
// this.$router.push(PATHS.addNewFees);
Expand Down
Loading

0 comments on commit 9607642

Please sign in to comment.