Skip to content

Commit

Permalink
feat: Add Parks role (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
afwilcox authored Feb 11, 2025
1 parent de4139c commit 14360bf
Show file tree
Hide file tree
Showing 25 changed files with 86 additions and 75 deletions.
6 changes: 3 additions & 3 deletions backend/src/age_code/age_code.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Resolver, Query, Args } from "@nestjs/graphql";
import { Resolver, Query } from "@nestjs/graphql";
import { AgeCodeService } from "./age_code.service";
import { JwtRoleGuard } from "../auth/jwtrole.guard";
import { UseGuards } from "@nestjs/common";
import { Role } from "../enum/role.enum";
import { coreRoles } from "../enum/role.enum";
import { Roles } from "../auth/decorators/roles.decorator";

@UseGuards(JwtRoleGuard)
Expand All @@ -11,7 +11,7 @@ export class AgeCodeResolver {
constructor(private readonly ageCodeService: AgeCodeService) {}

@Query("ageCodes")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findAll() {
return this.ageCodeService.findAll();
}
Expand Down
10 changes: 9 additions & 1 deletion backend/src/auth/decorators/roles.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ import { Role } from "../../enum/role.enum";
* For example @Roles(Role.COS) will allow users that have the COS role on the JWT claim.
*/
export const ROLES_KEY = "roles";
export const Roles = (...roles: Role[]) => SetMetadata(ROLES_KEY, roles);
export const Roles = (...roles: (Role[] | Role)[]) => {
// Three possible scenarios here
// @Roles(Role.COS_ADMIN)
// @Roles(coreRoles) which is an array
// @Roles(coreRoles, Roles.COS_ADMIN)
// To handle all cases we accept an array of stuff and then flatten it down.
const flattenedRoles = roles.flat();
return SetMetadata(ROLES_KEY, flattenedRoles);
};
38 changes: 19 additions & 19 deletions backend/src/case_file/case_file.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CreateAssessmentInput, CreateEquipmentInput, CreatePreventionInput } fr
import { UpdateAssessmentInput, UpdateEquipmentInput, UpdatePreventionInput } from "./dto/update-case_file.input";
import { JwtRoleGuard } from "../auth/jwtrole.guard";
import { UseGuards } from "@nestjs/common";
import { Role } from "../enum/role.enum";
import { Role, coreRoles } from "../enum/role.enum";
import { Roles } from "../auth/decorators/roles.decorator";
import { ReviewInput } from "./dto/review-input";
import { CreateSupplementalNoteInput } from "./dto/supplemental-note/create-supplemental-note.input";
Expand All @@ -26,109 +26,109 @@ export class CaseFileResolver {
constructor(private readonly caseFileService: CaseFileService) {}

@Mutation("createAssessment")
@Roles(Role.COS)
@Roles(Role.COS, Role.PARKS)
createAssessment(@Args("createAssessmentInput") createAssessmentInput: CreateAssessmentInput) {
return this.caseFileService.createAssessment(createAssessmentInput);
}

@Mutation("createPrevention")
@Roles(Role.COS)
@Roles(Role.COS, Role.PARKS)
createPrevention(@Args("createPreventionInput") createPreventionInput: CreatePreventionInput) {
return this.caseFileService.createPrevention(createPreventionInput);
}

@Mutation("createReview")
@Roles(Role.COS)
@Roles(Role.COS, Role.PARKS)
createReview(@Args("reviewInput") reviewInput: ReviewInput) {
return this.caseFileService.createReview(reviewInput);
}

@Query("getCaseFile")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findOne(@Args("caseIdentifier") caseIdentifier: string) {
return this.caseFileService.findOne(caseIdentifier);
}

@Query("getCaseFileByLeadId")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findOneByLeadId(@Args("leadIdentifier") leadIdentifier: string) {
return this.caseFileService.findOneByLeadId(leadIdentifier);
}

@Query("getCasesFilesBySearchString")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findManyBySearchString(@Args("searchString") searchString: string) {
return this.caseFileService.findManyBySearchString(searchString);
}

@Mutation("updateAssessment")
@Roles(Role.COS)
@Roles(Role.COS, Role.PARKS)
updateAssessment(@Args("updateAssessmentInput") updateAssessmentInput: UpdateAssessmentInput) {
return this.caseFileService.updateAssessment(updateAssessmentInput.caseIdentifier, updateAssessmentInput);
}

@Mutation("updatePrevention")
@Roles(Role.COS)
@Roles(Role.COS, Role.PARKS)
updatePrevention(@Args("updatePreventionInput") updatePreventionInput: UpdatePreventionInput) {
return this.caseFileService.updatePrevention(updatePreventionInput.caseIdentifier, updatePreventionInput);
}

@Mutation("createEquipment")
@Roles(Role.COS)
@Roles(Role.COS, Role.PARKS)
createEquipment(@Args("createEquipmentInput") createEquipmentInput: CreateEquipmentInput) {
return this.caseFileService.createEquipment(createEquipmentInput);
}

@Mutation("updateEquipment")
@Roles(Role.COS)
@Roles(Role.COS, Role.PARKS)
updateEquipment(@Args("updateEquipmentInput") updateEquipmentInput: UpdateEquipmentInput) {
return this.caseFileService.updateEquipment(updateEquipmentInput);
}

@Mutation("deleteEquipment")
@Roles(Role.COS)
@Roles(Role.COS, Role.PARKS)
deleteEquipment(@Args("deleteEquipmentInput") deleteEquipmentInput: DeleteEquipmentInput) {
return this.caseFileService.deleteEquipment(deleteEquipmentInput);
}

@Mutation("updateReview")
@Roles(Role.COS)
@Roles(Role.COS, Role.PARKS)
updateReview(@Args("reviewInput") reviewInput: ReviewInput) {
return this.caseFileService.updateReview(reviewInput);
}

@Mutation("createNote")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
createNote(@Args("input") input: CreateSupplementalNoteInput) {
return this.caseFileService.createNote(input);
}

@Mutation("updateNote")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
updateNote(@Args("input") input: UpdateSupplementalNoteInput) {
return this.caseFileService.updateNote(input);
}

@Mutation("deleteNote")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
deleteNote(@Args("input") input: DeleteSupplementalNoteInput) {
return this.caseFileService.deleteNote(input);
}

@Mutation("createWildlife")
@Roles(Role.COS)
@Roles(Role.COS, Role.PARKS)
createWildlife(@Args("input") input: CreateWildlifeInput) {
return this.caseFileService.createWildlife(input);
}

@Mutation("updateWildlife")
@Roles(Role.COS)
@Roles(Role.COS, Role.PARKS)
updateWildlife(@Args("input") input: UpdateWildlifeInput) {
return this.caseFileService.updateWildlife(input);
}

@Mutation("deleteWildlife")
@Roles(Role.COS)
@Roles(Role.COS, Role.PARKS)
deleteWildlife(@Args("input") input: DeleteWildlifeInput) {
return this.caseFileService.deleteWildlife(input);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Resolver, Query, Args } from "@nestjs/graphql";
import { JwtRoleGuard } from "../auth/jwtrole.guard";
import { UseGuards } from "@nestjs/common";
import { Role } from "../enum/role.enum";
import { coreRoles } from "../enum/role.enum";
import { Roles } from "../auth/decorators/roles.decorator";
import { ActionCodeService } from "../action_code/action_code.service";
import { ACTION_TYPE_CODES } from "../common/action_type_codes";
Expand All @@ -12,7 +12,7 @@ export class CEEBDecisionActionResolver {
constructor(private readonly actionCodeService: ActionCodeService) {}

@Query("CEEBDecisionActions")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
find() {
return this.actionCodeService.findAllCodesByType(ACTION_TYPE_CODES.CEEBACTION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Resolver, Query } from "@nestjs/graphql";
import { UseGuards } from "@nestjs/common";
import { JwtRoleGuard } from "src/auth/jwtrole.guard";
import { Roles } from "src/auth/decorators/roles.decorator";
import { Role } from "src/enum/role.enum";
import { coreRoles } from "src/enum/role.enum";
import { CaseLocationCodeService } from "./case_location_code.service";

@UseGuards(JwtRoleGuard)
Expand All @@ -11,7 +11,7 @@ export class CaseLocationCodeResolver {
constructor(private readonly service: CaseLocationCodeService) {}

@Query("caseLocationCodes")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findAll() {
return this.service.findAll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Resolver, Query } from "@nestjs/graphql";
import { UseGuards } from "@nestjs/common";
import { JwtRoleGuard } from "src/auth/jwtrole.guard";
import { Roles } from "src/auth/decorators/roles.decorator";
import { Role } from "src/enum/role.enum";
import { coreRoles } from "src/enum/role.enum";
import { DischargeCodeService } from "./discharge_code.service";

@UseGuards(JwtRoleGuard)
Expand All @@ -11,7 +11,7 @@ export class DischargeCodeResolver {
constructor(private readonly service: DischargeCodeService) {}

@Query("dischargeCodes")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findAll() {
return this.service.findAll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Resolver, Query } from "@nestjs/graphql";
import { UseGuards } from "@nestjs/common";
import { JwtRoleGuard } from "src/auth/jwtrole.guard";
import { Roles } from "src/auth/decorators/roles.decorator";
import { Role } from "src/enum/role.enum";
import { coreRoles } from "src/enum/role.enum";
import { NonComplianceCodeService } from "./non_compliance_code.service";

@UseGuards(JwtRoleGuard)
Expand All @@ -11,7 +11,7 @@ export class NonComplianceCodeResolver {
constructor(private readonly service: NonComplianceCodeService) {}

@Query("nonComplianceCodes")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findAll() {
return this.service.findAll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { UseGuards } from "@nestjs/common";
import { ScheduleCodeService } from "./schedule_code.service";
import { JwtRoleGuard } from "src/auth/jwtrole.guard";
import { Roles } from "src/auth/decorators/roles.decorator";
import { Role } from "src/enum/role.enum";
import { coreRoles } from "src/enum/role.enum";

@UseGuards(JwtRoleGuard)
@Resolver("ScheduleCode")
export class ScheduleCodeResolver {
constructor(private readonly service: ScheduleCodeService) {}

@Query("scheduleCodes")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findAll() {
return this.service.findAll();
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/code-tables/sector_code/sector_code.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Resolver, Query, Args } from "@nestjs/graphql";
import { UseGuards } from "@nestjs/common";
import { JwtRoleGuard } from "src/auth/jwtrole.guard";
import { Roles } from "src/auth/decorators/roles.decorator";
import { Role } from "src/enum/role.enum";
import { coreRoles } from "src/enum/role.enum";
import { SectorCodeService } from "./sector_code.service";

@UseGuards(JwtRoleGuard)
Expand All @@ -11,7 +11,7 @@ export class SectorCodeResolver {
constructor(private readonly service: SectorCodeService) {}

@Query("sectorCodes")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findAll() {
return this.service.findAll();
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/configuration/configuration.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Resolver, Query, Args } from "@nestjs/graphql";
import { ConfigurationService } from "./configuration.service";
import { JwtRoleGuard } from "../auth/jwtrole.guard";
import { UseGuards } from "@nestjs/common";
import { Role } from "../enum/role.enum";
import { coreRoles } from "../enum/role.enum";
import { Roles } from "../auth/decorators/roles.decorator";

@UseGuards(JwtRoleGuard)
Expand All @@ -11,7 +11,7 @@ export class ConfigurationResolver {
constructor(private readonly configurationService: ConfigurationService) {}

@Query("configurationCodes")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findOne(@Args("configurationCode") configurationCode?: string) {
return this.configurationService.find(configurationCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Resolver, Query, Args } from "@nestjs/graphql";
import { ConflictHistoryCodeService } from "./conflict_history_code.service";
import { JwtRoleGuard } from "../auth/jwtrole.guard";
import { UseGuards } from "@nestjs/common";
import { Role } from "../enum/role.enum";
import { coreRoles } from "../enum/role.enum";
import { Roles } from "../auth/decorators/roles.decorator";

@UseGuards(JwtRoleGuard)
Expand All @@ -11,7 +11,7 @@ export class ConflictHistoryCodeResolver {
constructor(private readonly conflictHistoryCodeService: ConflictHistoryCodeService) {}

@Query("conflictHistoryCodes")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findAll() {
return this.conflictHistoryCodeService.findAll();
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/drug_code/drug_code.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Resolver, Query, Args } from "@nestjs/graphql";
import { DrugCodeService } from "./drug_code.service";
import { JwtRoleGuard } from "../auth/jwtrole.guard";
import { UseGuards } from "@nestjs/common";
import { Role } from "../enum/role.enum";
import { coreRoles } from "../enum/role.enum";
import { Roles } from "../auth/decorators/roles.decorator";

@Resolver("DrugCode")
Expand All @@ -11,7 +11,7 @@ export class DrugCodeResolver {
constructor(private readonly drugCodeService: DrugCodeService) {}

@Query("drugCodes")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findAll() {
return this.drugCodeService.findAll();
}
Expand Down
6 changes: 3 additions & 3 deletions backend/src/drug_method_code/drug_method_code.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Resolver, Query, Args } from "@nestjs/graphql";
import { Resolver, Query } from "@nestjs/graphql";
import { DrugMethodCodeService } from "./drug_method_code.service";
import { JwtRoleGuard } from "../auth/jwtrole.guard";
import { UseGuards } from "@nestjs/common";
import { Role } from "../enum/role.enum";
import { coreRoles } from "../enum/role.enum";
import { Roles } from "../auth/decorators/roles.decorator";

@Resolver("DrugMethodCode")
Expand All @@ -11,7 +11,7 @@ export class DrugMethodCodeResolver {
constructor(private readonly drugMethodCodeService: DrugMethodCodeService) {}

@Query("drugMethodCodes")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findAll() {
return this.drugMethodCodeService.findAll();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Resolver, Query, Args } from "@nestjs/graphql";
import { Resolver, Query } from "@nestjs/graphql";
import { DrugRemainingOutcomeCodeService } from "./drug_remaining_outcome_code.service";
import { JwtRoleGuard } from "../auth/jwtrole.guard";
import { UseGuards } from "@nestjs/common";
import { Role } from "../enum/role.enum";
import { coreRoles } from "../enum/role.enum";
import { Roles } from "../auth/decorators/roles.decorator";

@UseGuards(JwtRoleGuard)
Expand All @@ -11,7 +11,7 @@ export class DrugRemainingOutcomeCodeResolver {
constructor(private readonly drugRemainingOutcomeCodeService: DrugRemainingOutcomeCodeService) {}

@Query("drugRemainingOutcomeCodes")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findAll() {
return this.drugRemainingOutcomeCodeService.findAll();
}
Expand Down
6 changes: 3 additions & 3 deletions backend/src/ear_code/ear_code.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Resolver, Query, Args } from "@nestjs/graphql";
import { Resolver, Query } from "@nestjs/graphql";
import { EarCodeService } from "./ear_code.service";
import { JwtRoleGuard } from "../auth/jwtrole.guard";
import { UseGuards } from "@nestjs/common";
import { Role } from "../enum/role.enum";
import { coreRoles } from "../enum/role.enum";
import { Roles } from "../auth/decorators/roles.decorator";

@UseGuards(JwtRoleGuard)
Expand All @@ -11,7 +11,7 @@ export class EarCodeResolver {
constructor(private readonly earCodeService: EarCodeService) {}

@Query("earCodes")
@Roles(Role.COS, Role.CEEB)
@Roles(coreRoles)
findAll() {
return this.earCodeService.findAll();
}
Expand Down
Loading

0 comments on commit 14360bf

Please sign in to comment.