Skip to content

Commit

Permalink
Added rolefilter to role assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
Linda-fintlabs committed Jan 17, 2025
1 parent e109b54 commit 9330a8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/data/fetch-assignments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export const fetchAssignmentsForUser = async (request: Request, id: string | und

}

export const fetchAssignedRoles = async (request: Request, id: string | undefined, size: string, page: string, search: string, orgUnits: string[]) => {
const response = await fetch(`${ASSIGNMENT_API_URL}${BASE_PATH}/api/assignments/resource/${id}/roles?size=${size}&page=${page}&search=${search}&${orgUnits.length > 0 ? 'orgUnits=' + orgUnits : ""}`, {
export const fetchAssignedRoles = async (request: Request, id: string | undefined, size: string, page: string, search: string, orgUnits: string[], roleFilter?: string) => {
const response = await fetch(`${ASSIGNMENT_API_URL}${BASE_PATH}/api/assignments/resource/${id}/roles?size=${size}&page=${page}&search=${search}&${orgUnits.length > 0 ? 'orgUnits=' + orgUnits : ""}${roleFilter}`, {
headers: request.headers
});

Expand Down
14 changes: 10 additions & 4 deletions app/routes/ressurs.$id.ny-tildeling.grupper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ export async function loader({params, request}: LoaderFunctionArgs): Promise<Typ
const resourceResponse = await fetchResourceById(request, params.id)
const resource = await resourceResponse.json()

const [responseRoles, responseAssignments, userTypesKodeverk] = await Promise.all([
fetchRoles(request, size, page, search, orgUnits, resource.validForRoles),
fetchAssignedRoles(request, params.id, "1000", "0", "", orgUnits),
const responseRoles = await fetchRoles(request, size, page, search, orgUnits, resource.validForRoles)
const roleList: IRoleList = await responseRoles.json()

let filter = ""
roleList.roles.forEach(value => {
filter += `&rolefilter=${value.id}`
})

const [responseAssignments, userTypesKodeverk] = await Promise.all([
fetchAssignedRoles(request, params.id, size, "0", "", orgUnits, filter),
fetchUserTypes(request)
]);
const roleList: IRoleList = await responseRoles.json()
const assignedRolesList: IAssignedRoles = await responseAssignments.json()

const assignedRolesMap: Map<number, IRole> = new Map(assignedRolesList.roles.map(role => [role.id, role]))
Expand Down

0 comments on commit 9330a8f

Please sign in to comment.