From 682130381b0085bac980b40aa9b9fab7e9e17a00 Mon Sep 17 00:00:00 2001 From: Dalton Burkhart Date: Sun, 22 Nov 2026 13:36:28 -0500 Subject: [PATCH 1/5] Final commit --- apps/backend/src/app.module.ts | 2 + apps/backend/src/aws/cognito/cognito.types.ts | 1 + apps/backend/src/config/migrations.ts | 2 + .../src/matches/dtos/create-match.dto.ts | 35 +- apps/backend/src/matches/matches.entity.ts | 18 +- apps/backend/src/matches/matches.module.ts | 2 + .../src/matches/matches.service.spec.ts | 3 + apps/backend/src/matches/matches.service.ts | 62 +++- .../1795372304908-AddStaffAndUpdateMatches.ts | 85 +++++ .../src/staff/dtos/confirm-staff.dto.ts | 19 ++ .../src/staff/dtos/create-staff.dto.ts | 96 ++++++ .../src/staff/staff.controller.spec.ts | 168 ++++++++++ apps/backend/src/staff/staff.controller.ts | 137 ++++++++ apps/backend/src/staff/staff.entity.ts | 104 ++++++ apps/backend/src/staff/staff.module.ts | 14 + apps/backend/src/staff/staff.service.spec.ts | 317 ++++++++++++++++++ apps/backend/src/staff/staff.service.ts | 181 ++++++++++ .../src/volunteers/volunteers.controller.ts | 6 +- 18 files changed, 1228 insertions(+), 24 deletions(-) create mode 100644 apps/backend/src/migrations/1795372304908-AddStaffAndUpdateMatches.ts create mode 100644 apps/backend/src/staff/dtos/confirm-staff.dto.ts create mode 100644 apps/backend/src/staff/dtos/create-staff.dto.ts create mode 100644 apps/backend/src/staff/staff.controller.spec.ts create mode 100644 apps/backend/src/staff/staff.controller.ts create mode 100644 apps/backend/src/staff/staff.entity.ts create mode 100644 apps/backend/src/staff/staff.module.ts create mode 100644 apps/backend/src/staff/staff.service.spec.ts create mode 100644 apps/backend/src/staff/staff.service.ts diff --git a/apps/backend/src/app.module.ts b/apps/backend/src/app.module.ts index 4a4710ea6..a138c438a 100644 --- a/apps/backend/src/app.module.ts +++ b/apps/backend/src/app.module.ts @@ -9,6 +9,7 @@ import { CoordinatorsModule } from './coordinators/coordinators.module'; import { VolunteersModule } from './volunteers/volunteers.module'; import { OwnersModule } from './owners/owners.module'; import { AnimalsModule } from './animals/animals.module'; +import { StaffModule } from './staff/staff.module'; @Module({ imports: [ @@ -28,6 +29,7 @@ import { AnimalsModule } from './animals/animals.module'; VolunteersModule, OwnersModule, AnimalsModule, + StaffModule, ], }) export class AppModule {} diff --git a/apps/backend/src/aws/cognito/cognito.types.ts b/apps/backend/src/aws/cognito/cognito.types.ts index 4ef827b31..4deb863d2 100644 --- a/apps/backend/src/aws/cognito/cognito.types.ts +++ b/apps/backend/src/aws/cognito/cognito.types.ts @@ -3,6 +3,7 @@ export enum CognitoRole { FosterVolunteer = 'FosterVolunteer', FosterCoordinator = 'FosterCoordinator', Owner = 'Owner', + Staff = 'Staff', } // Resolved Cognito configuration derived from environment variables. diff --git a/apps/backend/src/config/migrations.ts b/apps/backend/src/config/migrations.ts index f702dcdd8..c4886cb80 100644 --- a/apps/backend/src/config/migrations.ts +++ b/apps/backend/src/config/migrations.ts @@ -12,6 +12,7 @@ import { AddAnimalUpdatesAndFosterTypeArray1793163582751 } from '../migrations/1 import { AddFarmAnimalsToFosterType1793476100199 } from '../migrations/1793476100199-AddFarmAnimalsToFosterType'; import { RenameAdminUsersToOwners1793485161630 } from '../migrations/1793485161630-RenameAdminUsersToOwners'; import { AddFosterTypePreferences1793600000000 } from '../migrations/1793600000000-AddFosterTypePreferences'; +import { AddStaffAndUpdateMatches1795372304908 } from '../migrations/1795372304908-AddStaffAndUpdateMatches'; const schemaMigrations = [ InitialSchemas1789354568323, @@ -28,6 +29,7 @@ const schemaMigrations = [ AddFarmAnimalsToFosterType1793476100199, RenameAdminUsersToOwners1793485161630, AddFosterTypePreferences1793600000000, + AddStaffAndUpdateMatches1795372304908, ]; export default schemaMigrations; diff --git a/apps/backend/src/matches/dtos/create-match.dto.ts b/apps/backend/src/matches/dtos/create-match.dto.ts index 0d9c13491..a34869fb5 100644 --- a/apps/backend/src/matches/dtos/create-match.dto.ts +++ b/apps/backend/src/matches/dtos/create-match.dto.ts @@ -1,10 +1,41 @@ -import { IsInt, IsPositive, MaxLength } from 'class-validator'; +import { + IsInt, + IsOptional, + IsPositive, + MaxLength, + Validate, + ValidatorConstraint, + ValidatorConstraintInterface, + ValidationArguments, +} from 'class-validator'; import { IsNonEmptyString } from '../../utils/decorators/is-non-empty-string.decorator'; +@ValidatorConstraint({ name: 'exactlyOneApplicant', async: false }) +class ExactlyOneApplicantConstraint implements ValidatorConstraintInterface { + validate(_: unknown, args: ValidationArguments): boolean { + const obj = args.object as CreateMatchDto; + const hasVolunteer = + obj.volunteerId !== undefined && obj.volunteerId !== null; + const hasStaff = obj.staffId !== undefined && obj.staffId !== null; + return (hasVolunteer && !hasStaff) || (!hasVolunteer && hasStaff); + } + + defaultMessage(): string { + return 'Exactly one of volunteerId or staffId must be provided'; + } +} + export class CreateMatchDto { + @IsOptional() + @IsInt() + @IsPositive() + @Validate(ExactlyOneApplicantConstraint) + volunteerId?: number; + + @IsOptional() @IsInt() @IsPositive() - volunteerId!: number; + staffId?: number; @IsNonEmptyString() @MaxLength(255) diff --git a/apps/backend/src/matches/matches.entity.ts b/apps/backend/src/matches/matches.entity.ts index b0e27fc28..ac53a1fa0 100644 --- a/apps/backend/src/matches/matches.entity.ts +++ b/apps/backend/src/matches/matches.entity.ts @@ -6,6 +6,7 @@ import { JoinColumn, } from 'typeorm'; import { FosterVolunteer } from '../volunteers/volunteers.entity'; +import { FosterStaff } from '../staff/staff.entity'; import { Animal } from '../animals/animals.entity'; import { MatchStatus } from './matches.types'; @@ -15,13 +16,22 @@ export class Match { matchId!: number; @ManyToOne(() => FosterVolunteer, (volunteer) => volunteer.matches, { - nullable: false, + nullable: true, }) @JoinColumn({ name: 'volunteer_id' }) - volunteer!: FosterVolunteer; + volunteer!: FosterVolunteer | null; - @Column({ name: 'volunteer_id' }) - volunteerId!: number; + @Column({ name: 'volunteer_id', nullable: true }) + volunteerId!: number | null; + + @ManyToOne(() => FosterStaff, (staff) => staff.matches, { + nullable: true, + }) + @JoinColumn({ name: 'staff_id' }) + staff!: FosterStaff | null; + + @Column({ name: 'staff_id', nullable: true }) + staffId!: number | null; @ManyToOne(() => Animal, { nullable: false }) @JoinColumn({ diff --git a/apps/backend/src/matches/matches.module.ts b/apps/backend/src/matches/matches.module.ts index b6824c708..d3518cd96 100644 --- a/apps/backend/src/matches/matches.module.ts +++ b/apps/backend/src/matches/matches.module.ts @@ -6,6 +6,7 @@ import { MatchesService } from './matches.service'; import { VolunteersModule } from '../volunteers/volunteers.module'; import { AWSSESModule } from '../aws/ses/email.module'; import { AnimalsModule } from '../animals/animals.module'; +import { StaffModule } from '../staff/staff.module'; @Module({ imports: [ @@ -13,6 +14,7 @@ import { AnimalsModule } from '../animals/animals.module'; forwardRef(() => VolunteersModule), AWSSESModule, AnimalsModule, + StaffModule, ], controllers: [MatchesController], providers: [MatchesService], diff --git a/apps/backend/src/matches/matches.service.spec.ts b/apps/backend/src/matches/matches.service.spec.ts index 2bc506757..b4c8a1137 100644 --- a/apps/backend/src/matches/matches.service.spec.ts +++ b/apps/backend/src/matches/matches.service.spec.ts @@ -8,6 +8,7 @@ import { FosterVolunteer } from '../volunteers/volunteers.entity'; import { VolunteerStatus } from '../volunteers/volunteers.types'; import { FosterCoordinator } from '../coordinators/coordinators.entity'; import { VolunteersService } from '../volunteers/volunteers.service'; +import { StaffService } from '../staff/staff.service'; import { AnimalsService } from '../animals/animals.service'; import { EmailsService } from '../aws/ses/email.service'; import { SendEmailDTO } from '../aws/ses/sendEmail.dto'; @@ -126,6 +127,7 @@ describe('MatchesService', () => { MatchesService, { provide: getRepositoryToken(Match), useValue: matchRepo }, { provide: VolunteersService, useValue: volunteersService }, + { provide: StaffService, useValue: { findActiveOrFail: jest.fn() } }, { provide: AnimalsService, useValue: animalsService }, { provide: EmailsService, useValue: emailsService }, ], @@ -187,6 +189,7 @@ describe('MatchesService', () => { ); expect(matchRepo.create).toHaveBeenCalledWith({ volunteerId: 1, + staffId: null, chameleonAnimalId: 'A42', status: MatchStatus.PENDING, deniedReason: null, diff --git a/apps/backend/src/matches/matches.service.ts b/apps/backend/src/matches/matches.service.ts index c23cf47b6..b65e090b8 100644 --- a/apps/backend/src/matches/matches.service.ts +++ b/apps/backend/src/matches/matches.service.ts @@ -12,6 +12,7 @@ import { Match } from './matches.entity'; import { MatchStatus } from './matches.types'; import { CreateMatchDto } from './dtos/create-match.dto'; import { VolunteersService } from '../volunteers/volunteers.service'; +import { StaffService } from '../staff/staff.service'; import { AnimalsService } from '../animals/animals.service'; import { EmailsService } from '../aws/ses/email.service'; import { matchCreatedEmail } from './emails/matchCreated'; @@ -27,41 +28,58 @@ export class MatchesService { private repo: Repository, @Inject(forwardRef(() => VolunteersService)) private volunteersService: VolunteersService, + private staffService: StaffService, private animalsService: AnimalsService, private emailsService: EmailsService, ) {} /** - * Creates a PENDING match between a volunteer and a Chameleon animal, then - * notifies the volunteer's assigned foster coordinators by email. + * Creates a PENDING match between a volunteer or staff member and a Chameleon + * animal, then notifies the applicant's assigned foster coordinators by email. * * The email is best-effort: the match is already committed when it is sent, - * so a send failure is logged rather than surfaced to the caller. Volunteers + * so a send failure is logged rather than surfaced to the caller. Applicants * with no assigned coordinators still get a match; no email goes out. * - * @param dto the volunteer and Chameleon animal to match + * @param dto the volunteer/staff and Chameleon animal to match * @returns the created match - * @throws NotFoundException if the volunteer or animal does not exist - * @throws BadRequestException if the volunteer is not active + * @throws NotFoundException if the volunteer/staff or animal does not exist + * @throws BadRequestException if the volunteer/staff is not active */ async create(dto: CreateMatchDto): Promise { - const volunteer = await this.volunteersService.findActiveOrFail( - dto.volunteerId, - ); await this.animalsService.findByChameleonIdOrFail(dto.chameleonAnimalId); - const match = await this.repo.save( + if (dto.volunteerId) { + const volunteer = await this.volunteersService.findActiveOrFail( + dto.volunteerId, + ); + + const match = await this.repo.save( + this.repo.create({ + volunteerId: dto.volunteerId, + staffId: null, + chameleonAnimalId: dto.chameleonAnimalId, + status: MatchStatus.PENDING, + deniedReason: null, + }), + ); + + await this.notifyCoordinators(match, volunteer); + + return match; + } + + await this.staffService.findActiveOrFail(dto.staffId!); + + return this.repo.save( this.repo.create({ - volunteerId: dto.volunteerId, + volunteerId: null, + staffId: dto.staffId!, chameleonAnimalId: dto.chameleonAnimalId, status: MatchStatus.PENDING, deniedReason: null, }), ); - - await this.notifyCoordinators(match, volunteer); - - return match; } /** @@ -150,6 +168,20 @@ export class MatchesService { return this.repo.find({ where: { volunteerId } }); } + /** + * Fetches all Matches for a Staff member. + * + * Returns Matches of every status, not just active ones. + * Does not check that the Staff member exists, so an unknown ID yields an + * empty array; callers that need a 404 should check the Staff member first. + * + * @param staffId - The Staff member's ID. + * @returns The Staff member's Matches, or an empty array if they have none. + */ + findByStaffId(staffId: number): Promise { + return this.repo.find({ where: { staffId } }); + } + /** * Fetches all PENDING Matches for a Chameleon animal, each with its Volunteer * loaded, oldest application first. diff --git a/apps/backend/src/migrations/1795372304908-AddStaffAndUpdateMatches.ts b/apps/backend/src/migrations/1795372304908-AddStaffAndUpdateMatches.ts new file mode 100644 index 000000000..eab53f4bb --- /dev/null +++ b/apps/backend/src/migrations/1795372304908-AddStaffAndUpdateMatches.ts @@ -0,0 +1,85 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddStaffAndUpdateMatches1795372304908 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + CREATE TABLE "foster_staff" ( + "staff_id" SERIAL PRIMARY KEY, + "first_name" varchar(255) NOT NULL, + "last_name" varchar(255) NOT NULL, + "phone" varchar(20) NOT NULL, + "secondary_phone" varchar(20), + "email" varchar(255) NOT NULL, + "address" varchar(255) NOT NULL, + "city" varchar(255) NOT NULL, + "zipcode" varchar(10) NOT NULL, + "homebase" "homebase_enum" NOT NULL, + "resident_animals" text NOT NULL, + "notes" text, + "foster_type" "foster_type_enum"[] NOT NULL, + "completed_trainings" "foster_training_enum"[] NOT NULL DEFAULT '{}', + "most_recent_waiver_signed" boolean NOT NULL, + "foster_type_preferences" "foster_type_enum"[] NOT NULL DEFAULT '{}', + "active" boolean NOT NULL, + "cognito_sub" varchar(255) NOT NULL DEFAULT '', + CONSTRAINT "UQ_foster_staff_email" UNIQUE ("email") + ) + `); + + await queryRunner.query(` + CREATE TABLE "staff_coordinator_assignments" ( + "staff_id" int NOT NULL, + "coordinator_id" int NOT NULL, + PRIMARY KEY ("staff_id", "coordinator_id"), + CONSTRAINT "fk_staff_coordinator_staff" FOREIGN KEY ("staff_id") + REFERENCES "foster_staff" ("staff_id") ON DELETE CASCADE, + CONSTRAINT "fk_staff_coordinator_coordinator" FOREIGN KEY ("coordinator_id") + REFERENCES "foster_coordinators" ("coordinator_id") ON DELETE RESTRICT + ) + `); + + await queryRunner.query(` + ALTER TABLE "matches" + ALTER COLUMN "volunteer_id" DROP NOT NULL + `); + + await queryRunner.query(` + ALTER TABLE "matches" + ADD COLUMN "staff_id" int, + ADD CONSTRAINT "fk_matches_staff" FOREIGN KEY ("staff_id") + REFERENCES "foster_staff" ("staff_id") + `); + + await queryRunner.query(` + ALTER TABLE "matches" + ADD CONSTRAINT "chk_matches_one_applicant" CHECK ( + ("volunteer_id" IS NOT NULL AND "staff_id" IS NULL) + OR ("volunteer_id" IS NULL AND "staff_id" IS NOT NULL) + ) + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + ALTER TABLE "matches" + DROP CONSTRAINT "chk_matches_one_applicant" + `); + + await queryRunner.query(` + ALTER TABLE "matches" + DROP CONSTRAINT "fk_matches_staff", + DROP COLUMN "staff_id" + `); + + await queryRunner.query(` + ALTER TABLE "matches" + ALTER COLUMN "volunteer_id" SET NOT NULL + `); + + await queryRunner.query(`DROP TABLE "staff_coordinator_assignments"`); + + await queryRunner.query(`DROP TABLE "foster_staff"`); + } +} diff --git a/apps/backend/src/staff/dtos/confirm-staff.dto.ts b/apps/backend/src/staff/dtos/confirm-staff.dto.ts new file mode 100644 index 000000000..ae4ceb645 --- /dev/null +++ b/apps/backend/src/staff/dtos/confirm-staff.dto.ts @@ -0,0 +1,19 @@ +import { Transform } from 'class-transformer'; +import { IsEmail, Matches, MaxLength } from 'class-validator'; + +export class ConfirmStaffDto { + @Transform(({ value }) => + typeof value === 'string' ? value.trim().toLowerCase() : value, + ) + @IsEmail() + @MaxLength(255) + @Matches(/^[^\s@]+@mspca\.org$/, { + message: 'Email must end in @mspca.org', + }) + email!: string; + + @Matches(/^\d{6}$/, { + message: 'Verification code must be 6 digits', + }) + code!: string; +} diff --git a/apps/backend/src/staff/dtos/create-staff.dto.ts b/apps/backend/src/staff/dtos/create-staff.dto.ts new file mode 100644 index 000000000..68f1c3294 --- /dev/null +++ b/apps/backend/src/staff/dtos/create-staff.dto.ts @@ -0,0 +1,96 @@ +import { + ArrayNotEmpty, + ArrayUnique, + IsArray, + IsEmail, + IsEnum, + IsNotEmpty, + IsPhoneNumber, + IsString, + IsStrongPassword, + Matches, + MaxLength, + ValidateIf, +} from 'class-validator'; +import { Transform } from 'class-transformer'; +import { IsNonEmptyString } from '../../utils/decorators/is-non-empty-string.decorator'; +import { Homebase } from '../../types'; +import { FosterTraining, FosterType } from '../../volunteers/volunteers.types'; + +export class CreateStaffDto { + @IsNonEmptyString() + @MaxLength(255) + firstName!: string; + + @IsNonEmptyString() + @MaxLength(255) + lastName!: string; + + @IsNonEmptyString() + @IsPhoneNumber('US') + @MaxLength(20) + phone!: string; + + @ValidateIf((_, value) => value !== undefined && value !== null) + @IsNonEmptyString() + @IsPhoneNumber('US') + @MaxLength(20) + secondaryPhone?: string | null; + + @Transform(({ value }) => + typeof value === 'string' ? value.trim().toLowerCase() : value, + ) + @IsEmail() + @MaxLength(255) + @Matches(/^[^\s@]+@mspca\.org$/, { + message: 'Email must end in @mspca.org', + }) + email!: string; + + @IsString() + @IsNotEmpty() + @IsStrongPassword({ + minLength: 8, + minLowercase: 1, + minUppercase: 1, + minNumbers: 1, + minSymbols: 1, + }) + @MaxLength(256) + password!: string; + + @IsNonEmptyString() + @MaxLength(255) + address!: string; + + @IsNonEmptyString() + @MaxLength(255) + city!: string; + + @IsNonEmptyString() + @MaxLength(10) + zipcode!: string; + + @IsEnum(Homebase) + homebase!: Homebase; + + @IsNonEmptyString() + residentAnimals!: string; + + @ValidateIf((_, value) => value !== undefined && value !== null) + @IsNonEmptyString() + notes?: string | null; + + @IsArray() + @ArrayNotEmpty() + @ArrayUnique() + @IsEnum(FosterType, { each: true }) + fosterType!: FosterType[]; + + @ValidateIf((_, value) => value !== undefined) + @IsArray() + @ArrayNotEmpty() + @ArrayUnique() + @IsEnum(FosterTraining, { each: true }) + completedTrainings?: FosterTraining[]; +} diff --git a/apps/backend/src/staff/staff.controller.spec.ts b/apps/backend/src/staff/staff.controller.spec.ts new file mode 100644 index 000000000..677fb4a5f --- /dev/null +++ b/apps/backend/src/staff/staff.controller.spec.ts @@ -0,0 +1,168 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { NotFoundException } from '@nestjs/common'; +import { StaffController } from './staff.controller'; +import { StaffService } from './staff.service'; +import { FosterStaff } from './staff.entity'; +import { Homebase } from '../types'; +import { FosterType } from '../volunteers/volunteers.types'; +import { CreateStaffDto } from './dtos/create-staff.dto'; +import { ConfirmStaffDto } from './dtos/confirm-staff.dto'; + +describe('StaffController', () => { + let controller: StaffController; + let service: { + create: jest.Mock; + confirm: jest.Mock; + deactivate: jest.Mock; + activate: jest.Mock; + }; + + const dto = { + firstName: 'Jane', + lastName: 'Doe', + phone: '+16175551234', + secondaryPhone: null, + email: 'jane.doe@mspca.org', + password: 'Str0ng!Password', + address: '123 Main St', + city: 'Boston', + zipcode: '02101', + homebase: Homebase.BOSTON, + residentAnimals: 'None', + notes: null, + fosterType: [FosterType.DOG], + } as CreateStaffDto; + + const confirmDto = { + email: 'jane.doe@mspca.org', + code: '123456', + } as ConfirmStaffDto; + + beforeEach(async () => { + service = { + create: jest.fn(), + confirm: jest.fn(), + deactivate: jest.fn(), + activate: jest.fn(), + }; + + const module: TestingModule = await Test.createTestingModule({ + controllers: [StaffController], + providers: [{ provide: StaffService, useValue: service }], + }).compile(); + + controller = module.get(StaffController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); + + describe('create', () => { + it('delegates creation to the service', async () => { + const profile = { + firstName: dto.firstName, + lastName: dto.lastName, + phone: dto.phone, + secondaryPhone: dto.secondaryPhone, + email: dto.email, + address: dto.address, + city: dto.city, + zipcode: dto.zipcode, + homebase: dto.homebase, + residentAnimals: dto.residentAnimals, + notes: dto.notes, + fosterType: dto.fosterType, + }; + + const created = { + staffId: 1, + ...profile, + active: true, + cognitoSub: 'cognito-sub-123', + assignedCoordinators: [], + } as FosterStaff; + + service.create.mockResolvedValue(created); + + const result = await controller.create(dto); + + expect(service.create).toHaveBeenCalledWith(dto); + expect(result).toBe(created); + }); + + it('propagates service errors', async () => { + const error = new Error('Service failure'); + service.create.mockRejectedValue(error); + + await expect(controller.create(dto)).rejects.toBe(error); + }); + }); + + describe('confirm', () => { + it('delegates confirmation to the service', async () => { + service.confirm.mockResolvedValue(undefined); + + await controller.confirm(confirmDto); + + expect(service.confirm).toHaveBeenCalledWith(confirmDto); + }); + + it('propagates service errors', async () => { + const error = new Error('Invalid code'); + service.confirm.mockRejectedValue(error); + + await expect(controller.confirm(confirmDto)).rejects.toBe(error); + }); + }); + + describe('deactivate', () => { + it('should call service.deactivate with the parsed id', async () => { + const staff = { + staffId: 1, + active: false, + } as FosterStaff; + service.deactivate.mockResolvedValue(staff); + + const result = await controller.deactivate(1); + + expect(service.deactivate).toHaveBeenCalledWith(1); + expect(result).toEqual(staff); + }); + + it('propagates NotFoundException thrown by the service', async () => { + service.deactivate.mockRejectedValue( + new NotFoundException('Staff member with ID 999 not found'), + ); + + await expect(controller.deactivate(999)).rejects.toThrow( + new NotFoundException('Staff member with ID 999 not found'), + ); + }); + }); + + describe('activate', () => { + it('should call service.activate with the parsed id', async () => { + const staff = { + staffId: 1, + active: true, + } as FosterStaff; + service.activate.mockResolvedValue(staff); + + const result = await controller.activate(1); + + expect(service.activate).toHaveBeenCalledWith(1); + expect(result).toEqual(staff); + }); + + it('propagates NotFoundException thrown by the service', async () => { + service.activate.mockRejectedValue( + new NotFoundException('Staff member with ID 999 not found'), + ); + + await expect(controller.activate(999)).rejects.toThrow( + new NotFoundException('Staff member with ID 999 not found'), + ); + }); + }); +}); diff --git a/apps/backend/src/staff/staff.controller.ts b/apps/backend/src/staff/staff.controller.ts new file mode 100644 index 000000000..434910d9a --- /dev/null +++ b/apps/backend/src/staff/staff.controller.ts @@ -0,0 +1,137 @@ +import { + Body, + Controller, + HttpCode, + HttpStatus, + Param, + ParseIntPipe, + Patch, + Post, +} from '@nestjs/common'; +import { ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger'; +import { StaffService } from './staff.service'; +import { FosterStaff } from './staff.entity'; +import { CreateStaffDto } from './dtos/create-staff.dto'; +import { ConfirmStaffDto } from './dtos/confirm-staff.dto'; +import { Public } from '../aws/cognito/cognito.decorator'; +import { validateId } from '../utils/validation.utils'; + +@ApiTags('Staff') +@Controller('staff') +export class StaffController { + constructor(private staffService: StaffService) {} + + @Public() + @Post() + @ApiOperation({ + summary: 'Create a staff member account', + }) + @ApiResponse({ + status: HttpStatus.CREATED, + description: + 'The staff member was created and a verification code was emailed', + type: FosterStaff, + }) + @ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'Invalid profile fields or password', + }) + @ApiResponse({ + status: HttpStatus.CONFLICT, + description: 'An account with this email already exists', + }) + @ApiResponse({ + status: HttpStatus.INTERNAL_SERVER_ERROR, + description: 'Failed to register or save the staff member', + }) + async create(@Body() dto: CreateStaffDto): Promise { + return this.staffService.create(dto); + } + + @Public() + @Post('/confirm') + @HttpCode(HttpStatus.NO_CONTENT) + @ApiOperation({ + summary: 'Confirm a staff member email', + }) + @ApiResponse({ + status: HttpStatus.NO_CONTENT, + description: + 'The email was confirmed and the staff member was assigned their Cognito role', + }) + @ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'Invalid or expired verification code', + }) + @ApiResponse({ + status: HttpStatus.NOT_FOUND, + description: 'No staff member with this email exists', + }) + @ApiResponse({ + status: HttpStatus.TOO_MANY_REQUESTS, + description: 'Too many verification attempts', + }) + @ApiResponse({ + status: HttpStatus.INTERNAL_SERVER_ERROR, + description: 'Failed to confirm the staff member', + }) + async confirm(@Body() dto: ConfirmStaffDto): Promise { + await this.staffService.confirm(dto); + } + + @Patch('/:id/deactivate') + @ApiOperation({ + summary: 'Deactivate an active staff member', + }) + @ApiParam({ + name: 'id', + type: Number, + description: 'Staff member ID', + }) + @ApiResponse({ + status: HttpStatus.OK, + description: 'The staff member was deactivated', + type: FosterStaff, + }) + @ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'Invalid staff member ID or staff member is already inactive', + }) + @ApiResponse({ + status: HttpStatus.NOT_FOUND, + description: 'Staff member with the given ID does not exist', + }) + async deactivate( + @Param('id', ParseIntPipe) id: number, + ): Promise { + validateId(id, 'Staff member'); + return this.staffService.deactivate(id); + } + + @Patch('/:id/activate') + @ApiOperation({ + summary: 'Activate an inactive staff member', + }) + @ApiParam({ + name: 'id', + type: Number, + description: 'Staff member ID', + }) + @ApiResponse({ + status: HttpStatus.OK, + description: 'The staff member was activated', + type: FosterStaff, + }) + @ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'Invalid staff member ID or staff member is already active', + }) + @ApiResponse({ + status: HttpStatus.NOT_FOUND, + description: 'Staff member with the given ID does not exist', + }) + async activate(@Param('id', ParseIntPipe) id: number): Promise { + validateId(id, 'Staff member'); + return this.staffService.activate(id); + } +} diff --git a/apps/backend/src/staff/staff.entity.ts b/apps/backend/src/staff/staff.entity.ts new file mode 100644 index 000000000..66b2408f8 --- /dev/null +++ b/apps/backend/src/staff/staff.entity.ts @@ -0,0 +1,104 @@ +import { + Entity, + PrimaryGeneratedColumn, + Column, + OneToMany, + ManyToMany, + JoinTable, + Unique, +} from 'typeorm'; +import { Homebase } from '../types'; +import { FosterTraining, FosterType } from '../volunteers/volunteers.types'; +import { FosterCoordinator } from '../coordinators/coordinators.entity'; +import { Match } from '../matches/matches.entity'; + +@Entity('foster_staff') +@Unique('UQ_foster_staff_email', ['email']) +export class FosterStaff { + @PrimaryGeneratedColumn({ name: 'staff_id' }) + staffId!: number; + + @Column({ name: 'first_name', type: 'varchar', length: 255 }) + firstName!: string; + + @Column({ name: 'last_name', type: 'varchar', length: 255 }) + lastName!: string; + + @Column({ type: 'varchar', length: 20 }) + phone!: string; + + @Column({ + name: 'secondary_phone', + type: 'varchar', + length: 20, + nullable: true, + }) + secondaryPhone!: string | null; + + @Column({ type: 'varchar', length: 255, unique: true }) + email!: string; + + @Column({ type: 'varchar', length: 255 }) + address!: string; + + @Column({ type: 'varchar', length: 255 }) + city!: string; + + @Column({ type: 'varchar', length: 10 }) + zipcode!: string; + + @Column({ type: 'enum', enum: Homebase }) + homebase!: Homebase; + + @Column({ name: 'resident_animals', type: 'text' }) + residentAnimals!: string; + + @Column({ type: 'text', nullable: true }) + notes!: string | null; + + @Column({ name: 'foster_type', type: 'enum', enum: FosterType, array: true }) + fosterType!: FosterType[]; + + @Column({ + name: 'completed_trainings', + type: 'enum', + enum: FosterTraining, + enumName: 'foster_training_enum', + array: true, + default: () => "'{}'", + }) + completedTrainings!: FosterTraining[]; + + @Column({ name: 'most_recent_waiver_signed', type: 'boolean' }) + mostRecentWaiverSigned!: boolean; + + @Column({ + name: 'foster_type_preferences', + type: 'enum', + enum: FosterType, + enumName: 'foster_type_enum', + array: true, + default: () => "'{}'", + }) + fosterTypePreferences!: FosterType[]; + + @Column({ type: 'boolean' }) + active!: boolean; + + @Column({ name: 'cognito_sub', type: 'varchar', length: 255, default: '' }) + cognitoSub!: string; + + @ManyToMany(() => FosterCoordinator, { onDelete: 'CASCADE' }) + @JoinTable({ + name: 'staff_coordinator_assignments', + joinColumn: { name: 'staff_id', referencedColumnName: 'staffId' }, + inverseJoinColumn: { + name: 'coordinator_id', + referencedColumnName: 'coordinatorId', + }, + }) + assignedCoordinators!: FosterCoordinator[]; + + @OneToMany(() => Match, (match) => match.staff) + matches?: Match[]; +} diff --git a/apps/backend/src/staff/staff.module.ts b/apps/backend/src/staff/staff.module.ts new file mode 100644 index 000000000..5f059228e --- /dev/null +++ b/apps/backend/src/staff/staff.module.ts @@ -0,0 +1,14 @@ +import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { FosterStaff } from './staff.entity'; +import { StaffController } from './staff.controller'; +import { StaffService } from './staff.service'; +import { CognitoModule } from '../aws/cognito/cognito.module'; + +@Module({ + imports: [TypeOrmModule.forFeature([FosterStaff]), CognitoModule], + controllers: [StaffController], + providers: [StaffService], + exports: [StaffService], +}) +export class StaffModule {} diff --git a/apps/backend/src/staff/staff.service.spec.ts b/apps/backend/src/staff/staff.service.spec.ts new file mode 100644 index 000000000..fb61cbe51 --- /dev/null +++ b/apps/backend/src/staff/staff.service.spec.ts @@ -0,0 +1,317 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { + BadRequestException, + ConflictException, + InternalServerErrorException, + Logger, + NotFoundException, +} from '@nestjs/common'; +import { getRepositoryToken } from '@nestjs/typeorm'; +import { Repository } from 'typeorm'; +import { StaffService } from './staff.service'; +import { FosterStaff } from './staff.entity'; +import { CreateStaffDto } from './dtos/create-staff.dto'; +import { ConfirmStaffDto } from './dtos/confirm-staff.dto'; +import { CognitoService } from '../aws/cognito/cognito.service'; +import { CognitoRole } from '../aws/cognito/cognito.types'; +import { Homebase } from '../types'; +import { FosterType } from '../volunteers/volunteers.types'; + +describe('StaffService', () => { + let service: StaffService; + let repo: jest.Mocked>; + let cognitoService: jest.Mocked; + let loggerSpy: jest.SpyInstance; + + const dto: CreateStaffDto = { + firstName: 'Jane', + lastName: 'Doe', + phone: '+16175551234', + secondaryPhone: null, + email: 'jane.doe@mspca.org', + password: 'Str0ng!Password', + address: '123 Main St', + city: 'Boston', + zipcode: '02101', + homebase: Homebase.BOSTON, + residentAnimals: 'None', + notes: null, + fosterType: [FosterType.DOG], + }; + + const confirmDto: ConfirmStaffDto = { + email: dto.email, + code: '123456', + }; + + const staff = { + staffId: 1, + firstName: dto.firstName, + lastName: dto.lastName, + phone: dto.phone, + secondaryPhone: dto.secondaryPhone, + email: dto.email, + address: dto.address, + city: dto.city, + zipcode: dto.zipcode, + homebase: dto.homebase, + residentAnimals: dto.residentAnimals, + notes: dto.notes, + fosterType: dto.fosterType, + active: true, + cognitoSub: 'cognito-sub-123', + assignedCoordinators: [], + } as FosterStaff; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [ + StaffService, + { + provide: getRepositoryToken(FosterStaff), + useValue: { + findOneBy: jest.fn(), + findOne: jest.fn(), + save: jest.fn(), + }, + }, + { + provide: CognitoService, + useValue: { + signUpUser: jest.fn(), + confirmUser: jest.fn(), + deleteUser: jest.fn(), + }, + }, + ], + }).compile(); + + service = module.get(StaffService); + repo = module.get(getRepositoryToken(FosterStaff)); + cognitoService = module.get(CognitoService); + + loggerSpy = jest.spyOn(Logger.prototype, 'error').mockImplementation(); + }); + + afterEach(() => { + jest.restoreAllMocks(); + }); + + describe('create', () => { + it('signs up with Cognito before saving', async () => { + repo.findOneBy.mockResolvedValue(null); + cognitoService.signUpUser.mockResolvedValue('cognito-sub-123'); + repo.save.mockResolvedValue(staff); + + const result = await service.create(dto); + + expect(repo.findOneBy).toHaveBeenCalledWith({ + email: dto.email, + }); + + expect(cognitoService.signUpUser).toHaveBeenCalledWith({ + firstName: dto.firstName, + lastName: dto.lastName, + email: dto.email, + password: dto.password, + }); + + expect(repo.save).toHaveBeenCalledWith( + expect.objectContaining({ + email: dto.email, + active: true, + cognitoSub: 'cognito-sub-123', + }), + ); + + expect(repo.save.mock.calls[0][0]).not.toHaveProperty('password'); + expect(result).toBe(staff); + }); + + it('saves with an empty coordinator list', async () => { + repo.findOneBy.mockResolvedValue(null); + cognitoService.signUpUser.mockResolvedValue('cognito-sub-123'); + repo.save.mockResolvedValue(staff); + + await service.create(dto); + + expect(repo.save).toHaveBeenCalledWith( + expect.objectContaining({ assignedCoordinators: [] }), + ); + }); + + it('rejects duplicate staff members', async () => { + repo.findOneBy.mockResolvedValue(staff); + + await expect(service.create(dto)).rejects.toThrow(ConflictException); + + expect(cognitoService.signUpUser).not.toHaveBeenCalled(); + expect(repo.save).not.toHaveBeenCalled(); + }); + + it('does not save if Cognito sign-up fails', async () => { + repo.findOneBy.mockResolvedValue(null); + cognitoService.signUpUser.mockRejectedValue( + new ConflictException('Cognito user already exists'), + ); + + await expect(service.create(dto)).rejects.toThrow(ConflictException); + + expect(repo.save).not.toHaveBeenCalled(); + }); + + it('deletes the Cognito user when saving fails and logs the error', async () => { + const databaseError = new Error('Database error'); + + repo.findOneBy.mockResolvedValue(null); + cognitoService.signUpUser.mockResolvedValue('sub-123'); + repo.save.mockRejectedValue(databaseError); + cognitoService.deleteUser.mockResolvedValue(undefined); + + await expect(service.create(dto)).rejects.toThrow( + InternalServerErrorException, + ); + + expect(cognitoService.deleteUser).toHaveBeenCalledWith(dto.email); + + expect(loggerSpy).toHaveBeenCalledWith( + `Failed to save staff member ${dto.email}`, + databaseError, + ); + }); + + it('returns a server error and logs when Cognito cleanup fails', async () => { + const databaseError = new Error('Database error'); + const cleanupError = new Error('Cleanup failed'); + + repo.findOneBy.mockResolvedValue(null); + cognitoService.signUpUser.mockResolvedValue('sub-123'); + repo.save.mockRejectedValue(databaseError); + cognitoService.deleteUser.mockRejectedValue(cleanupError); + + await expect(service.create(dto)).rejects.toThrow( + InternalServerErrorException, + ); + + expect(cognitoService.deleteUser).toHaveBeenCalledWith(dto.email); + + expect(loggerSpy).toHaveBeenCalledWith( + `Failed to save staff member ${dto.email}`, + databaseError, + ); + + expect(loggerSpy).toHaveBeenCalledWith( + `Created Cognito user sub-123 for ${dto.email}, but failed to save the staff member or delete the Cognito user`, + ); + }); + }); + + describe('confirm', () => { + it('confirms an existing staff member', async () => { + repo.findOneBy.mockResolvedValue(staff); + cognitoService.confirmUser.mockResolvedValue(undefined); + + await expect(service.confirm(confirmDto)).resolves.toBeUndefined(); + + expect(repo.findOneBy).toHaveBeenCalledWith({ + email: confirmDto.email, + }); + + expect(cognitoService.confirmUser).toHaveBeenCalledWith( + confirmDto.email, + confirmDto.code, + CognitoRole.Staff, + ); + }); + + it('rejects confirmation when the staff member does not exist', async () => { + repo.findOneBy.mockResolvedValue(null); + + await expect(service.confirm(confirmDto)).rejects.toThrow( + NotFoundException, + ); + + expect(cognitoService.confirmUser).not.toHaveBeenCalled(); + }); + + it('propagates an invalid verification code error', async () => { + const error = new BadRequestException('Invalid verification code'); + + repo.findOneBy.mockResolvedValue(staff); + cognitoService.confirmUser.mockRejectedValue(error); + + await expect(service.confirm(confirmDto)).rejects.toBe(error); + + expect(cognitoService.confirmUser).toHaveBeenCalledWith( + confirmDto.email, + confirmDto.code, + CognitoRole.Staff, + ); + }); + + it('propagates an expired verification code error', async () => { + const error = new BadRequestException('Verification code expired'); + + repo.findOneBy.mockResolvedValue(staff); + cognitoService.confirmUser.mockRejectedValue(error); + + await expect(service.confirm(confirmDto)).rejects.toBe(error); + }); + + it('propagates Cognito server errors', async () => { + const error = new InternalServerErrorException('Failed to confirm user'); + + repo.findOneBy.mockResolvedValue(staff); + cognitoService.confirmUser.mockRejectedValue(error); + + await expect(service.confirm(confirmDto)).rejects.toBe(error); + }); + }); + + describe('deactivate', () => { + it('deactivates an active staff member', async () => { + repo.findOne.mockResolvedValue({ ...staff }); + repo.save.mockImplementation(async (value) => value as FosterStaff); + + const result = await service.deactivate(1); + + expect(result.active).toBe(false); + expect(repo.save).toHaveBeenCalled(); + }); + + it('rejects an already inactive staff member', async () => { + repo.findOne.mockResolvedValue({ + ...staff, + active: false, + }); + + await expect(service.deactivate(1)).rejects.toThrow(BadRequestException); + }); + }); + + describe('activate', () => { + it('activates an inactive staff member', async () => { + repo.findOne.mockResolvedValue({ + ...staff, + active: false, + }); + repo.save.mockImplementation(async (value) => value as FosterStaff); + + const result = await service.activate(1); + + expect(result.active).toBe(true); + }); + + it('rejects an already active staff member', async () => { + repo.findOne.mockResolvedValue({ ...staff }); + + await expect(service.activate(1)).rejects.toThrow(BadRequestException); + }); + + it('rejects a missing staff member', async () => { + repo.findOne.mockResolvedValue(null); + + await expect(service.activate(999)).rejects.toThrow(NotFoundException); + }); + }); +}); diff --git a/apps/backend/src/staff/staff.service.ts b/apps/backend/src/staff/staff.service.ts new file mode 100644 index 000000000..edd18d153 --- /dev/null +++ b/apps/backend/src/staff/staff.service.ts @@ -0,0 +1,181 @@ +import { + BadRequestException, + ConflictException, + Injectable, + InternalServerErrorException, + Logger, + NotFoundException, +} from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; +import { Repository } from 'typeorm'; +import { FosterStaff } from './staff.entity'; +import { CreateStaffDto } from './dtos/create-staff.dto'; +import { ConfirmStaffDto } from './dtos/confirm-staff.dto'; +import { CognitoService } from '../aws/cognito/cognito.service'; +import { CognitoRole } from '../aws/cognito/cognito.types'; + +@Injectable() +export class StaffService { + private readonly logger = new Logger(StaffService.name); + + constructor( + @InjectRepository(FosterStaff) + private repo: Repository, + private cognitoService: CognitoService, + ) {} + + /** + * Registers a staff member with Cognito and saves their profile. + * Staff are active immediately and do not require approval. + * Coordinator assignments are left empty for now. + * + * @param dto - The staff member's registration information. + * @returns The newly created staff member. + * @throws {ConflictException} If a staff member with the email already exists in the database. + * @throws {BadRequestException} If Cognito rejects the registration request. + * @throws {InternalServerErrorException} If saving the staff member to the database fails (the Cognito user is deleted). + */ + async create(dto: CreateStaffDto): Promise { + const { password, ...profile } = dto; + const { email } = profile; + + const existing = await this.repo.findOneBy({ email }); + + if (existing) { + throw new ConflictException( + 'A staff member with this email already exists', + ); + } + + const cognitoSub = await this.cognitoService.signUpUser({ + firstName: profile.firstName, + lastName: profile.lastName, + email, + password, + }); + + try { + return await this.repo.save({ + ...profile, + active: true, + cognitoSub, + assignedCoordinators: [], + }); + } catch (error) { + this.logger.error(`Failed to save staff member ${email}`, error); + + try { + await this.cognitoService.deleteUser(email); + } catch { + this.logger.error( + `Created Cognito user ${cognitoSub} for ${email}, but failed to save the staff member or delete the Cognito user`, + ); + } + + throw new InternalServerErrorException('Failed to save the staff member'); + } + } + + /** + * Confirms a staff member's email and assigns the Staff Cognito role. + * + * @param dto - The staff member's email and verification code. + * @returns A promise that resolves when confirmation is complete. + * @throws {NotFoundException} If no staff member exists with the given email in the database. + * @throws {BadRequestException} If Cognito rejects the verification code or confirmation request. + * @throws {InternalServerErrorException} If Cognito fails to complete the confirmation. + */ + async confirm(dto: ConfirmStaffDto): Promise { + const { email } = dto; + + const staff = await this.repo.findOneBy({ email }); + + if (!staff) { + throw new NotFoundException('No staff member with this email exists'); + } + + await this.cognitoService.confirmUser(email, dto.code, CognitoRole.Staff); + } + + /** + * Fetches a staff member by their ID, including their assigned coordinators. + * + * @param id - The ID of the staff member to retrieve. + * @returns The staff member with their assigned coordinators. + * @throws {NotFoundException} If no staff member exists with the given ID. + */ + async findByIdOrFail(id: number): Promise { + const staff = await this.repo.findOne({ + where: { staffId: id }, + relations: ['assignedCoordinators'], + }); + + if (!staff) { + throw new NotFoundException(`Staff member with ID ${id} not found`); + } + + return staff; + } + + /** + * Fetches a staff member by their ID and verifies they are active. + * + * @param id - The ID of the staff member to retrieve. + * @returns The staff member. + * @throws {NotFoundException} If no staff member exists with the given ID. + * @throws {BadRequestException} If the staff member is not active. + */ + async findActiveOrFail(id: number): Promise { + const staff = await this.findByIdOrFail(id); + + if (!staff.active) { + throw new BadRequestException(`Staff member with ID ${id} is not active`); + } + + return staff; + } + + /** + * Deactivates an active staff member. + * + * @param id - The ID of the staff member to deactivate. + * @returns The updated staff member. + * @throws {NotFoundException} If the staff member does not exist. + * @throws {BadRequestException} If the staff member is already inactive. + */ + async deactivate(id: number): Promise { + const staff = await this.findByIdOrFail(id); + + if (!staff.active) { + throw new BadRequestException( + `Staff member with ID ${id} is already inactive`, + ); + } + + staff.active = false; + + return this.repo.save(staff); + } + + /** + * Reactivates an inactive staff member. + * + * @param id - The ID of the staff member to activate. + * @returns The updated staff member. + * @throws {NotFoundException} If the staff member does not exist. + * @throws {BadRequestException} If the staff member is already active. + */ + async activate(id: number): Promise { + const staff = await this.findByIdOrFail(id); + + if (staff.active) { + throw new BadRequestException( + `Staff member with ID ${id} is already active`, + ); + } + + staff.active = true; + + return this.repo.save(staff); + } +} diff --git a/apps/backend/src/volunteers/volunteers.controller.ts b/apps/backend/src/volunteers/volunteers.controller.ts index c43c02e47..884d31779 100644 --- a/apps/backend/src/volunteers/volunteers.controller.ts +++ b/apps/backend/src/volunteers/volunteers.controller.ts @@ -168,12 +168,12 @@ export class VolunteersController { return this.volunteersService.findByIdOrFail(volunteerId); } - // TODO: restrict to coordinators once role guarding is added + // TODO: restrict to coordinators and staff once role guarding is added @Patch('/:volunteerId/coordinator-update-profile') @ApiOperation({ - summary: "Update a volunteer's profile as a coordinator", + summary: "Update a volunteer's profile as a coordinator or staff member", description: - 'Accepts every field a volunteer can edit, plus coordinator-only fields. Returns the full volunteer, including all fields hidden to them.', + 'Accepts every field a volunteer can edit, plus coordinator-only fields. Returns the full volunteer, including all fields hidden to them. Staff members can also use this endpoint (role guards will be added later).', }) @ApiParam({ name: 'volunteerId', From 5852699d7c857779e0c37f3d84d5c5b89fad053d Mon Sep 17 00:00:00 2001 From: Dalton Burkhart Date: Sun, 22 Nov 2026 13:53:49 -0500 Subject: [PATCH 2/5] Updated matching logic --- .../src/matches/dtos/create-match.dto.ts | 11 +++--- .../src/matches/matches.service.spec.ts | 11 +++--- apps/backend/src/matches/matches.service.ts | 34 ++++++++++++------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/apps/backend/src/matches/dtos/create-match.dto.ts b/apps/backend/src/matches/dtos/create-match.dto.ts index a34869fb5..08de9712d 100644 --- a/apps/backend/src/matches/dtos/create-match.dto.ts +++ b/apps/backend/src/matches/dtos/create-match.dto.ts @@ -1,9 +1,9 @@ import { IsInt, - IsOptional, IsPositive, MaxLength, Validate, + ValidateIf, ValidatorConstraint, ValidatorConstraintInterface, ValidationArguments, @@ -14,9 +14,8 @@ import { IsNonEmptyString } from '../../utils/decorators/is-non-empty-string.dec class ExactlyOneApplicantConstraint implements ValidatorConstraintInterface { validate(_: unknown, args: ValidationArguments): boolean { const obj = args.object as CreateMatchDto; - const hasVolunteer = - obj.volunteerId !== undefined && obj.volunteerId !== null; - const hasStaff = obj.staffId !== undefined && obj.staffId !== null; + const hasVolunteer = obj.volunteerId !== undefined; + const hasStaff = obj.staffId !== undefined; return (hasVolunteer && !hasStaff) || (!hasVolunteer && hasStaff); } @@ -26,13 +25,13 @@ class ExactlyOneApplicantConstraint implements ValidatorConstraintInterface { } export class CreateMatchDto { - @IsOptional() + @ValidateIf((o) => o.volunteerId !== undefined) @IsInt() @IsPositive() @Validate(ExactlyOneApplicantConstraint) volunteerId?: number; - @IsOptional() + @ValidateIf((o) => o.staffId !== undefined) @IsInt() @IsPositive() staffId?: number; diff --git a/apps/backend/src/matches/matches.service.spec.ts b/apps/backend/src/matches/matches.service.spec.ts index b4c8a1137..91a6506e6 100644 --- a/apps/backend/src/matches/matches.service.spec.ts +++ b/apps/backend/src/matches/matches.service.spec.ts @@ -371,15 +371,14 @@ describe('MatchesService', () => { service.create({ volunteerId: 999, chameleonAnimalId: 'A42' }), ).rejects.toThrow(NotFoundException); - expect(animalsService.findByChameleonIdOrFail).not.toHaveBeenCalled(); + expect(animalsService.findByChameleonIdOrFail).toHaveBeenCalledWith( + 'A42', + ); expect(matchRepo.save).not.toHaveBeenCalled(); expect(emailsService.sendEmail).not.toHaveBeenCalled(); }); - it('throws when the animal does not exist, after checking the volunteer', async () => { - volunteersService.findActiveOrFail.mockResolvedValue( - volunteerWithCoordinator, - ); + it('throws when the animal does not exist, before checking the volunteer', async () => { animalsService.findByChameleonIdOrFail.mockRejectedValue( new NotFoundException('Animal with Chameleon ID A999 not found'), ); @@ -390,10 +389,10 @@ describe('MatchesService', () => { new NotFoundException('Animal with Chameleon ID A999 not found'), ); - expect(volunteersService.findActiveOrFail).toHaveBeenCalledWith(1); expect(animalsService.findByChameleonIdOrFail).toHaveBeenCalledWith( 'A999', ); + expect(volunteersService.findActiveOrFail).not.toHaveBeenCalled(); expect(matchRepo.save).not.toHaveBeenCalled(); expect(emailsService.sendEmail).not.toHaveBeenCalled(); }); diff --git a/apps/backend/src/matches/matches.service.ts b/apps/backend/src/matches/matches.service.ts index b65e090b8..fc922e2d6 100644 --- a/apps/backend/src/matches/matches.service.ts +++ b/apps/backend/src/matches/matches.service.ts @@ -69,16 +69,22 @@ export class MatchesService { return match; } - await this.staffService.findActiveOrFail(dto.staffId!); - - return this.repo.save( - this.repo.create({ - volunteerId: null, - staffId: dto.staffId!, - chameleonAnimalId: dto.chameleonAnimalId, - status: MatchStatus.PENDING, - deniedReason: null, - }), + if (dto.staffId) { + await this.staffService.findActiveOrFail(dto.staffId); + + return this.repo.save( + this.repo.create({ + volunteerId: null, + staffId: dto.staffId, + chameleonAnimalId: dto.chameleonAnimalId, + status: MatchStatus.PENDING, + deniedReason: null, + }), + ); + } + + throw new BadRequestException( + 'Exactly one of volunteerId or staffId must be provided', ); } @@ -233,7 +239,7 @@ export class MatchesService { status: MatchStatus.PENDING, matchId: Not(id), }, - relations: ['volunteer'], + relations: ['volunteer', 'staff'], }); match.status = MatchStatus.ACTIVE; @@ -251,7 +257,11 @@ export class MatchesService { const applicantEmails = [ ...new Set( - otherMatches.map((otherMatch) => otherMatch.volunteer.email), + otherMatches.map((otherMatch) => + otherMatch.volunteer + ? otherMatch.volunteer.email + : otherMatch.staff!.email, + ), ), ]; From 331c4fbf5303efb086f1dee6b29a537725cd04ff Mon Sep 17 00:00:00 2001 From: Dalton Burkhart Date: Sun, 22 Nov 2026 14:27:56 -0500 Subject: [PATCH 3/5] Fixed tests --- apps/backend/src/matches/matches.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/backend/src/matches/matches.service.spec.ts b/apps/backend/src/matches/matches.service.spec.ts index 91a6506e6..6b477de87 100644 --- a/apps/backend/src/matches/matches.service.spec.ts +++ b/apps/backend/src/matches/matches.service.spec.ts @@ -535,7 +535,7 @@ describe('MatchesService', () => { _value: 1, }), }, - relations: ['volunteer'], + relations: ['volunteer', 'staff'], }); }); From 1d5860eb06420efbe8d64d18bad3c78bf0f4a5d5 Mon Sep 17 00:00:00 2001 From: Dalton Burkhart Date: Sun, 22 Nov 2026 16:15:50 -0500 Subject: [PATCH 4/5] Addressed comments --- .../src/matches/dtos/create-match.dto.ts | 28 ++--------- .../validators/exactly-one.validator.spec.ts | 48 +++++++++++++++++++ .../dtos/validators/exactly-one.validator.ts | 29 +++++++++++ .../1795372304908-AddStaffAndUpdateMatches.ts | 34 +++++-------- .../src/staff/dtos/create-staff.dto.ts | 19 ++------ .../src/staff/staff.controller.spec.ts | 6 +-- apps/backend/src/staff/staff.entity.ts | 28 ++--------- apps/backend/src/staff/staff.service.spec.ts | 36 ++++---------- apps/backend/src/staff/staff.service.ts | 1 + apps/backend/src/staff/staff.types.ts | 4 ++ .../src/volunteers/volunteers.entity.ts | 2 - 11 files changed, 115 insertions(+), 120 deletions(-) create mode 100644 apps/backend/src/matches/dtos/validators/exactly-one.validator.spec.ts create mode 100644 apps/backend/src/matches/dtos/validators/exactly-one.validator.ts create mode 100644 apps/backend/src/staff/staff.types.ts diff --git a/apps/backend/src/matches/dtos/create-match.dto.ts b/apps/backend/src/matches/dtos/create-match.dto.ts index 08de9712d..d496f3e7b 100644 --- a/apps/backend/src/matches/dtos/create-match.dto.ts +++ b/apps/backend/src/matches/dtos/create-match.dto.ts @@ -1,34 +1,12 @@ -import { - IsInt, - IsPositive, - MaxLength, - Validate, - ValidateIf, - ValidatorConstraint, - ValidatorConstraintInterface, - ValidationArguments, -} from 'class-validator'; +import { IsInt, IsPositive, MaxLength, ValidateIf } from 'class-validator'; import { IsNonEmptyString } from '../../utils/decorators/is-non-empty-string.decorator'; +import { ExactlyOne } from './validators/exactly-one.validator'; -@ValidatorConstraint({ name: 'exactlyOneApplicant', async: false }) -class ExactlyOneApplicantConstraint implements ValidatorConstraintInterface { - validate(_: unknown, args: ValidationArguments): boolean { - const obj = args.object as CreateMatchDto; - const hasVolunteer = obj.volunteerId !== undefined; - const hasStaff = obj.staffId !== undefined; - return (hasVolunteer && !hasStaff) || (!hasVolunteer && hasStaff); - } - - defaultMessage(): string { - return 'Exactly one of volunteerId or staffId must be provided'; - } -} - +@ExactlyOne(['volunteerId', 'staffId']) export class CreateMatchDto { @ValidateIf((o) => o.volunteerId !== undefined) @IsInt() @IsPositive() - @Validate(ExactlyOneApplicantConstraint) volunteerId?: number; @ValidateIf((o) => o.staffId !== undefined) diff --git a/apps/backend/src/matches/dtos/validators/exactly-one.validator.spec.ts b/apps/backend/src/matches/dtos/validators/exactly-one.validator.spec.ts new file mode 100644 index 000000000..66ecc8cc9 --- /dev/null +++ b/apps/backend/src/matches/dtos/validators/exactly-one.validator.spec.ts @@ -0,0 +1,48 @@ +import { validate } from 'class-validator'; +import { ExactlyOne } from './exactly-one.validator'; + +@ExactlyOne(['a', 'b']) +class TestDto { + a?: number; + b?: number; +} + +describe('ExactlyOne', () => { + it('passes when only the first field is provided', async () => { + const dto = Object.assign(new TestDto(), { a: 1 }); + + expect(await validate(dto)).toHaveLength(0); + }); + + it('passes when only the second field is provided', async () => { + const dto = Object.assign(new TestDto(), { b: 2 }); + + expect(await validate(dto)).toHaveLength(0); + }); + + it('fails when both fields are provided', async () => { + const dto = Object.assign(new TestDto(), { a: 1, b: 2 }); + const errors = await validate(dto); + + expect(errors).toHaveLength(1); + expect(errors[0].constraints).toEqual({ + exactlyOne: 'Exactly one of a, b must be provided', + }); + }); + + it('fails when neither field is provided', async () => { + const errors = await validate(new TestDto()); + + expect(errors).toHaveLength(1); + expect(errors[0].constraints).toEqual({ + exactlyOne: 'Exactly one of a, b must be provided', + }); + }); + + it('fails when both fields are explicitly undefined', async () => { + const dto = Object.assign(new TestDto(), { a: undefined, b: undefined }); + const errors = await validate(dto); + + expect(errors).toHaveLength(1); + }); +}); diff --git a/apps/backend/src/matches/dtos/validators/exactly-one.validator.ts b/apps/backend/src/matches/dtos/validators/exactly-one.validator.ts new file mode 100644 index 000000000..2384f21b3 --- /dev/null +++ b/apps/backend/src/matches/dtos/validators/exactly-one.validator.ts @@ -0,0 +1,29 @@ +import { registerDecorator, ValidationArguments } from 'class-validator'; + +/** + * Class decorator that rejects the DTO unless exactly one of the given fields + * is provided (i.e. not undefined). + * + * It only checks presence. The decorators on each field still validate the + * values themselves. + */ +export function ExactlyOne( + fields: (keyof T & string)[], +): ClassDecorator { + return (target) => { + registerDecorator({ + name: 'exactlyOne', + target, + propertyName: 'exactlyOne', + validator: { + validate(_: unknown, args: ValidationArguments): boolean { + const dto = args.object as Record; + return fields.filter((f) => dto[f] !== undefined).length === 1; + }, + defaultMessage(): string { + return `Exactly one of ${fields.join(', ')} must be provided`; + }, + }, + }); + }; +} diff --git a/apps/backend/src/migrations/1795372304908-AddStaffAndUpdateMatches.ts b/apps/backend/src/migrations/1795372304908-AddStaffAndUpdateMatches.ts index eab53f4bb..e82d0661f 100644 --- a/apps/backend/src/migrations/1795372304908-AddStaffAndUpdateMatches.ts +++ b/apps/backend/src/migrations/1795372304908-AddStaffAndUpdateMatches.ts @@ -4,6 +4,10 @@ export class AddStaffAndUpdateMatches1795372304908 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + CREATE TYPE "staff_type_enum" AS ENUM ('Hospital', 'Shelter') + `); + await queryRunner.query(` CREATE TABLE "foster_staff" ( "staff_id" SERIAL PRIMARY KEY, @@ -18,10 +22,8 @@ export class AddStaffAndUpdateMatches1795372304908 "homebase" "homebase_enum" NOT NULL, "resident_animals" text NOT NULL, "notes" text, - "foster_type" "foster_type_enum"[] NOT NULL, - "completed_trainings" "foster_training_enum"[] NOT NULL DEFAULT '{}', "most_recent_waiver_signed" boolean NOT NULL, - "foster_type_preferences" "foster_type_enum"[] NOT NULL DEFAULT '{}', + "staff_type" "staff_type_enum" NOT NULL, "active" boolean NOT NULL, "cognito_sub" varchar(255) NOT NULL DEFAULT '', CONSTRAINT "UQ_foster_staff_email" UNIQUE ("email") @@ -42,18 +44,10 @@ export class AddStaffAndUpdateMatches1795372304908 await queryRunner.query(` ALTER TABLE "matches" - ALTER COLUMN "volunteer_id" DROP NOT NULL - `); - - await queryRunner.query(` - ALTER TABLE "matches" + ALTER COLUMN "volunteer_id" DROP NOT NULL, ADD COLUMN "staff_id" int, ADD CONSTRAINT "fk_matches_staff" FOREIGN KEY ("staff_id") - REFERENCES "foster_staff" ("staff_id") - `); - - await queryRunner.query(` - ALTER TABLE "matches" + REFERENCES "foster_staff" ("staff_id"), ADD CONSTRAINT "chk_matches_one_applicant" CHECK ( ("volunteer_id" IS NOT NULL AND "staff_id" IS NULL) OR ("volunteer_id" IS NULL AND "staff_id" IS NOT NULL) @@ -64,22 +58,16 @@ export class AddStaffAndUpdateMatches1795372304908 public async down(queryRunner: QueryRunner): Promise { await queryRunner.query(` ALTER TABLE "matches" - DROP CONSTRAINT "chk_matches_one_applicant" - `); - - await queryRunner.query(` - ALTER TABLE "matches" + DROP CONSTRAINT "chk_matches_one_applicant", DROP CONSTRAINT "fk_matches_staff", - DROP COLUMN "staff_id" - `); - - await queryRunner.query(` - ALTER TABLE "matches" + DROP COLUMN "staff_id", ALTER COLUMN "volunteer_id" SET NOT NULL `); await queryRunner.query(`DROP TABLE "staff_coordinator_assignments"`); await queryRunner.query(`DROP TABLE "foster_staff"`); + + await queryRunner.query(`DROP TYPE "staff_type_enum"`); } } diff --git a/apps/backend/src/staff/dtos/create-staff.dto.ts b/apps/backend/src/staff/dtos/create-staff.dto.ts index 68f1c3294..9d3d7d728 100644 --- a/apps/backend/src/staff/dtos/create-staff.dto.ts +++ b/apps/backend/src/staff/dtos/create-staff.dto.ts @@ -1,7 +1,4 @@ import { - ArrayNotEmpty, - ArrayUnique, - IsArray, IsEmail, IsEnum, IsNotEmpty, @@ -15,7 +12,7 @@ import { import { Transform } from 'class-transformer'; import { IsNonEmptyString } from '../../utils/decorators/is-non-empty-string.decorator'; import { Homebase } from '../../types'; -import { FosterTraining, FosterType } from '../../volunteers/volunteers.types'; +import { StaffType } from '../staff.types'; export class CreateStaffDto { @IsNonEmptyString() @@ -81,16 +78,6 @@ export class CreateStaffDto { @IsNonEmptyString() notes?: string | null; - @IsArray() - @ArrayNotEmpty() - @ArrayUnique() - @IsEnum(FosterType, { each: true }) - fosterType!: FosterType[]; - - @ValidateIf((_, value) => value !== undefined) - @IsArray() - @ArrayNotEmpty() - @ArrayUnique() - @IsEnum(FosterTraining, { each: true }) - completedTrainings?: FosterTraining[]; + @IsEnum(StaffType) + staffType!: StaffType; } diff --git a/apps/backend/src/staff/staff.controller.spec.ts b/apps/backend/src/staff/staff.controller.spec.ts index 677fb4a5f..a892ea9b8 100644 --- a/apps/backend/src/staff/staff.controller.spec.ts +++ b/apps/backend/src/staff/staff.controller.spec.ts @@ -4,7 +4,7 @@ import { StaffController } from './staff.controller'; import { StaffService } from './staff.service'; import { FosterStaff } from './staff.entity'; import { Homebase } from '../types'; -import { FosterType } from '../volunteers/volunteers.types'; +import { StaffType } from './staff.types'; import { CreateStaffDto } from './dtos/create-staff.dto'; import { ConfirmStaffDto } from './dtos/confirm-staff.dto'; @@ -30,7 +30,7 @@ describe('StaffController', () => { homebase: Homebase.BOSTON, residentAnimals: 'None', notes: null, - fosterType: [FosterType.DOG], + staffType: StaffType.SHELTER, } as CreateStaffDto; const confirmDto = { @@ -72,7 +72,7 @@ describe('StaffController', () => { homebase: dto.homebase, residentAnimals: dto.residentAnimals, notes: dto.notes, - fosterType: dto.fosterType, + staffType: dto.staffType, }; const created = { diff --git a/apps/backend/src/staff/staff.entity.ts b/apps/backend/src/staff/staff.entity.ts index 66b2408f8..4bb588a3f 100644 --- a/apps/backend/src/staff/staff.entity.ts +++ b/apps/backend/src/staff/staff.entity.ts @@ -5,15 +5,13 @@ import { OneToMany, ManyToMany, JoinTable, - Unique, } from 'typeorm'; import { Homebase } from '../types'; -import { FosterTraining, FosterType } from '../volunteers/volunteers.types'; +import { StaffType } from './staff.types'; import { FosterCoordinator } from '../coordinators/coordinators.entity'; import { Match } from '../matches/matches.entity'; @Entity('foster_staff') -@Unique('UQ_foster_staff_email', ['email']) export class FosterStaff { @PrimaryGeneratedColumn({ name: 'staff_id' }) staffId!: number; @@ -56,31 +54,11 @@ export class FosterStaff { @Column({ type: 'text', nullable: true }) notes!: string | null; - @Column({ name: 'foster_type', type: 'enum', enum: FosterType, array: true }) - fosterType!: FosterType[]; - - @Column({ - name: 'completed_trainings', - type: 'enum', - enum: FosterTraining, - enumName: 'foster_training_enum', - array: true, - default: () => "'{}'", - }) - completedTrainings!: FosterTraining[]; - @Column({ name: 'most_recent_waiver_signed', type: 'boolean' }) mostRecentWaiverSigned!: boolean; - @Column({ - name: 'foster_type_preferences', - type: 'enum', - enum: FosterType, - enumName: 'foster_type_enum', - array: true, - default: () => "'{}'", - }) - fosterTypePreferences!: FosterType[]; + @Column({ name: 'staff_type', type: 'enum', enum: StaffType }) + staffType!: StaffType; @Column({ type: 'boolean' }) active!: boolean; diff --git a/apps/backend/src/staff/staff.service.spec.ts b/apps/backend/src/staff/staff.service.spec.ts index fb61cbe51..880eb32f3 100644 --- a/apps/backend/src/staff/staff.service.spec.ts +++ b/apps/backend/src/staff/staff.service.spec.ts @@ -15,7 +15,7 @@ import { ConfirmStaffDto } from './dtos/confirm-staff.dto'; import { CognitoService } from '../aws/cognito/cognito.service'; import { CognitoRole } from '../aws/cognito/cognito.types'; import { Homebase } from '../types'; -import { FosterType } from '../volunteers/volunteers.types'; +import { StaffType } from './staff.types'; describe('StaffService', () => { let service: StaffService; @@ -23,7 +23,7 @@ describe('StaffService', () => { let cognitoService: jest.Mocked; let loggerSpy: jest.SpyInstance; - const dto: CreateStaffDto = { + const dto = { firstName: 'Jane', lastName: 'Doe', phone: '+16175551234', @@ -36,13 +36,13 @@ describe('StaffService', () => { homebase: Homebase.BOSTON, residentAnimals: 'None', notes: null, - fosterType: [FosterType.DOG], - }; + staffType: StaffType.SHELTER, + } as CreateStaffDto; - const confirmDto: ConfirmStaffDto = { + const confirmDto = { email: dto.email, code: '123456', - }; + } as ConfirmStaffDto; const staff = { staffId: 1, @@ -57,8 +57,9 @@ describe('StaffService', () => { homebase: dto.homebase, residentAnimals: dto.residentAnimals, notes: dto.notes, - fosterType: dto.fosterType, + staffType: dto.staffType, active: true, + mostRecentWaiverSigned: true, cognitoSub: 'cognito-sub-123', assignedCoordinators: [], } as FosterStaff; @@ -120,6 +121,7 @@ describe('StaffService', () => { expect.objectContaining({ email: dto.email, active: true, + mostRecentWaiverSigned: true, cognitoSub: 'cognito-sub-123', }), ); @@ -234,7 +236,7 @@ describe('StaffService', () => { expect(cognitoService.confirmUser).not.toHaveBeenCalled(); }); - it('propagates an invalid verification code error', async () => { + it('propagates errors from Cognito', async () => { const error = new BadRequestException('Invalid verification code'); repo.findOneBy.mockResolvedValue(staff); @@ -248,24 +250,6 @@ describe('StaffService', () => { CognitoRole.Staff, ); }); - - it('propagates an expired verification code error', async () => { - const error = new BadRequestException('Verification code expired'); - - repo.findOneBy.mockResolvedValue(staff); - cognitoService.confirmUser.mockRejectedValue(error); - - await expect(service.confirm(confirmDto)).rejects.toBe(error); - }); - - it('propagates Cognito server errors', async () => { - const error = new InternalServerErrorException('Failed to confirm user'); - - repo.findOneBy.mockResolvedValue(staff); - cognitoService.confirmUser.mockRejectedValue(error); - - await expect(service.confirm(confirmDto)).rejects.toBe(error); - }); }); describe('deactivate', () => { diff --git a/apps/backend/src/staff/staff.service.ts b/apps/backend/src/staff/staff.service.ts index edd18d153..4daefb377 100644 --- a/apps/backend/src/staff/staff.service.ts +++ b/apps/backend/src/staff/staff.service.ts @@ -58,6 +58,7 @@ export class StaffService { return await this.repo.save({ ...profile, active: true, + mostRecentWaiverSigned: true, cognitoSub, assignedCoordinators: [], }); diff --git a/apps/backend/src/staff/staff.types.ts b/apps/backend/src/staff/staff.types.ts new file mode 100644 index 000000000..2beb0c3c3 --- /dev/null +++ b/apps/backend/src/staff/staff.types.ts @@ -0,0 +1,4 @@ +export enum StaffType { + HOSPITAL = 'Hospital', + SHELTER = 'Shelter', +} diff --git a/apps/backend/src/volunteers/volunteers.entity.ts b/apps/backend/src/volunteers/volunteers.entity.ts index 879d868a5..6e04fae7c 100644 --- a/apps/backend/src/volunteers/volunteers.entity.ts +++ b/apps/backend/src/volunteers/volunteers.entity.ts @@ -5,7 +5,6 @@ import { OneToMany, ManyToMany, JoinTable, - Unique, } from 'typeorm'; import { Homebase } from '../types'; import { @@ -17,7 +16,6 @@ import { FosterCoordinator } from '../coordinators/coordinators.entity'; import { Match } from '../matches/matches.entity'; @Entity('foster_volunteers') -@Unique('UQ_foster_volunteers_email', ['email']) export class FosterVolunteer { @PrimaryGeneratedColumn({ name: 'volunteer_id' }) volunteerId!: number; From 9fc80a44390f8dfef763cfe1a1b2085256d47415 Mon Sep 17 00:00:00 2001 From: Dalton Burkhart Date: Sun, 22 Nov 2026 17:37:52 -0500 Subject: [PATCH 5/5] Added staff to sign in process --- .../src/migrations/1795372304908-AddStaffAndUpdateMatches.ts | 1 - apps/backend/src/staff/dtos/create-staff.dto.ts | 3 --- apps/backend/src/staff/staff.controller.spec.ts | 2 -- apps/backend/src/staff/staff.entity.ts | 3 --- apps/backend/src/staff/staff.service.spec.ts | 2 -- 5 files changed, 11 deletions(-) diff --git a/apps/backend/src/migrations/1795372304908-AddStaffAndUpdateMatches.ts b/apps/backend/src/migrations/1795372304908-AddStaffAndUpdateMatches.ts index e82d0661f..70b4c85b1 100644 --- a/apps/backend/src/migrations/1795372304908-AddStaffAndUpdateMatches.ts +++ b/apps/backend/src/migrations/1795372304908-AddStaffAndUpdateMatches.ts @@ -20,7 +20,6 @@ export class AddStaffAndUpdateMatches1795372304908 "city" varchar(255) NOT NULL, "zipcode" varchar(10) NOT NULL, "homebase" "homebase_enum" NOT NULL, - "resident_animals" text NOT NULL, "notes" text, "most_recent_waiver_signed" boolean NOT NULL, "staff_type" "staff_type_enum" NOT NULL, diff --git a/apps/backend/src/staff/dtos/create-staff.dto.ts b/apps/backend/src/staff/dtos/create-staff.dto.ts index 9d3d7d728..bc805df11 100644 --- a/apps/backend/src/staff/dtos/create-staff.dto.ts +++ b/apps/backend/src/staff/dtos/create-staff.dto.ts @@ -71,9 +71,6 @@ export class CreateStaffDto { @IsEnum(Homebase) homebase!: Homebase; - @IsNonEmptyString() - residentAnimals!: string; - @ValidateIf((_, value) => value !== undefined && value !== null) @IsNonEmptyString() notes?: string | null; diff --git a/apps/backend/src/staff/staff.controller.spec.ts b/apps/backend/src/staff/staff.controller.spec.ts index a892ea9b8..f1e9a1163 100644 --- a/apps/backend/src/staff/staff.controller.spec.ts +++ b/apps/backend/src/staff/staff.controller.spec.ts @@ -28,7 +28,6 @@ describe('StaffController', () => { city: 'Boston', zipcode: '02101', homebase: Homebase.BOSTON, - residentAnimals: 'None', notes: null, staffType: StaffType.SHELTER, } as CreateStaffDto; @@ -70,7 +69,6 @@ describe('StaffController', () => { city: dto.city, zipcode: dto.zipcode, homebase: dto.homebase, - residentAnimals: dto.residentAnimals, notes: dto.notes, staffType: dto.staffType, }; diff --git a/apps/backend/src/staff/staff.entity.ts b/apps/backend/src/staff/staff.entity.ts index 4bb588a3f..05fd6e478 100644 --- a/apps/backend/src/staff/staff.entity.ts +++ b/apps/backend/src/staff/staff.entity.ts @@ -48,9 +48,6 @@ export class FosterStaff { @Column({ type: 'enum', enum: Homebase }) homebase!: Homebase; - @Column({ name: 'resident_animals', type: 'text' }) - residentAnimals!: string; - @Column({ type: 'text', nullable: true }) notes!: string | null; diff --git a/apps/backend/src/staff/staff.service.spec.ts b/apps/backend/src/staff/staff.service.spec.ts index 8c7d6d095..39470fe50 100644 --- a/apps/backend/src/staff/staff.service.spec.ts +++ b/apps/backend/src/staff/staff.service.spec.ts @@ -34,7 +34,6 @@ describe('StaffService', () => { city: 'Boston', zipcode: '02101', homebase: Homebase.BOSTON, - residentAnimals: 'None', notes: null, staffType: StaffType.SHELTER, } as CreateStaffDto; @@ -55,7 +54,6 @@ describe('StaffService', () => { city: dto.city, zipcode: dto.zipcode, homebase: dto.homebase, - residentAnimals: dto.residentAnimals, notes: dto.notes, staffType: dto.staffType, active: true,