Skip to content

Commit

Permalink
CPF-313-2 conditional agency dropdown, refactor PR (#337)
Browse files Browse the repository at this point in the history
* CPF-313 WIP create getAgenciesByUserRole query and resolver, autoselect user's current agency

* CPF-313 cleanup code, rename resolver

* CPF-313 eslint fixes

* CPF-313 use constant for staff role

* CPF-313 retrieve agency from currentUser object
  • Loading branch information
Vikariusu authored Jun 17, 2024
1 parent 253c3c9 commit dc710ac
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions api/src/services/agencies/agencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,14 @@ export const deleteAgency: MutationResolvers['deleteAgency'] = ({ id }) => {

export const agenciesAvailableForUpload = async () => {
try {
const agencies = []
const user = await db.user.findFirst({
where: { id: context.currentUser.id },
})

if (!user) {
logger.error('User not found')
return
}
const currentUser = context.currentUser

const agency = await db.agency.findFirst({
where: { id: user.agencyId },
})
const organizationId = agency?.organizationId

if (user.role === ROLES.ORGANIZATION_STAFF) {
const agency = await db.agency.findFirst({
where: { id: user.agencyId },
})
agencies.push(agency)
return agencies
if (currentUser.role === ROLES.ORGANIZATION_STAFF) {
return [currentUser.agency]
} else {
const allAgenciesUnderOrganization = agenciesByOrganization({
organizationId,
return await agenciesByOrganization({
organizationId: currentUser.agency.organizationId,
})
return allAgenciesUnderOrganization
}
} catch (error) {
logger.error(error, `Error retrieving agencies`)
Expand Down

0 comments on commit dc710ac

Please sign in to comment.