-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from GenieWizards/feat/settlement-model
feat(settlement.model.ts): create settlement model
- Loading branch information
Showing
2 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { | ||
pgEnum, | ||
pgTable, | ||
real, | ||
timestamp, | ||
varchar, | ||
} from "drizzle-orm/pg-core"; | ||
import { createInsertSchema, createSelectSchema } from "drizzle-zod"; | ||
import type { z } from "zod"; | ||
|
||
import { splitTypeArr } from "@/common/enums"; | ||
|
||
export const splitTypeEnum = pgEnum("splitType", splitTypeArr); | ||
|
||
const settlementModel = pgTable("settlement", { | ||
id: varchar({ length: 60 }) | ||
.$defaultFn(() => Bun.randomUUIDv7()) | ||
.primaryKey(), | ||
senderId: varchar({ length: 60 }) | ||
.notNull(), | ||
receiverId: varchar({ length: 60 }) | ||
.notNull(), | ||
groupId: varchar({ length: 60 }), | ||
amount: real().notNull(), | ||
createdAt: timestamp().notNull().defaultNow(), | ||
updatedAt: timestamp().notNull().defaultNow(), | ||
}); | ||
|
||
// Schema for selecting/inserting a 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"), | ||
receiverId: schema => | ||
schema.receiverId.describe("Reference to the user who is ower "), | ||
groupId: schema => | ||
schema.groupId.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"), | ||
updatedAt: schema => | ||
schema.updatedAt.describe("Timestamp when the settlement was last updated"), | ||
}); | ||
|
||
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"), | ||
receiverId: schema => | ||
schema.receiverId.describe("Reference to the user who is ower "), | ||
groupId: schema => | ||
schema.groupId.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"), | ||
updatedAt: schema => | ||
schema.updatedAt.describe("Timestamp when the settlement was last updated"), | ||
}); | ||
|
||
export type TSelectSettlementSchema = z.infer<typeof selectSettlementSchema>; | ||
export type TInsertSettlementSchema = z.infer<typeof insertSettlementSchema>; | ||
|
||
export default settlementModel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters