feat: query plaid transactions
This commit is contained in:
@@ -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(),
|
||||
});
|
||||
|
||||
@@ -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(),
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -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, () => ({}));
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user