feat: query plaid transactions

This commit is contained in:
Max Koon
2025-10-15 10:53:37 -04:00
parent 23987e4f87
commit 415150d58e
12 changed files with 322 additions and 32 deletions

View File

@@ -92,3 +92,10 @@ export const auditLogs = pgTable("audit_log", {
.references(() => users.id, { onDelete: "cascade" }),
action: text("action").notNull(),
});
export const plaidAccessTokens = pgTable("plaidAccessToken", {
id: text("id").primaryKey(),
userId: text("user_id").notNull(),
token: text("token").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
});

View File

@@ -1,4 +1,4 @@
import { integer, pgTable, text, boolean, timestamp, uniqueIndex } from "drizzle-orm/pg-core";
import { pgTable, text, boolean, timestamp, uniqueIndex, decimal } from "drizzle-orm/pg-core";
export const users = pgTable(
"user",
@@ -18,7 +18,14 @@ export const transaction = pgTable("transaction", {
id: text("id").primaryKey(),
user_id: text("user_id").notNull(),
name: text("name").notNull(),
amount: integer("amount").notNull(),
amount: decimal("amount").notNull(),
});
export const plaidLink = pgTable("plaidLink", {
id: text("id").primaryKey(),
user_id: text("user_id").notNull(),
link: text("link").notNull(),
token: text("token").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
});

View File

@@ -25,7 +25,9 @@ export function createMutators(authData: AuthData | null) {
},
},
link: {
async create() {}
async create() {},
async get(tx: Tx, { link_token }: { link_token: string }) {},
async updateTransactions() {},
}
} as const;
}

View File

@@ -17,5 +17,12 @@ export const queries = {
return builder.users
.where('id', '=', authData.user.id)
.one();
})
}),
getPlaidLink: syncedQueryWithContext('getPlaidLink', z.tuple([]), (authData: AuthData | null) => {
isLoggedIn(authData);
return builder.plaidLink
.where('user_id', '=', authData.user.id)
.orderBy('createdAt', 'desc')
.one();
}),
};

View File

@@ -1,4 +1,6 @@
import { definePermissions } from "@rocicorp/zero";
import { schema } from "./zero-schema.gen";
import { schema as schemaGen } from "./zero-schema.gen";
export const schema = schemaGen;
export const permissions = definePermissions(schema, () => ({}));

View File

@@ -21,6 +21,58 @@ type ZeroSchema = DrizzleToZeroSchema<typeof drizzleSchema>;
*/
export const schema = {
tables: {
plaidLink: {
name: "plaidLink",
columns: {
id: {
type: "string",
optional: false,
customType: null as unknown as ZeroCustomType<
ZeroSchema,
"plaidLink",
"id"
>,
},
user_id: {
type: "string",
optional: false,
customType: null as unknown as ZeroCustomType<
ZeroSchema,
"plaidLink",
"user_id"
>,
},
link: {
type: "string",
optional: false,
customType: null as unknown as ZeroCustomType<
ZeroSchema,
"plaidLink",
"link"
>,
},
token: {
type: "string",
optional: false,
customType: null as unknown as ZeroCustomType<
ZeroSchema,
"plaidLink",
"token"
>,
},
createdAt: {
type: "number",
optional: true,
customType: null as unknown as ZeroCustomType<
ZeroSchema,
"plaidLink",
"createdAt"
>,
serverName: "created_at",
},
},
primaryKey: ["id"],
},
transaction: {
name: "transaction",
columns: {
@@ -147,6 +199,11 @@ export const schema = {
* This type is auto-generated from your Drizzle schema definition.
*/
export type Schema = typeof schema;
/**
* Represents a row from the "plaidLink" table.
* This type is auto-generated from your Drizzle schema definition.
*/
export type PlaidLink = Row<Schema["tables"]["plaidLink"]>;
/**
* Represents a row from the "transaction" table.
* This type is auto-generated from your Drizzle schema definition.