Skip to content

Commit

Permalink
create pet finished (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrobaina authored Oct 31, 2023
1 parent 4818b9b commit 6513cba
Show file tree
Hide file tree
Showing 26 changed files with 848 additions and 158 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@types/bcrypt": "^5.0.0",
"@types/body-parser": "^1.19.2",
"@types/google-cloud__storage": "^2.3.1",
"@types/qrcode": "^1.5.4",
"@types/sharp": "^0.32.0",
"aws-sdk": "^2.814.0",
"bcrypt": "^5.0.0",
Expand All @@ -35,7 +36,8 @@
"nodemailer": "^6.7.2",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
"prisma": "^5.3.0"
"prisma": "^5.3.0",
"qrcode": "^1.5.3"
},
"devDependencies": {
"@types/cors": "^2.8.8",
Expand Down
51 changes: 26 additions & 25 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
import express from 'express';
import express from 'express'
// morgan sirve para ver las peticiones a la api cuando esta corriendo el servidor en la consola
import morgan from 'morgan';
import dotenv from 'dotenv';
import morgan from 'morgan'
import dotenv from 'dotenv'
// sirve para comunicarnos con otros tipos de servidores de desarrollo
import cors from 'cors';
import passport from 'passport';
import passportMiddleware from './middlewares/passport';
import routes from './routes';
import path from 'path';
import { config } from './config/config';
import cors from 'cors'
import passport from 'passport'
import passportMiddleware from './middlewares/passport'
import routes from './routes'
import path from 'path'
import { config } from './config/config'

// initializations
const app = express();
dotenv.config();
const app = express()
dotenv.config()

const port = config.PORT;
const port = config.PORT
// settings
app.set('port', port);
app.set('port', port)

// middleware

app.use(morgan('dev'));
app.use(morgan('dev'));
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'uploads')));
app.use(passport.initialize());
passport.use(passportMiddleware);
app.use(morgan('dev'))
app.use(morgan('dev'))
app.use(cors())
app.use(express.json())
app.use('/uploads', express.static(path.join(__dirname, 'uploads')))
app.use(express.urlencoded({ extended: false }))
// app.use(express.static(path.join(__dirname, 'uploads')));
app.use(passport.initialize())
passport.use(passportMiddleware)

// routes
app.get('/', (req, res) => {
res.send(`Welcome to ${config.APP_NAME}`);
});
res.send(`Welcome to ${config.APP_NAME}`)
})

app.use(routes);
app.use(routes)

export default app;
export default app
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Warnings:
- You are about to drop the column `veterinarian` on the `MedicalRecord` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "MedicalRecord" DROP COLUMN "veterinarian",
ADD COLUMN "vetId" TEXT;

-- AlterTable
ALTER TABLE "User" ADD COLUMN "description" TEXT;

