feat: update multiple balances
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { definePermissions } from "@rocicorp/zero";
|
||||
import { pgTable, text, boolean, timestamp, uniqueIndex, decimal } from "drizzle-orm/pg-core";
|
||||
|
||||
export const users = pgTable(
|
||||
@@ -29,3 +30,13 @@ export const plaidLink = pgTable("plaidLink", {
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
});
|
||||
|
||||
export const balance = pgTable("balance", {
|
||||
id: text("id").primaryKey(),
|
||||
user_id: text("userId").notNull(),
|
||||
plaid_id: text("plaidId").notNull().unique(),
|
||||
avaliable: decimal("avaliable").notNull(),
|
||||
current: decimal("current").notNull(),
|
||||
name: text("name").notNull(),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
||||
})
|
||||
|
||||
@@ -28,6 +28,7 @@ export function createMutators(authData: AuthData | null) {
|
||||
async create() {},
|
||||
async get(tx: Tx, { link_token }: { link_token: string }) {},
|
||||
async updateTransactions() {},
|
||||
async updateBalences() {},
|
||||
}
|
||||
} as const;
|
||||
}
|
||||
|
||||
@@ -25,4 +25,9 @@ export const queries = {
|
||||
.orderBy('createdAt', 'desc')
|
||||
.one();
|
||||
}),
|
||||
getBalances: syncedQueryWithContext('getBalances', z.tuple([]), (authData: AuthData | null) => {
|
||||
isLoggedIn(authData);
|
||||
return builder.balance
|
||||
.where('user_id', '=', authData.user.id);
|
||||
})
|
||||
};
|
||||
|
||||
@@ -21,6 +21,88 @@ type ZeroSchema = DrizzleToZeroSchema<typeof drizzleSchema>;
|
||||
*/
|
||||
export const schema = {
|
||||
tables: {
|
||||
balance: {
|
||||
name: "balance",
|
||||
columns: {
|
||||
id: {
|
||||
type: "string",
|
||||
optional: false,
|
||||
customType: null as unknown as ZeroCustomType<
|
||||
ZeroSchema,
|
||||
"balance",
|
||||
"id"
|
||||
>,
|
||||
},
|
||||
user_id: {
|
||||
type: "string",
|
||||
optional: false,
|
||||
customType: null as unknown as ZeroCustomType<
|
||||
ZeroSchema,
|
||||
"balance",
|
||||
"user_id"
|
||||
>,
|
||||
serverName: "userId",
|
||||
},
|
||||
plaid_id: {
|
||||
type: "string",
|
||||
optional: false,
|
||||
customType: null as unknown as ZeroCustomType<
|
||||
ZeroSchema,
|
||||
"balance",
|
||||
"plaid_id"
|
||||
>,
|
||||
serverName: "plaidId",
|
||||
},
|
||||
avaliable: {
|
||||
type: "number",
|
||||
optional: false,
|
||||
customType: null as unknown as ZeroCustomType<
|
||||
ZeroSchema,
|
||||
"balance",
|
||||
"avaliable"
|
||||
>,
|
||||
},
|
||||
current: {
|
||||
type: "number",
|
||||
optional: false,
|
||||
customType: null as unknown as ZeroCustomType<
|
||||
ZeroSchema,
|
||||
"balance",
|
||||
"current"
|
||||
>,
|
||||
},
|
||||
name: {
|
||||
type: "string",
|
||||
optional: false,
|
||||
customType: null as unknown as ZeroCustomType<
|
||||
ZeroSchema,
|
||||
"balance",
|
||||
"name"
|
||||
>,
|
||||
},
|
||||
createdAt: {
|
||||
type: "number",
|
||||
optional: true,
|
||||
customType: null as unknown as ZeroCustomType<
|
||||
ZeroSchema,
|
||||
"balance",
|
||||
"createdAt"
|
||||
>,
|
||||
serverName: "created_at",
|
||||
},
|
||||
updatedAt: {
|
||||
type: "number",
|
||||
optional: true,
|
||||
customType: null as unknown as ZeroCustomType<
|
||||
ZeroSchema,
|
||||
"balance",
|
||||
"updatedAt"
|
||||
>,
|
||||
serverName: "updated_at",
|
||||
},
|
||||
},
|
||||
primaryKey: ["id"],
|
||||
},
|
||||
plaidLink: {
|
||||
name: "plaidLink",
|
||||
columns: {
|
||||
@@ -199,6 +281,11 @@ export const schema = {
|
||||
* This type is auto-generated from your Drizzle schema definition.
|
||||
*/
|
||||
export type Schema = typeof schema;
|
||||
/**
|
||||
* Represents a row from the "balance" table.
|
||||
* This type is auto-generated from your Drizzle schema definition.
|
||||
*/
|
||||
export type Balance = Row<Schema["tables"]["balance"]>;
|
||||
/**
|
||||
* Represents a row from the "plaidLink" table.
|
||||
* This type is auto-generated from your Drizzle schema definition.
|
||||
|
||||
Reference in New Issue
Block a user