Skip to content

Commit

Permalink
add recurrence enum
Browse files Browse the repository at this point in the history
  • Loading branch information
jessica2673 committed Mar 28, 2024
1 parent f6e83a8 commit fcfc5a3
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 76 deletions.

This file was deleted.

32 changes: 0 additions & 32 deletions backend/typescript/prisma/migrations/20240317173631_/migration.sql

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-- CreateEnum
CREATE TYPE "RoleType" AS ENUM ('Admin', 'User');

-- CreateEnum
CREATE TYPE "Recurrence" AS ENUM ('None', 'Weekly', 'Monthly', 'Annually');

-- CreateTable
CREATE TABLE "User" (
"id" TEXT NOT NULL,
Expand All @@ -23,20 +26,13 @@ CREATE TABLE "Donation" (
"user_id" TEXT NOT NULL,
"amount" DOUBLE PRECISION NOT NULL,
"donation_date" TIMESTAMP(3) NOT NULL,
"is_recurring" BOOLEAN NOT NULL,
"cause_id" INTEGER NOT NULL,
"is_recurring" "Recurrence" 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,
Expand Down Expand Up @@ -67,9 +63,6 @@ CREATE TABLE "Item" (
CONSTRAINT "Item_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Donation_user_id_key" ON "Donation"("user_id");

-- CreateIndex
CREATE UNIQUE INDEX "NPO_item_id_key" ON "NPO"("item_id");

Expand Down
9 changes: 8 additions & 1 deletion backend/typescript/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ model Donation {
donation_date DateTime
cause Cause @relation(fields: [cause_id], references: [id])
cause_id Int
is_recurring Boolean
is_recurring Recurrence
confirmation_email_sent Boolean
}

enum Recurrence {
None
Weekly
Monthly
Annually
}

// 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())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import IDonationService from "../interfaces/donationService";
import { DonationDTO } from "../../types"
import { DonationDTO, Recurrence } from "../../types"
import prisma from "../../prisma";
import logger from "../../utilities/logger";
import { getErrorMessage } from "../../utilities/errorUtils";
Expand Down Expand Up @@ -33,7 +33,7 @@ class DonationService implements IDonationService {
}
}

async createDonation(user_id: string, amount: number, cause_id: number, is_recurring: boolean, confirmation_email_sent: boolean): Promise<DonationDTO> {
async createDonation(user_id: string, amount: number, cause_id: number, is_recurring: string, confirmation_email_sent: boolean): Promise<DonationDTO> {
{
try {
const newDonation = await prisma.donation.create({
Expand All @@ -42,13 +42,13 @@ class DonationService implements IDonationService {
amount,
donation_date: new Date(),
cause_id: cause_id,
is_recurring,
is_recurring: is_recurring as Recurrence,
confirmation_email_sent
},
});
return newDonation;
} catch (error) {

Logger.error(`Error creating donation for user ${user_id} = ${error}`);
throw error;
}
}
Expand Down
5 changes: 2 additions & 3 deletions backend/typescript/services/interfaces/donationService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DateDataType, FloatDataType, IntegerDataType } from "sequelize";
import { DonationDTO } from "../../types";
import { DonationDTO, Recurrence } from "../../types";

interface IDonationService {
/**
Expand Down Expand Up @@ -31,7 +30,7 @@ interface IDonationService {
user_id: string,
amount: number,
cause_id: number,
is_recurring: boolean,
is_recurring: string,
confirmation_email_sent: boolean
): Promise<DonationDTO>;
}
Expand Down
4 changes: 3 additions & 1 deletion backend/typescript/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ export type NodemailerConfig = {

export type SignUpMethod = "PASSWORD" | "GOOGLE";

export type Recurrence = "None" | "Weekly" | "Monthly" | "Annually";

export type DonationDTO = {
user_id: string;
amount: number;
donation_date: Date;
cause_id: number;
is_recurring: boolean;
is_recurring: Recurrence;
confirmation_email_sent: boolean;
}

Expand Down

0 comments on commit fcfc5a3

Please sign in to comment.