-- AddForeignKey
ALTER TABLE "MedicalRecord" ADD CONSTRAINT "MedicalRecord_vetId_fkey" FOREIGN KEY ("vetId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:
- The `status` column on the `PetVaccine` table would be dropped and recreated. This will lead to data loss if there is data in the column.
*/
-- CreateEnum
CREATE TYPE "VaccineStatus" AS ENUM ('DONE', 'PENDING', 'NOT_APPLICABLE');

-- AlterTable
ALTER TABLE "PetVaccine" DROP COLUMN "status",
ADD COLUMN "status" "VaccineStatus" NOT NULL DEFAULT 'PENDING';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Warnings:
- Added the required column `title` to the `MedicalRecord` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "MedicalRecord" ADD COLUMN "title" TEXT NOT NULL;

-- AlterTable
ALTER TABLE "Pet" ADD COLUMN "createdBy" TEXT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Pet" ADD COLUMN "qrCode" TEXT;
22 changes: 16 additions & 6 deletions src/database/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ model User {
locationId String?
location Location? @relation(fields: [locationId], references: [id])
image String?
description String?
username String? @unique
email String @unique
updatedAt DateTime @updatedAt
Expand Down Expand Up @@ -60,8 +61,10 @@ model Pet {
age String // Baby, Young, Adult, Senior
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
qrCode String?
adoptedBy String? // Foreign Key for Adopter
shelterId String? // Foreign Key for Shelter
createdBy String? // Foreign Key for Volunteer
location Location? @relation(fields: [locationId], references: [id])
Adopter User? @relation(name: "AdoptedPets", fields: [adoptedBy], references: [id])
Shelter User? @relation(name: "ShelterPets", fields: [shelterId], references: [id])
Expand All @@ -81,12 +84,12 @@ model PetsCaredByVolunteer {
}

model PetVaccine {
id String @id @default(cuid())
petId String @map("pet_id")
vaccineId String @map("vaccine_id")
status String // NOT_APPLICABLE, PENDING, DONE
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
id String @id @default(cuid())
petId String @map("pet_id")
vaccineId String @map("vaccine_id")
status VaccineStatus @default(PENDING)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Pet Pet @relation(fields: [petId], references: [id])
Vaccine Vaccine @relation(fields: [vaccineId], references: [id])
Expand All @@ -107,6 +110,7 @@ model MedicalRecord {
petId String
Pet Pet @relation(fields: [petId], references: [id])
date DateTime @default(now())
title String // Title of the visit/appointment
description String // Brief description or reason for the visit/appointment
diagnosis String? // Diagnosis made by the veterinarian
treatment String? // Treatment provided or prescribed
Expand Down Expand Up @@ -152,3 +156,9 @@ enum Role {
SHELTER
ADMIN
}

enum VaccineStatus {
DONE
PENDING
NOT_APPLICABLE
}
21 changes: 16 additions & 5 deletions src/database/prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { PrismaClient } from '@prisma/client'
import { PrismaClient, VaccineStatus } from '@prisma/client'
import { createPets } from './utils/createPets'
import { createVaccines } from './utils/createVaccunes'
import { createUsers } from './utils/createUsers'

const prisma = new PrismaClient()

async function main() {
await createUsers()

await createPets()

const pets = await prisma.pet.findMany({})
Expand All @@ -28,19 +31,23 @@ async function main() {

const catVaccineData = catVaccineId.map((vaccineId) => ({
vaccineId: vaccineId,
status: 'pending',
status: VaccineStatus.PENDING,
}))

const dogsVaccineData = dogVaccineId.map((vaccineId) => ({
vaccineId: vaccineId,
status: 'pending',
status: VaccineStatus.PENDING,
}))

for (let i = 0; i < pets.length; i++) {
if (pets[i].category === 'cat') {
for (let i = 0; i < catVaccineData.length; i++) {
await prisma.petVaccine.create({
data: { ...catVaccineData[i], petId: pets[i].id },
data: {
petId: pets[i].id,
status: catVaccineData[i].status,
vaccineId: catVaccineData[i].vaccineId,
},
})
}
}
Expand All @@ -50,7 +57,11 @@ async function main() {
if (pets[i].category === 'dog') {
for (let i = 0; i < dogsVaccineData.length; i++) {
await prisma.petVaccine.create({
data: { ...dogsVaccineData[i], petId: pets[i].id },
data: {
vaccineId: dogsVaccineData[i].vaccineId,
status: dogsVaccineData[i].status,
petId: pets[i].id,
},
})
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/database/prisma/utils/createPets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,31 @@ export const createPets = async () => {

const petDescription = `He boasts tufted ears, a hallmark of his breed, and a long, bushy tail reminiscent of a luxurious feather duster. With a weight tipping the scale at 18 pounds, he is undeniably large but wears his size with elegance and grace. He possesses a gentle disposition, often seeking the warmth of a human lap or the soft notes of a lullaby sung by his favorite humans. Despite his calm demeanor, Whiskers has a playful side. He's particularly fond of feather toys and laser pointers, often displaying the agility and stealth of a panther when engaged in play.`

const usersShelter = await prisma.user.findMany({
where: {
role: 'SHELTER',
},
})

const usersAdopter = await prisma.user.findMany({
where: {
role: 'ADOPTER',
},
})

for (let i = 0; i < 14; i++) {
const randomTypeIndex = Math.floor(Math.random() * category.length)
const randomBreedIndex = Math.floor(Math.random() * breed.length)
const randomAgeIndex = Math.floor(Math.random() * age.length)
const randomGenderIndex = Math.floor(Math.random() * gender.length)
const randomSizeIndex = Math.floor(Math.random() * size.length)
const randomPetNamesIndex = Math.floor(Math.random() * petNames.length)
const randomUserAdopterIndex = Math.floor(
Math.random() * usersAdopter.length,
)
const randomUserShelterIndex = Math.floor(
Math.random() * usersShelter.length,
)

await prisma.pet.create({
data: {
Expand All @@ -77,6 +95,8 @@ export const createPets = async () => {
gender: gender[randomGenderIndex],
size: size[randomSizeIndex],
description: petDescription,
adoptedBy: usersAdopter[randomUserAdopterIndex].id,
shelterId: usersShelter[randomUserShelterIndex].id,
},
})
}
Expand Down
Loading

0 comments on commit 6513cba

Please sign in to comment.