Skip to content
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

Pets #43

Merged
merged 2 commits into from
Feb 26, 2025
Merged

Pets #43

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/modules/health/patients/controllers/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe("Create patient e2e", () => {
id: expect.any(String),
name: "Nina",
birthdate: "2021-01-01",
sex: "FEMALE",
specie: "Dog",
breed: "German Shepherd",
});
Expand Down
4 changes: 2 additions & 2 deletions src/modules/health/patients/use-cases/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ describe("Create patient use case", () => {
const patient: CreatePatient = {
name: "Nina",
birthdate: "2021-01-01",
sex: "FEMALE",
medicalObservations:
"No prior medical conditions reported. Regular vaccinations up to date. Recent flea and tick prevention administered. Healthy and active upon initial examination.",
sex: "FEMALE",
breed: "German Shepherd",
specie: "Dog",
};
Expand All @@ -29,9 +29,9 @@ describe("Create patient use case", () => {
id: expect.any(String),
name: "Nina",
birthdate: "2021-01-01",
sex: "FEMALE",
medicalObservations:
"No prior medical conditions reported. Regular vaccinations up to date. Recent flea and tick prevention administered. Healthy and active upon initial examination.",
sex: "FEMALE",
breed: "German Shepherd",
specie: "Dog",
});
Expand Down
6 changes: 5 additions & 1 deletion src/modules/pet/pets/controllers/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe("Create pet e2e", () => {
const data: CreatePet = {
name: "Nina",
birthdate: "2021-01-01",
observations: "She's a very playful dog",
sex: "FEMALE",
observations: "She's a very playful dog",
speciesId: specie.id,
breedId: breed.id,
};
Expand All @@ -42,6 +42,7 @@ describe("Create pet e2e", () => {
id: expect.any(String),
name: "Nina",
birthdate: "2021-01-01",
sex: "FEMALE",
speciesId: specie.id,
breedId: breed.id,
});
Expand All @@ -64,6 +65,7 @@ describe("Create pet e2e", () => {
const data: CreatePet = {
name: "Nina",
birthdate: "2021-01-01",
sex: "FEMALE",
speciesId: "b38d7184-b9cf-4e79-acb6-6b7b8f797284", // Unregistered specie
breedId: breed.id,
};
Expand Down Expand Up @@ -93,6 +95,7 @@ describe("Create pet e2e", () => {
const data: CreatePet = {
name: "Nina",
birthdate: "2021-01-01",
sex: "FEMALE",
speciesId: specie.id,
breedId: "b38d7184-b9cf-4e79-acb6-6b7b8f797284", // Unregistered breed
};
Expand Down Expand Up @@ -133,6 +136,7 @@ describe("Create pet e2e", () => {
const data: CreatePet = {
name: "Nina",
birthdate: "2021-01-01",
sex: "FEMALE",
speciesId: specieDog.id,
breedId: catBreed.id,
};
Expand Down
4 changes: 4 additions & 0 deletions src/modules/pet/pets/controllers/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe("List pet e2e", () => {
const createPet: CreatePet = {
name: "Nina",
birthdate: "2021-01-01",
sex: "FEMALE",
speciesId: specie.id,
breedId: breed.id,
};
Expand Down Expand Up @@ -53,6 +54,7 @@ describe("List pet e2e", () => {
id: expect.any(String),
name: "Nina",
birthdate: "2021-01-01",
sex: "FEMALE",
speciesId: specie.id,
breedId: breed.id,
});
Expand Down Expand Up @@ -102,6 +104,7 @@ describe("List pet e2e", () => {
const createPet: CreatePet = {
name: `Nina-${i}`,
birthdate: "2021-01-01",
sex: "FEMALE",
speciesId: specie.id,
breedId: breed.id,
};
Expand Down Expand Up @@ -135,6 +138,7 @@ describe("List pet e2e", () => {
id: expect.any(String),
name: "Nina-10",
birthdate: "2021-01-01",
sex: "FEMALE",
speciesId: specie.id,
breedId: breed.id,
});
Expand Down
6 changes: 3 additions & 3 deletions src/modules/pet/pets/controllers/list.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Elysia from "elysia";
import { listPetSchema } from "../schema";
import { listPetsSchema } from "../schema";
import { makeListPetsUseCase } from "../factories/make-list";
import { SpecieNotFoundError } from "../../shared/errors/specie-not-found";
import { BreedNotFoundError } from "../../shared/errors/breed-not-found";
import { InvalidBreedSpecieError } from "../../shared/errors/invalid-breed-specie";

export const listPet = new Elysia()
export const listPets = new Elysia()
.error({
SpecieNotFoundError,
BreedNotFoundError,
Expand All @@ -21,6 +21,6 @@ export const listPet = new Elysia()
return pets;
},
{
query: listPetSchema,
query: listPetsSchema,
},
);
10 changes: 4 additions & 6 deletions src/modules/pet/pets/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ export const createPetSchema = t.Object({
name: t.String(),
birthdate: t.String({ format: "date" }),
observations: t.Optional(t.String()),
sex: t.Optional(
t.Union([t.Literal("MALE"), t.Literal("FEMALE"), t.Literal("UNKNOWN")], {
default: "UNKNOWN",
}),
),
sex: t.Union([t.Literal("MALE"), t.Literal("FEMALE"), t.Literal("UNKNOWN")], {
default: "UNKNOWN",
}),
breedId: t.String({
format: "uuid",
}),
Expand All @@ -17,7 +15,7 @@ export const createPetSchema = t.Object({
}),
});

export const listPetSchema = t.Object({
export const listPetsSchema = t.Object({
page: t.Integer({ minimum: 1 }),
pageSize: t.Integer({ minimum: 1, maximum: 100, default: 10 }),
});
7 changes: 5 additions & 2 deletions src/modules/pet/pets/use-cases/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ describe("Create pet use case", () => {
const pet: CreatePet = {
name: "Nina",
birthdate: "2021-01-01",
observations: "She's a very playful dog",
sex: "FEMALE",
observations: "She's a very playful dog",
breedId: breed.id,
speciesId: specie.id,
};
Expand All @@ -50,8 +50,8 @@ describe("Create pet use case", () => {
id: expect.any(String),
name: "Nina",
birthdate: "2021-01-01",
observations: "She's a very playful dog",
sex: "FEMALE",
observations: "She's a very playful dog",
breedId: breed.id,
speciesId: specie.id,
});
Expand All @@ -70,6 +70,7 @@ describe("Create pet use case", () => {
const pet: CreatePet = {
name: "Nina",
birthdate: "2021-01-01",
sex: "FEMALE",
breedId: breed.id,
speciesId: "NonExistentSpecieId",
};
Expand All @@ -87,6 +88,7 @@ describe("Create pet use case", () => {
const pet: CreatePet = {
name: "Nina",
birthdate: "2021-01-01",
sex: "FEMALE",
breedId: "NonExistentBreedId",
speciesId: specie.id,
};
Expand All @@ -113,6 +115,7 @@ describe("Create pet use case", () => {
const pet: CreatePet = {
name: "Nina",
birthdate: "2021-01-01",
sex: "FEMALE",
speciesId: specieDog.id,
breedId: breedCat.id,
};
Expand Down
4 changes: 2 additions & 2 deletions src/modules/pet/pets/use-cases/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ describe("Create pet use case", () => {
const pet: CreatePet = {
name: "Nina",
birthdate: "2021-01-01",
observations: "She's a very playful dog",
sex: "FEMALE",
observations: "She's a very playful dog",
breedId: breed.id,
speciesId: specie.id,
};
Expand All @@ -52,8 +52,8 @@ describe("Create pet use case", () => {
id: expect.any(String),
name: "Nina",
birthdate: "2021-01-01",
observations: "She's a very playful dog",
sex: "FEMALE",
observations: "She's a very playful dog",
breedId: breed.id,
speciesId: specie.id,
});
Expand Down
4 changes: 2 additions & 2 deletions src/modules/pet/shared/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import Elysia from "elysia";
import { createPet } from "../pets/controllers/create";
import { createBreed } from "../breeds/controllers/create";
import { createSpecie } from "../species/controllers/create";
import { listPet } from "../pets/controllers/list";
import { listPets } from "../pets/controllers/list";

const petRoutes = new Elysia();

petRoutes.group("pet", (app) =>
app.use(createPet).use(listPet).use(createBreed).use(createSpecie),
app.use(createPet).use(listPets).use(createBreed).use(createSpecie),
);

export default petRoutes;