Skip to content

Commit

Permalink
WIP - Add syncOfficeStaff to Offices use case
Browse files Browse the repository at this point in the history
Jira ticket: CAMS-283
  • Loading branch information
btposey committed Sep 19, 2024
1 parent 0882a14 commit eeea11f
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion backend/functions/lib/use-cases/offices/offices.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { OfficeDetails } from '../../../../../common/src/cams/courts';
import { CamsRole } from '../../../../../common/src/cams/roles';
import { CamsUserReference } from '../../../../../common/src/cams/users';
import { ApplicationContext } from '../../adapters/types/basic';
import { getOfficesGateway, getOfficesRepository } from '../../factory';
import { getOfficesGateway, getUserGroupGateway, getOfficesRepository } from '../../factory';
import { AttorneyUser } from '../../../../../common/src/cams/users';

export class OfficesUseCase {
Expand All @@ -16,4 +18,49 @@ export class OfficesUseCase {
const repository = getOfficesRepository(context);
return repository.getOfficeAttorneys(context, officeCode);
}

public async syncOfficeStaff(applicationContext: ApplicationContext): Promise<object> {
const results = {
userGroups: [],
};

const gateway = getUserGroupGateway(applicationContext);
// TODO: get repo gateway

const config = applicationContext.config.userGroupGatewayConfig;
const userGroups = await gateway.getUserGroups(config);
const userMap = new Map<string, CamsUserReference>();

// TODO: implement the filter.
const roleGroups = userGroups.filter(() => true);
for (const roleGroup of roleGroups) {
const users = await gateway.getUserGroupUsers(config, roleGroup);
// TODO: Set the appropriate role for the group.
const role = CamsRole.TrialAttorney;
for (const user of users) {
if (userMap.has(user.id)) {
userMap.get(user.id).roles.push(role);
} else {
user.roles.push(role);
userMap.set(user.id, user);
}
}
results.userGroups.push(roleGroup);
}

// TODO: implement the filter.
const officeGroups = userGroups.filter(() => true);
for (const officeGroup of officeGroups) {
// TODO: Map the group name to the office Id.
const officeId = '';
const users = await gateway.getUserGroupUsers(config, officeGroup);
for (const user of users) {
const userWithRoles = userMap.has(user.id) ? userMap.get(user.id) : user;
console.log(officeId, userWithRoles);
// TODO: Write user document to repo
}
}

return results;
}
}

0 comments on commit eeea11f

Please sign in to comment.