Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into jessica/donations-routes
Browse files Browse the repository at this point in the history
  • Loading branch information
jessica2673 committed Mar 10, 2024
2 parents d15d89b + 3dd588f commit cd30bec
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 15 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# don-efficace
# don-efficace

# Useful commands to run prisma
"npx prisma db push" to push
"npx prisma studio" to run prisma
4 changes: 2 additions & 2 deletions backend/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@prisma/client": "4.15.0",
"@prisma/client": "^5.10.2",
"@types/graphql-upload": "^8.0.6",
"@types/json2csv": "^5.0.3",
"@types/multer": "^1.4.6",
Expand Down Expand Up @@ -72,7 +72,7 @@
"mongodb-memory-server": "^6.9.6",
"nodemon": "^2.0.7",
"prettier": "^2.2.1",
"prisma": "^4.15.0",
"prisma": "^5.10.2",
"ts-jest": "^27.0.3",
"typescript": "^4.1.5"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
-- CreateEnum
CREATE TYPE "CauseEnum" AS ENUM ('ENVIRONMENT', 'EDUCATION', 'HEALTH');

-- CreateTable
CREATE TABLE "User" (
"id" SERIAL NOT NULL,
"first_name" TEXT NOT NULL,
"last_name" TEXT NOT NULL,
"full_addr" TEXT NOT NULL,
"email_addr" TEXT NOT NULL,
"opt_in" BOOLEAN NOT NULL,
"date_created" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"is_admin" BOOLEAN NOT NULL DEFAULT false,

CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Donation" (
"id" SERIAL NOT NULL,
"user_id" INTEGER NOT NULL,
"amount" DOUBLE PRECISION NOT NULL,
"donation_date" TIMESTAMP(3) NOT NULL,
"is_recurring" BOOLEAN NOT NULL,
"confirmation_email_sent" BOOLEAN NOT NULL,

CONSTRAINT "Donation_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "CauseDonation" (
"donation_id" INTEGER NOT NULL,
"cause_id" INTEGER NOT NULL,

CONSTRAINT "CauseDonation_pkey" PRIMARY KEY ("donation_id","cause_id")
);

