Skip to content

Commit

Permalink
#11
Browse files Browse the repository at this point in the history
  • Loading branch information
spelkey-ucd committed Jun 12, 2023
1 parent efea89a commit 2e112b2
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 8 deletions.
7 changes: 5 additions & 2 deletions app/api/onboarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ module.exports = (api) => {

const { default: iamAdmin } = await import('@ucd-lib/iam-support-lib/src/utils/admin.js');
const { default: UcdlibOnboarding } = await import('@ucd-lib/iam-support-lib/src/utils/onboarding.js');
const { default: config } = await import('../lib/config.js');

if (
!req.auth.token.hasAdminAccess &&
Expand Down Expand Up @@ -417,13 +418,14 @@ module.exports = (api) => {
res.status(400).json({error: true, message: 'Missing required field: sendItisRt or sendFacilitiesRt'});
return;
}
const params = {rtConfig: config.rt, submittedBy: req.auth.token.id, onboardingRecord}
if ( payload.sendItisRt ) {
const ticketId = onboardingRecord.rt_ticket_id;
if ( !ticketId ) {
res.status(400).json({error: true, message: 'No ITIS RT ticket ID found!'});
return;
}
const r = await iamAdmin.sendBackgroundCheckRtNotification(ticketId, payload);
const r = await iamAdmin.sendBackgroundCheckRtNotification(ticketId, payload, params);
if ( r.error ) {
console.error(r);
res.status(500).json({error: true, message: 'Unable to send ITIS RT notification'});
Expand All @@ -438,7 +440,7 @@ module.exports = (api) => {
res.status(400).json({error: true, message: 'No Facilities RT ticket ID found!'});
return;
}
const r = await iamAdmin.sendBackgroundCheckRtNotification(ticketId, payload);
const r = await iamAdmin.sendBackgroundCheckRtNotification(ticketId, payload, params);
if ( r.error ) {
console.error(r);
res.status(500).json({error: true, message: 'Unable to send Facilities RT notification'});
Expand All @@ -451,6 +453,7 @@ module.exports = (api) => {
// update onboarding record
backgroundCheck.message = payload.message || '';
backgroundCheck.notificationSent = true;
backgroundCheck.submittedBy = req.auth.token.id;
const additionalData = {...onboardingRecord.additional_data, backgroundCheck};
const update = await UcdlibOnboarding.update(onboardingRecord.id, {additionalData});
if ( update.err ) {
Expand Down
31 changes: 29 additions & 2 deletions app/client/src/elements/pages/ucdlib-iam-page-onboarding-single.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export default class UcdlibIamPageOnboardingSingle extends window.Mixin(LitEleme
facilitiesRtTicketId: {state: true},
backgroundCheck: {state: true},
hideBackgroundCheckButton: {state: true},
sentBackgroundCheck: {state: true}
sentBackgroundCheck: {state: true},
rtTicketId: {state: true}
};
}

Expand All @@ -48,6 +49,7 @@ export default class UcdlibIamPageOnboardingSingle extends window.Mixin(LitEleme
this.firstName = '';
this.lastName = '';
this.isActiveStatus = false;
this.rtTicketId = '';
this.status = '';
this.libraryTitle = '';
this.department = '';
Expand Down Expand Up @@ -217,6 +219,13 @@ export default class UcdlibIamPageOnboardingSingle extends window.Mixin(LitEleme
this.querySelector('#obs-background-check').show();
}

/**
* @description Bound to inputs in background check modal. Updates backgroundCheck property
* @param {String} prop - property to update
* @param {String} value - value to set
* @param {String} inputType - type of input (checkbox, text, etc). If checkbox, value is ignored
* @returns
*/
_onBackgroundCheckChange(prop, value, inputType){
if (!prop ) return;
if ( inputType == 'checkbox' ) {
Expand All @@ -226,11 +235,29 @@ export default class UcdlibIamPageOnboardingSingle extends window.Mixin(LitEleme
this.requestUpdate();
}

/**
* @description Called after user clicks submit button in background check modal. Sends request to send background check notification
*/
async _onSendBackgroundCheck(){
const modal = this.querySelector('#obs-background-check');
modal.hide();
console.log(this.backgroundCheck);

this.AppStateModel.showLoading();
const r = await this.OnboardingModel.sendBackgroundCheckNotification(this.requestId, this.backgroundCheck);
if ( r.state == 'error' ){
let msg = 'Unable to send background check notification';
if ( r.error && r.error.payload && r.error.payload.message ) msg = r.error.payload.message;
console.error(r);
requestAnimationFrame(() => this.AppStateModel.showError(msg));
} else {
this.OnboardingModel.clearIdCache(this.requestId);
this.OnboardingModel.clearQueryCache();
if ( this.rtTicketId ){
this.RtModel.clearHistoryCache(this.rtTicketId);
}
this.AppStateModel.refresh();
this.AppStateModel.showAlertBanner({message: 'Background check notification sent', brandColor: 'farmers-market'});
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function render() {
.checked=${this.backgroundCheck?.sendItisRt || this.backgroundCheck?.itisRtSent}
.disabled=${this.sentBackgroundCheck || !this.rtTicketId}
>
<label class='u-inline'>ITIS RT Ticket ${this.backgroundCheck?.itisRtSentTimestamp ? `(Sent ${this.backgroundCheck?.itisRtSentDate} )` : ''}</label>
<label class='u-inline'>ITIS RT Ticket ${this.backgroundCheck?.itisRtSentTimestamp ? `(Sent ${(new Date(this.backgroundCheck?.itisRtSentTimestamp)).toLocaleString()})` : ''}</label>
</li>
<li>
<input
Expand All @@ -117,7 +117,7 @@ export function render() {
.checked=${this.backgroundCheck?.sendFacilitiesRt || this.backgroundCheck?.sendFacilitiesRt}
.disabled=${this.sentBackgroundCheck || !this.facilitiesRtTicketId}
>
<label class='u-inline'>Facilities RT Ticket ${this.backgroundCheck?.facilitiesRtSentTimestamp ? `(Sent ${this.backgroundCheck?.facilitiesRtSentTimestamp} )` : ''}</label>
<label class='u-inline'>Facilities RT Ticket ${this.backgroundCheck?.facilitiesRtSentTimestamp ? `(Sent ${(new Date(this.backgroundCheck?.facilitiesRtSentTimestamp)).toLocaleString()})` : ''}</label>
</li>
</ul>
<div class="field-container u-space-mt">
Expand Down
12 changes: 12 additions & 0 deletions lib/src/models/OnboardingModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ class OnboardingModel extends BaseModel {
return this.store.data.reconciliation[onboardingId];
}

async sendBackgroundCheckNotification(onboardingId, payload) {
let state = this.store.data.backgroundCheck[onboardingId];
try {
if( state && state.state === 'loading' ) {
await state.request;
} else {
await this.service.backgroundCheck(onboardingId, payload);
}
} catch(e) {}
return this.store.data.backgroundCheck[onboardingId];
}

async getById(id) {
let state = this.store.data.byId[id];
try {
Expand Down
14 changes: 14 additions & 0 deletions lib/src/services/OnboardingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ class OnboardingService extends BaseService {
});
}

backgroundCheck(onboardingId, payload){
return this.request({
url : `/api/onboarding/${onboardingId}/background-check-notification`,
fetchOptions : {
method : 'POST',
body : payload
},
json: true,
onLoading : request => this.store.backgroundCheckLoading(request, onboardingId),
onLoad : result => this.store.backgroundCheckLoaded(result.body, onboardingId),
onError : e => this.store.backgroundCheckError(e, onboardingId)
});
}

getById(id){
return this.request({
url : '/api/onboarding/' + id,
Expand Down
30 changes: 29 additions & 1 deletion lib/src/stores/OnboardingStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class OnboardingStore extends BaseStore {
byId: {},
byQuery: {},
byRecord: {},
reconciliation: {}
reconciliation: {},
backgroundCheck: {}
};
this.events = {
NEW_ONBOARDING_SUBMISSION: 'new-onboarding-submission',
ONBOARDING_RECONCILIATION: 'onboarding-reconciliation',
ONBOARDING_BACKGROUND_CHECK: 'onboarding-background-check',
ONBOARDING_SUBMISSION_FETCH: 'onboarding-submission-fetch',
ONBOARDING_SUBMISSION_REQUEST: 'onboarding-submission-request',
ONBOARDING_RECORD: 'onboarding-record',
Expand Down Expand Up @@ -76,6 +78,32 @@ class OnboardingStore extends BaseStore {
this.emit(this.events.ONBOARDING_RECONCILIATION, state);
}

backgroundCheckLoading(request, id) {
this._setBackgroundCheckState({
state : this.STATE.LOADING,
request
}, id);
}

backgroundCheckLoaded(payload, id) {
this._setBackgroundCheckState({
state : this.STATE.LOADED,
payload
}, id);
}

backgroundCheckError(error, id) {
this._setBackgroundCheckState({
state : this.STATE.ERROR,
error
}, id);
}

_setBackgroundCheckState(state, id) {
this.data.backgroundCheck[id] = state;
this.emit(this.events.ONBOARDING_BACKGROUND_CHECK, state);
}

byIdLoading(request, id) {
this._setByIdState({
state : this.STATE.LOADING,
Expand Down
48 changes: 47 additions & 1 deletion lib/src/utils/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,53 @@ class iamAdmin {
return out;
}

async sendBackgroundCheckRtNotification(rtTicketId, data) {}
/**
* @description Sends a notification to the RT ticket that background check is complete
* @param {String} rtTicketId - RT ticket id
* @param {Object} data - data object saved to additional_data field of onboarding record
* @param {Object} params - params object with the following properties:
* {Object} rtConfig - RT config object
* {Object} onboardingRecord - onboarding record object
* {String} submittedBy - username of person who submitted the background check request
* @returns {Object}
*/
async sendBackgroundCheckRtNotification(rtTicketId, data={}, params={}) {
const out = {
error: false,
message: '',
rtSent: false,
}
const rtClient = new UcdlibRt(params.rtConfig);
const ticket = new UcdlibRtTicket(false, {id: rtTicketId});
let name = '';
if ( params.onboardingRecord?.additional_data ) {
name = `${params.onboardingRecord.additional_data.employeeFirstName || ''} ${params.onboardingRecord.additional_data.employeeLastName || ''}`;
}
let reply = ticket.createReply();
reply.addSubject('Background Check Completed');
reply.addContent('Hello,');
reply.addContent('');
reply.addContent(`The background check ${name ? `for ${name} ` : ''}has been completed.`);
if ( data.message ) {
reply.addContent('');
reply.addContent('Details:');
reply.addContent(data.message);
}
if ( params.submittedBy ){
reply.addContent('');
reply.addContent(`Submitted by: ${params.submittedBy}`);
}
const rtResponse = await rtClient.sendCorrespondence(reply);
if ( rtResponse.err ) {
out.error = true;
out.response = rtResponse.err;
return out;
}
out.rtSent = true;
out.message = `Background check RT notification sent`;
return out;

}
}

export default new iamAdmin();

0 comments on commit 2e112b2

Please sign in to comment.