Repository navigation
MSPCA-56 Add pets and household details to foster volunteers #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6420da1
MSPCA-56: add pets table and household details to volunteers
Juwang110 a53201a
MSPCA-56: accept pets and household details in volunteer DTOs
Juwang110 2543159
MSPCA-56: enforce children rule and replace pets on volunteer updates
Juwang110 285635c
MSPCA-56: cap pets and children, load pets only where used, clear age…
Juwang110 e510398
MSPCA-56: address review conventions in tests, docs and Swagger
Juwang110 8a46338
MSPCA-56: always load pets with the volunteer so every endpoint retur…
Juwang110 7401ba6
MSPCA-56: drop caps on pet and children counts and ages, remove migra…
Juwang110 4c4d356
Merge main into jw/mspca-56-volunteer-pets
Juwang110 62313a8
MSPCA-56: add livelyNeighborhood and address review feedback
Juwang110 3305f9c
Merge remote-tracking branch 'origin/main' into jw/mspca-56-volunteer…
Juwang110 c3dcc08
MSPCA-56: address second-round review comments
Juwang110 43b407e
Merged main
dburkhart07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
apps/backend/src/migrations/1794408338094-AddPetsAndHouseholdDetails.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
|
||
| export class AddPetsAndHouseholdDetails1794408338094 | ||
| implements MigrationInterface | ||
| { | ||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(` | ||
| CREATE TABLE "pets" ( | ||
| "pet_id" SERIAL PRIMARY KEY, | ||
| "volunteer_id" int NOT NULL | ||
| REFERENCES "foster_volunteers" ("volunteer_id") ON DELETE CASCADE, | ||
| "age_year" int NOT NULL, | ||
| "age_month" int NOT NULL, | ||
| "species" "foster_type_enum" NOT NULL, | ||
| "breed" varchar(255) NOT NULL, | ||
| CONSTRAINT "CHK_pets_age_year" CHECK ("age_year" >= 0), | ||
| CONSTRAINT "CHK_pets_age_month" CHECK ("age_month" BETWEEN 0 AND 11) | ||
| ) | ||
| `); | ||
|
|
||
| await queryRunner.query(` | ||
| ALTER TABLE "foster_volunteers" | ||
| ADD COLUMN "has_children" boolean NOT NULL DEFAULT false, | ||
| ADD COLUMN "children_ages" int[] NOT NULL DEFAULT '{}', | ||
| ADD COLUMN "has_separate_foster_room" boolean NOT NULL DEFAULT false, | ||
| ADD COLUMN "lively_neighborhood" boolean NOT NULL DEFAULT false, | ||
| DROP COLUMN "resident_animals" | ||
| `); | ||
|
|
||
| await queryRunner.query(` | ||
| ALTER TABLE "foster_volunteers" | ||
| ALTER COLUMN "has_children" DROP DEFAULT, | ||
| ALTER COLUMN "has_separate_foster_room" DROP DEFAULT, | ||
| ALTER COLUMN "lively_neighborhood" DROP DEFAULT, | ||
| ADD CONSTRAINT "CHK_foster_volunteers_children_ages" CHECK ( | ||
| ("has_children" AND cardinality("children_ages") > 0) | ||
| OR (NOT "has_children" AND cardinality("children_ages") = 0) | ||
| ), | ||
| ADD CONSTRAINT "CHK_foster_volunteers_children_ages_nonnegative" | ||
| CHECK (0 <= ALL ("children_ages")) | ||
| `); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(` | ||
| ALTER TABLE "foster_volunteers" | ||
| DROP CONSTRAINT "CHK_foster_volunteers_children_ages_nonnegative", | ||
| DROP CONSTRAINT "CHK_foster_volunteers_children_ages", | ||
| DROP COLUMN "lively_neighborhood", | ||
| DROP COLUMN "has_separate_foster_room", | ||
| DROP COLUMN "children_ages", | ||
| DROP COLUMN "has_children", | ||
| ADD COLUMN "resident_animals" text NOT NULL DEFAULT '' | ||
| `); | ||
|
|
||
| await queryRunner.query(` | ||
| ALTER TABLE "foster_volunteers" ALTER COLUMN "resident_animals" DROP DEFAULT | ||
|
dburkhart07 marked this conversation as resolved.
Resolved
|
||
| `); | ||
|
|
||
| await queryRunner.query(`DROP TABLE "pets"`); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { IsEnum, IsInt, Max, MaxLength, Min } from 'class-validator'; | ||
|
Juwang110 marked this conversation as resolved.
Resolved
|
||
| import { FosterType } from '../../volunteers/volunteers.types'; | ||
| import { IsNonEmptyString } from '../../utils/decorators/is-non-empty-string.decorator'; | ||
|
|
||
| export class PetDto { | ||
| @IsInt() | ||
| @Min(0) | ||
| ageYear!: number; | ||
|
|
||
| @IsInt() | ||
| @Min(0) | ||
| @Max(11) | ||
| ageMonth!: number; | ||
|
|
||
| @IsEnum(FosterType) | ||
| species!: FosterType; | ||
|
|
||
| @IsNonEmptyString() | ||
| @MaxLength(255) | ||
| breed!: string; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { | ||
| Entity, | ||
| PrimaryGeneratedColumn, | ||
| Column, | ||
| ManyToOne, | ||
| JoinColumn, | ||
| Check, | ||
| } from 'typeorm'; | ||
| import { FosterVolunteer } from '../volunteers/volunteers.entity'; | ||
| import { FosterType } from '../volunteers/volunteers.types'; | ||
|
|
||
| @Entity('pets') | ||
| @Check('CHK_pets_age_year', '"age_year" >= 0') | ||
| @Check('CHK_pets_age_month', '"age_month" BETWEEN 0 AND 11') | ||
| export class Pet { | ||
| @PrimaryGeneratedColumn({ name: 'pet_id' }) | ||
| petId!: number; | ||
|
|
||
| @ManyToOne(() => FosterVolunteer, (volunteer) => volunteer.pets, { | ||
| nullable: false, | ||
| onDelete: 'CASCADE', | ||
| orphanedRowAction: 'delete', | ||
| }) | ||
| @JoinColumn({ name: 'volunteer_id' }) | ||
| volunteer!: FosterVolunteer; | ||
|
|
||
| @Column({ name: 'volunteer_id' }) | ||
| volunteerId!: number; | ||
|
|
||
| @Column({ name: 'age_year', type: 'int' }) | ||
| ageYear!: number; | ||
|
|
||
| @Column({ name: 'age_month', type: 'int' }) | ||
| ageMonth!: number; | ||
|
|
||
| @Column({ type: 'enum', enum: FosterType, enumName: 'foster_type_enum' }) | ||
| species!: FosterType; | ||
|
|
||
| @Column({ type: 'varchar', length: 255 }) | ||
| breed!: string; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.