Skip to content

Commit d45bbcf

Browse files
authoredFeb 15, 2025··
Merge pull request #144 from GenieWizards/feat/64-feat-implement-functionality-to-handle-settlement-between-group-users
Feat/64 feat implement functionality to handle settlement between group users
2 parents 545ad66 + 0d39593 commit d45bbcf

17 files changed

+529
-2881
lines changed
 

‎src/app.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ import { categoryRouter } from "./modules/categories/category.index";
66
import { expenseRouter } from "./modules/expenses/expense.index";
77
import { groupRouters } from "./modules/group/group.index";
88
import { healthCheckRouter } from "./modules/health-check/health-check.index";
9+
import { settlementsRouter } from "./modules/settlements/settlements.index";
910

1011
export const app = createApp();
1112

12-
const routesV1 = [authRouter, categoryRouter, groupRouters, activityRouter, expenseRouter];
13+
const routesV1 = [
14+
authRouter,
15+
categoryRouter,
16+
groupRouters,
17+
activityRouter,
18+
expenseRouter,
19+
settlementsRouter,
20+
];
1321

1422
configureOpenAPI(app);
1523

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
CREATE TYPE "public"."activityType" AS ENUM('category_created', 'category_updated', 'category_deleted', 'group_created', 'group_deleted', 'group_updated', 'group_member_added', 'group_member_removed', 'expense_added', 'expense_updated', 'expense_deleted');--> statement-breakpoint
2+
CREATE TYPE "public"."splitType" AS ENUM('even', 'uneven', 'proportional');--> statement-breakpoint
3+
CREATE TYPE "public"."status" AS ENUM('settled', 'unsettled');--> statement-breakpoint
4+
CREATE TYPE "public"."role" AS ENUM('user', 'admin');--> statement-breakpoint
5+
CREATE TABLE "account" (
6+
"id" varchar(60) PRIMARY KEY NOT NULL,
7+
"provider_id" varchar(255) NOT NULL,
8+
"provider_account_id" varchar(255) NOT NULL,
9+
"user_id" varchar(60) NOT NULL,
10+
"access_token" varchar(255),
11+
"refresh_token" varchar(255),
12+
"id_token" varchar(255),
13+
"expires_at" timestamp,
14+
"password" varchar(255),
15+
"created_at" timestamp DEFAULT now() NOT NULL,
16+
"updated_at" timestamp DEFAULT now() NOT NULL,
17+
CONSTRAINT "account_userId_providerId_unique" UNIQUE("user_id","provider_id")
18+
);
19+
--> statement-breakpoint
20+
CREATE TABLE "activity" (
21+
"id" varchar(60) PRIMARY KEY NOT NULL,
22+
"type" varchar(60) NOT NULL,
23+
"metadata" jsonb NOT NULL,
24+
"group_id" varchar(60),
25+
"created_at" timestamp DEFAULT now() NOT NULL,
26+
"updated_at" timestamp DEFAULT now() NOT NULL
27+
);
28+
--> statement-breakpoint
29+
CREATE TABLE "category" (
30+
"id" varchar(60) PRIMARY KEY NOT NULL,
31+
"name" varchar(255) NOT NULL,
32+
"description" text,
33+
"user_id" varchar(60),
34+
"is_active" boolean DEFAULT true NOT NULL,
35+
"icon" varchar(255),
36+
"created_at" timestamp DEFAULT now() NOT NULL,
37+
"updated_at" timestamp DEFAULT now() NOT NULL
38+
);
39+
--> statement-breakpoint
40+
CREATE TABLE "expense" (
41+
"id" varchar(60) PRIMARY KEY NOT NULL,
42+
"payer_id" varchar(60) NOT NULL,
43+
"creator_id" varchar(60) NOT NULL,
44+
"category_id" varchar(60),
45+
"group_id" varchar(60),
46+
"amount" real NOT NULL,
47+
"currency" varchar(3) NOT NULL,
48+
"split_type" "splitType",
49+
"description" text,
50+
"created_at" timestamp DEFAULT now() NOT NULL,
51+
"updated_at" timestamp DEFAULT now() NOT NULL
52+
);
53+
--> statement-breakpoint
54+
CREATE TABLE "group" (
55+
"id" varchar(60) PRIMARY KEY NOT NULL,
56+
"name" varchar(255) NOT NULL,
57+
"creator_id" varchar(60) NOT NULL,
58+
"status" "status" DEFAULT 'unsettled',
59+
"created_at" timestamp DEFAULT now() NOT NULL,
60+
"updated_at" timestamp DEFAULT now() NOT NULL
61+
);
62+
--> statement-breakpoint
63+
CREATE TABLE "session" (
64+
"id" varchar(80) PRIMARY KEY NOT NULL,
65+
"expires_at" timestamp NOT NULL,
66+
"ip_address" varchar(255),
67+
"user_agent" varchar(255),
68+
"user_id" varchar NOT NULL
69+
);
70+
--> statement-breakpoint
71+
CREATE TABLE "split" (
72+
"id" varchar(60) PRIMARY KEY NOT NULL,
73+
"user_id" varchar(60) NOT NULL,
74+
"expense_id" varchar(60) NOT NULL,
75+
"amount" real NOT NULL,
76+
"created_at" timestamp DEFAULT now() NOT NULL,
77+
"updated_at" timestamp DEFAULT now() NOT NULL
78+
);
79+
--> statement-breakpoint
80+
CREATE TABLE "users" (
81+
"id" varchar(60) PRIMARY KEY NOT NULL,
82+
"email" varchar(255) NOT NULL,
83+
"email_verified" boolean DEFAULT false,
84+
"full_name" varchar(255),
85+
"role" "role" DEFAULT 'user',
86+
"created_at" timestamp DEFAULT now() NOT NULL,
87+
"updated_at" timestamp DEFAULT now() NOT NULL,
88+
CONSTRAINT "users_email_unique" UNIQUE("email")
89+
);
90+
--> statement-breakpoint
91+
CREATE TABLE "settlement" (
92+
"id" varchar(60) PRIMARY KEY NOT NULL,
93+
"sender_id" varchar(60) NOT NULL,
94+
"receiver_id" varchar(60) NOT NULL,
95+
"group_id" varchar(60),
96+
"amount" real NOT NULL,
97+
"created_at" timestamp DEFAULT now() NOT NULL,
98+
"updated_at" timestamp DEFAULT now() NOT NULL
99+
);
100+
--> statement-breakpoint
101+
CREATE TABLE "users_to_groups" (
102+
"user_id" varchar(60) NOT NULL,
103+
"group_id" varchar(60) NOT NULL,
104+
"created_at" timestamp DEFAULT now() NOT NULL,
105+
"updated_at" timestamp DEFAULT now() NOT NULL,
106+
CONSTRAINT "users_to_groups_user_id_group_id_pk" PRIMARY KEY("user_id","group_id")
107+
);
108+
--> statement-breakpoint
109+
ALTER TABLE "account" ADD CONSTRAINT "account_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
110+
ALTER TABLE "activity" ADD CONSTRAINT "activity_group_id_group_id_fk" FOREIGN KEY ("group_id") REFERENCES "public"."group"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
111+
ALTER TABLE "category" ADD CONSTRAINT "category_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
112+
ALTER TABLE "expense" ADD CONSTRAINT "expense_payer_id_users_id_fk" FOREIGN KEY ("payer_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
113+
ALTER TABLE "expense" ADD CONSTRAINT "expense_creator_id_users_id_fk" FOREIGN KEY ("creator_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
114+
ALTER TABLE "expense" ADD CONSTRAINT "expense_category_id_category_id_fk" FOREIGN KEY ("category_id") REFERENCES "public"."category"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
115+
ALTER TABLE "expense" ADD CONSTRAINT "expense_group_id_group_id_fk" FOREIGN KEY ("group_id") REFERENCES "public"."group"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
116+
ALTER TABLE "group" ADD CONSTRAINT "group_creator_id_users_id_fk" FOREIGN KEY ("creator_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
117+
ALTER TABLE "session" ADD CONSTRAINT "session_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
118+
ALTER TABLE "split" ADD CONSTRAINT "split_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
119+
ALTER TABLE "split" ADD CONSTRAINT "split_expense_id_expense_id_fk" FOREIGN KEY ("expense_id") REFERENCES "public"."expense"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
120+
ALTER TABLE "users_to_groups" ADD CONSTRAINT "users_to_groups_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
121+
ALTER TABLE "users_to_groups" ADD CONSTRAINT "users_to_groups_group_id_group_id_fk" FOREIGN KEY ("group_id") REFERENCES "public"."group"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
122+
CREATE UNIQUE INDEX "unique_name_userId_idx" ON "category" USING btree (lower("name"),"user_id");--> statement-breakpoint
123+
CREATE INDEX "search_index" ON "category" USING gin ((
124+
setweight(to_tsvector('english', "name"), 'A') ||
125+
setweight(to_tsvector('english', "description"), 'B')
126+
));--> statement-breakpoint
127+
CREATE UNIQUE INDEX "unique_email_idx" ON "users" USING btree (lower("email"));

‎src/db/migrations/0000_natural_mephisto.sql

-176
This file was deleted.

‎src/db/migrations/0001_parallel_red_hulk.sql

-7
This file was deleted.

‎src/db/migrations/0002_safe_cobalt_man.sql

-11
This file was deleted.

‎src/db/migrations/0003_bored_captain_stacy.sql

-1
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.