Skip to content

Commit

Permalink
Merge pull request #129 from GenieWizards/feat/64-feat-implement-func…
Browse files Browse the repository at this point in the history
…tionality-to-handle-settlement-between-group-users

fix(settlement validations): add id validation
  • Loading branch information
shivamvijaywargi authored Dec 28, 2024
2 parents 72387be + 0a4327d commit e5f602b
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions src/db/schemas/settlement.model.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
pgEnum,
pgTable,
real,
timestamp,
varchar,
} from "drizzle-orm/pg-core";
import { pgEnum, pgTable, real, timestamp, varchar } from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import type { z } from "zod";

Expand All @@ -16,10 +10,8 @@ const settlementModel = pgTable("settlement", {
id: varchar({ length: 60 })
.$defaultFn(() => Bun.randomUUIDv7())
.primaryKey(),
senderId: varchar({ length: 60 })
.notNull(),
receiverId: varchar({ length: 60 })
.notNull(),
senderId: varchar({ length: 60 }).notNull(),
receiverId: varchar({ length: 60 }).notNull(),
groupId: varchar({ length: 60 }),
amount: real().notNull(),
createdAt: timestamp().notNull().defaultNow(),
Expand All @@ -30,13 +22,20 @@ const settlementModel = pgTable("settlement", {
export const selectSettlementSchema = createSelectSchema(settlementModel, {
id: schema => schema.id.describe("Unique identifier for the settlement"),
senderId: schema =>
schema.senderId.describe("Reference to the user who is payer"),
schema.senderId
.min(60)
.max(60)
.describe("Reference to the user who is payer"),
receiverId: schema =>
schema.receiverId.describe("Reference to the user who is ower "),
schema.receiverId
.min(60)
.max(60)
.describe("Reference to the user who is ower "),
groupId: schema =>
schema.groupId.describe(
"Reference to the group the settlement belongs to",
),
schema.groupId
.min(60)
.max(60)
.describe("Reference to the group the settlement belongs to"),
amount: schema => schema.amount.describe("Amount of the settlement"),
createdAt: schema =>
schema.createdAt.describe("Timestamp when the settlement was created"),
Expand All @@ -47,13 +46,20 @@ export const selectSettlementSchema = createSelectSchema(settlementModel, {
export const insertSettlementSchema = createInsertSchema(settlementModel, {
id: schema => schema.id.describe("Unique identifier for the settlement"),
senderId: schema =>
schema.senderId.describe("Reference to the user who is payer"),
schema.senderId
.min(60)
.max(60)
.describe("Reference to the user who is payer"),
receiverId: schema =>
schema.receiverId.describe("Reference to the user who is ower "),
schema.receiverId
.min(60)
.max(60)
.describe("Reference to the user who is ower "),
groupId: schema =>
schema.groupId.describe(
"Reference to the group the settlement belongs to",
),
schema.groupId
.min(60)
.max(60)
.describe("Reference to the group the settlement belongs to"),
amount: schema => schema.amount.describe("Amount of the settlement"),
createdAt: schema =>
schema.createdAt.describe("Timestamp when the settlement was created"),
Expand Down

0 comments on commit e5f602b

Please sign in to comment.