-- CreateTable
CREATE TABLE "Cause" (
"id" SERIAL NOT NULL,
"name" "CauseEnum" NOT NULL,
"description" TEXT NOT NULL,

CONSTRAINT "Cause_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "NPO" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"contact_information" TEXT NOT NULL,
"cause_id" INTEGER NOT NULL,
"item_id" INTEGER,

CONSTRAINT "NPO_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Item" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"impact_ratio" DOUBLE PRECISION NOT NULL,

CONSTRAINT "Item_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "User_email_addr_key" ON "User"("email_addr");

-- AddForeignKey
ALTER TABLE "Donation" ADD CONSTRAINT "Donation_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CauseDonation" ADD CONSTRAINT "CauseDonation_donation_id_fkey" FOREIGN KEY ("donation_id") REFERENCES "Donation"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "CauseDonation" ADD CONSTRAINT "CauseDonation_cause_id_fkey" FOREIGN KEY ("cause_id") REFERENCES "Cause"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "NPO" ADD CONSTRAINT "NPO_cause_id_fkey" FOREIGN KEY ("cause_id") REFERENCES "Cause"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "NPO" ADD CONSTRAINT "NPO_item_id_fkey" FOREIGN KEY ("item_id") REFERENCES "Item"("id") ON DELETE SET NULL ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions backend/typescript/prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
18 changes: 6 additions & 12 deletions backend/typescript/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,27 @@ model CauseDonation {
// Cause and NPO: One-to-Many: A single cause can be associated with many NPOs, and each NPO is linked to one cause
model Cause {
id Int @id @default(autoincrement())
name CauseEnum
name String
description String
npos NPO[]
Donation CauseDonation[]
}

enum CauseEnum {
ENVIRONMENT
EDUCATION
HEALTH
}

// NPO and Item: Many-to-One: One NPO can have one item, and each item can be associated with multiple NPOs
// example: multiple NPOs can donate trees (item)
// NPO and Item: One-to-One: One NPO can have one item, and each item can be associated with one NPOs
model NPO {
id Int @id @default(autoincrement())
name String
contact_information String
cause Cause @relation(fields: [cause_id], references: [id])
cause_id Int
item Item? @relation(fields: [item_id], references: [id])
item_id Int?
item Item? @relation("NPOItem", fields: [item_id], references: [id])
item_id Int? @unique
}

model Item {
id Int @id @default(autoincrement())
name String
impact_ratio Float
npo NPO[]
npo NPO? @relation("NPOItem")
npo_id Int? @unique
}
48 changes: 48 additions & 0 deletions backend/typescript/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,47 @@
"@nodelib/fs.scandir" "2.1.4"
fastq "^1.6.0"

"@prisma/client@^5.10.2":
version "5.10.2"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.10.2.tgz#e087b40a4de8e3171eb9cbf0a873465cd2068e17"
integrity sha512-ef49hzB2yJZCvM5gFHMxSFL9KYrIP9udpT5rYo0CsHD4P9IKj473MbhU1gjKKftiwWBTIyrt9jukprzZXazyag==

"@prisma/[email protected]":
version "5.10.2"
resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-5.10.2.tgz#74be81d8969978f4d53c1b4e76d61f04bfbc3951"
integrity sha512-bkBOmH9dpEBbMKFJj8V+Zp8IZHIBjy3fSyhLhxj4FmKGb/UBSt9doyfA6k1UeUREsMJft7xgPYBbHSOYBr8XCA==

"@prisma/engines-version@5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9":
version "5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9.tgz#1502335d4d72d2014cb25b8ad8a740a3a13400ea"
integrity sha512-uCy/++3Jx/O3ufM+qv2H1L4tOemTNqcP/gyEVOlZqTpBvYJUe0tWtW0y3o2Ueq04mll4aM5X3f6ugQftOSLdFQ==

"@prisma/[email protected]":
version "5.10.2"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.10.2.tgz#a4851d90f76ad6d22e783d5fd2e2e8c0640f1e81"
integrity sha512-HkSJvix6PW8YqEEt3zHfCYYJY69CXsNdhU+wna+4Y7EZ+AwzeupMnUThmvaDA7uqswiHkgm5/SZ6/4CStjaGmw==
dependencies:
"@prisma/debug" "5.10.2"
"@prisma/engines-version" "5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9"
"@prisma/fetch-engine" "5.10.2"
"@prisma/get-platform" "5.10.2"

"@prisma/[email protected]":
version "5.10.2"
resolved "https://registry.yarnpkg.com/@prisma/fetch-engine/-/fetch-engine-5.10.2.tgz#a061f6727d395c7033b55f9c6e92f8741a70d5c5"
integrity sha512-dSmXcqSt6DpTmMaLQ9K8ZKzVAMH3qwGCmYEZr/uVnzVhxRJ1EbT/w2MMwIdBNq1zT69Rvh0h75WMIi0mrIw7Hg==
dependencies:
"@prisma/debug" "5.10.2"
"@prisma/engines-version" "5.10.0-34.5a9203d0590c951969e85a7d07215503f4672eb9"
"@prisma/get-platform" "5.10.2"

"@prisma/[email protected]":
version "5.10.2"
resolved "https://registry.yarnpkg.com/@prisma/get-platform/-/get-platform-5.10.2.tgz#7af97b1d82e5574a474e3fbf6eaf04f4156bc535"
integrity sha512-nqXP6vHiY2PIsebBAuDeWiUYg8h8mfjBckHh6Jezuwej0QJNnjDiOq30uesmg+JXxGk99nqyG3B7wpcOODzXvg==
dependencies:
"@prisma/debug" "5.10.2"

"@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz#9b8b0cc663d669a7d8f6f5d0893a14d348f30fbf"
Expand Down Expand Up @@ -5600,6 +5641,13 @@ pretty-format@^27.0.6:
ansi-styles "^5.0.0"
react-is "^17.0.1"

prisma@^5.10.2:
version "5.10.2"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.10.2.tgz#aa63085c49dc74cdb5c3816e8dd1fb4d74a2aadd"
integrity sha512-hqb/JMz9/kymRE25pMWCxkdyhbnIWrq+h7S6WysJpdnCvhstbJSNP/S6mScEcqiB8Qv2F+0R3yG+osRaWqZacQ==
dependencies:
"@prisma/engines" "5.10.2"

process-nextick-args@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
Expand Down

0 comments on commit cd30bec

Please sign in to comment.