feat: show transaction info

This commit is contained in:
Max Koon
2025-10-15 15:52:15 -04:00
parent 1551d39978
commit 22dbe2b3b5
6 changed files with 116 additions and 48 deletions

View File

@@ -18,8 +18,14 @@ export const users = pgTable(
export const transaction = pgTable("transaction", {
id: text("id").primaryKey(),
user_id: text("user_id").notNull(),
plaid_id: text("plaid_id").notNull().unique(),
name: text("name").notNull(),
amount: decimal("amount").notNull(),
datetime: timestamp("datetime"),
authorized_datetime: timestamp("authorized_datetime"),
json: text("json"),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
});
export const plaidLink = pgTable("plaidLink", {

View File

@@ -1,29 +1,11 @@
import type { Transaction } from "@rocicorp/zero";
import type { AuthData } from "./auth";
import type { Schema } from ".";
import { isLoggedIn } from "./zql";
type Tx = Transaction<Schema>;
export function createMutators(authData: AuthData | null) {
return {
transaction: {
async create(tx: Tx, { id, name, amount }: { id: string, name: string, amount: number }) {
isLoggedIn(authData);
await tx.mutate.transaction.insert({
id,
user_id: authData.user.id,
name,
amount,
})
},
async deleteAll(tx: Tx) {
const t = await tx.query.transaction.limit(10);
for (const i of t) {
await tx.mutate.transaction.delete({ id: i.id });
}
},
},
link: {
async create() {},
async get(tx: Tx, { link_token }: { link_token: string }) {},

View File

@@ -9,7 +9,8 @@ export const queries = {
isLoggedIn(authData);
return builder.transaction
.where('user_id', '=', authData.user.id)
.limit(10)
.orderBy('datetime', 'desc')
.limit(50)
}
),
me: syncedQueryWithContext('me', z.tuple([]), (authData: AuthData | null) => {

View File

@@ -176,6 +176,15 @@ export const schema = {
"user_id"
>,
},
plaid_id: {
type: "string",
optional: false,
customType: null as unknown as ZeroCustomType<
ZeroSchema,
"transaction",
"plaid_id"
>,
},
name: {
type: "string",
optional: false,
@@ -194,6 +203,53 @@ export const schema = {
"amount"
>,
},
datetime: {
type: "number",
optional: true,
customType: null as unknown as ZeroCustomType<
ZeroSchema,
"transaction",
"datetime"
>,
},
authorized_datetime: {
type: "number",
optional: true,
customType: null as unknown as ZeroCustomType<
ZeroSchema,
"transaction",
"authorized_datetime"
>,
},
json: {
type: "string",
optional: true,
customType: null as unknown as ZeroCustomType<
ZeroSchema,
"transaction",
"json"
>,
},
createdAt: {
type: "number",
optional: true,
customType: null as unknown as ZeroCustomType<
ZeroSchema,
"transaction",
"createdAt"
>,
serverName: "created_at",
},
updatedAt: {
type: "number",
optional: true,
customType: null as unknown as ZeroCustomType<
ZeroSchema,
"transaction",
"updatedAt"
>,
serverName: "updated_at",
},
},
primaryKey: ["id"],
},