Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion services/app/api/employees.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export default (api) => {
* Returns blank array if no reports
*/
api.get('/employees/direct-reports', async (req, res) => {
const iamId = req.auth.token.iamId;
const iamId = req.query.iamId || req.auth.token.iamId;

Comment on lines 10 to +12
if ( !iamId ) {
res.json([]);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class UcdlibIamPageSeparationSingle extends Mixin(LitElement)
appComponent : new AppComponentController(this),
}

this._injectModel('AppStateModel', 'SeparationModel', 'RtModel', 'AuthModel');
this._injectModel('AppStateModel', 'EmployeeModel', 'SeparationModel', 'RtModel', 'AuthModel');
}

/**
Expand Down Expand Up @@ -106,6 +106,7 @@ export default class UcdlibIamPageSeparationSingle extends Mixin(LitElement)
this.missingUid = payload.statusId == 9;
const ad = payload.additionalData;
this.request = payload;
this.iamId = payload.iamId || '';
this.firstName = ad?.employeeFirstName || '';
this.lastName = ad?.employeeLastName || '';
this.employeeId = ad?.employeeId || '';
Expand All @@ -119,6 +120,8 @@ export default class UcdlibIamPageSeparationSingle extends Mixin(LitElement)
this.isActiveStatus = payload.isActiveStatus;
this.status = payload.statusName || '';
this.statusDescription = payload.statusDescription || '';
this.removedFromSystems = ad?.removedFromSystems || [];
await this.getDirectReports();

this.showDeprovisionButton = this.AuthModel.isAdmin &&
(Array.isArray(ad?.removedFromSystems) && !ad.removedFromSystems.find(s => s?.value === 'ucdlib-iam-db'));
Expand Down Expand Up @@ -147,6 +150,20 @@ export default class UcdlibIamPageSeparationSingle extends Mixin(LitElement)
];
}

/**
* @description Get direct reports of separated employee for display if employee is currently in system.
*/
async getDirectReports(){
if(this.removedFromSystems?.length) return [];
const r = await this.EmployeeModel.getDirectReports(this.iamId);
Comment on lines +156 to +158
if ( r.state === 'loaded' ){
this.directReports = r.payload;
} else if ( r.state === 'error' ){
this.AppStateModel.showError('Error fetching direct reports');
this.directReports = [];
}
}

/**
* @description Opens the deprovision employee confirmation modal. Attached to button in side panel
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ export function render() {
<div><label class='u-inline'>Department:</label> ${this.department}</div>
<div><label class='u-inline'>Separation Date:</label> ${this.separationDate}</div>
</div>
<div class="panel panel--icon panel--icon-custom o-box panel--icon-cabernet" ?hidden=${this.removedFromSystems?.length}>
<h2 class="panel__title"><span class="panel__custom-icon fas fa-user-group"></span>Current Direct Reports</h2>
<div ?hidden=${this.directReports?.length}><em>No direct reports found.</em></div>
${this.directReports?.map(r => html`
<div><label class='u-inline'>Name:</label> ${r.firstName} ${r.lastName}</div>
<div><label class='u-inline'>IAM ID:</label> ${r.iamId}</div>
<br>
`)}
</div>
</div>
<div class="panel panel--icon panel--icon-custom o-box panel--icon-delta">
<h2 class="panel__title"><span class="panel__custom-icon fas fa-sitemap"></span>Supervisor</h2>
<div><label class='u-inline'>Name:</label> ${this.supervisorName}</div>
Expand Down
6 changes: 4 additions & 2 deletions services/lib/cork/models/EmployeeModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class EmployeeModel extends BaseModel {

/**
* @description Returns all direct reports for the current user
* @param {String} iamId - optional, defaults to current user
* @returns {Object} {total, results}
*/
Comment on lines 22 to 26
getDirectReports(){
return this.service.getDirectReports();
getDirectReports(iamId=''){
return this.service.getDirectReports(iamId);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion services/lib/cork/services/EmployeeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ class EmployeeService extends BaseService {
return `/api/employees`;
}

async getDirectReports(){
async getDirectReports(iamId=''){
const store = this.store.data.directReports;
const id = 'directReports';

await this.checkRequesting(
id, store,
() => this.request({
url : `${this.baseUrl}/direct-reports`,
qs: { iamId },
checkCached : () => store.get(id),
onUpdate : resp => this.store.set(
{...resp, id},
Expand Down