format: format with biome
This commit is contained in:
@@ -1,3 +1,2 @@
|
||||
export const HOST = process.env.EXPO_PUBLIC_TAILSCALE_MACHINE || "localhost";
|
||||
export const BASE_URL = `http://${HOST}`;
|
||||
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { pgTable, text, boolean, timestamp, uniqueIndex, decimal } from "drizzle-orm/pg-core";
|
||||
import {
|
||||
boolean,
|
||||
decimal,
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
pgEnum,
|
||||
uniqueIndex,
|
||||
} from "drizzle-orm/pg-core";
|
||||
|
||||
export const users = pgTable(
|
||||
"user",
|
||||
@@ -33,6 +41,7 @@ export const plaidLink = pgTable("plaidLink", {
|
||||
user_id: text("user_id").notNull(),
|
||||
link: text("link").notNull(),
|
||||
token: text("token").notNull(),
|
||||
completeAt: timestamp("complete_at"),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
});
|
||||
|
||||
|
||||
@@ -12,32 +12,33 @@ export function createMutators(authData: AuthData | null) {
|
||||
async get(tx: Tx, { link_token }: { link_token: string }) {},
|
||||
async updateTransactions() {},
|
||||
async updateBalences() {},
|
||||
async deleteAccounts(tx: Tx, { accountIds }: { accountIds: string[] }) {
|
||||
async deleteAccounts(tx: Tx, { accountIds }: { accountIds: string[] }) {
|
||||
isLoggedIn(authData);
|
||||
for (const id of accountIds) {
|
||||
const token = await tx.query.plaidAccessTokens.where("userId", '=', authData.user.id).one();
|
||||
const token = await tx.query.plaidAccessTokens
|
||||
.where("userId", "=", authData.user.id)
|
||||
.one();
|
||||
if (!token) continue;
|
||||
await tx.mutate.plaidAccessTokens.delete({ id });
|
||||
|
||||
const balances = await tx.query.balance
|
||||
.where('user_id', '=', authData.user.id)
|
||||
.where("tokenId", '=', token.id)
|
||||
.where("user_id", "=", authData.user.id)
|
||||
.where("tokenId", "=", token.id)
|
||||
.run();
|
||||
|
||||
for (const bal of balances) {
|
||||
await tx.mutate.balance.delete({ id: bal.id });
|
||||
const txs = await tx.query.transaction
|
||||
.where('user_id', '=', authData.user.id)
|
||||
.where('account_id', '=', bal.tokenId)
|
||||
.where("user_id", "=", authData.user.id)
|
||||
.where("account_id", "=", bal.tokenId)
|
||||
.run();
|
||||
for (const transaction of txs) {
|
||||
await tx.mutate.transaction.delete({ id: transaction.id });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
} as const;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,37 +5,59 @@ import { type AuthData } from "./auth";
|
||||
import { isLoggedIn } from "./zql";
|
||||
|
||||
export const queries = {
|
||||
me: syncedQueryWithContext('me', z.tuple([]), (authData: AuthData | null) => {
|
||||
me: syncedQueryWithContext("me", z.tuple([]), (authData: AuthData | null) => {
|
||||
isLoggedIn(authData);
|
||||
return builder.users
|
||||
.where('id', '=', authData.user.id)
|
||||
.one();
|
||||
return builder.users.where("id", "=", authData.user.id).one();
|
||||
}),
|
||||
allTransactions: syncedQueryWithContext('allTransactions', z.tuple([]), (authData: AuthData | null) => {
|
||||
isLoggedIn(authData);
|
||||
return builder.transaction
|
||||
.where('user_id', '=', authData.user.id)
|
||||
.orderBy('datetime', 'desc')
|
||||
.limit(50)
|
||||
}),
|
||||
getPlaidLink: syncedQueryWithContext('getPlaidLink', z.tuple([]), (authData: AuthData | null) => {
|
||||
isLoggedIn(authData);
|
||||
return builder.plaidLink
|
||||
.where('user_id', '=', authData.user.id)
|
||||
.where('createdAt', '>', new Date().getTime() - (1000 * 60 * 60 * 4))
|
||||
.orderBy('createdAt', 'desc')
|
||||
.one();
|
||||
}),
|
||||
getBalances: syncedQueryWithContext('getBalances', z.tuple([]), (authData: AuthData | null) => {
|
||||
isLoggedIn(authData);
|
||||
return builder.balance
|
||||
.where('user_id', '=', authData.user.id)
|
||||
.orderBy('name', 'asc');
|
||||
}),
|
||||
getItems: syncedQueryWithContext('getItems', z.tuple([]), (authData: AuthData | null) => {
|
||||
isLoggedIn(authData);
|
||||
return builder.plaidAccessTokens
|
||||
.where('userId', '=', authData.user.id)
|
||||
.orderBy('createdAt', 'desc');
|
||||
})
|
||||
allTransactions: syncedQueryWithContext(
|
||||
"allTransactions",
|
||||
z.tuple([]),
|
||||
(authData: AuthData | null) => {
|
||||
isLoggedIn(authData);
|
||||
return builder.transaction
|
||||
.where("user_id", "=", authData.user.id)
|
||||
.orderBy("datetime", "desc")
|
||||
.limit(50);
|
||||
},
|
||||
),
|
||||
getPlaidLink: syncedQueryWithContext(
|
||||
"getPlaidLink",
|
||||
z.tuple([]),
|
||||
(authData: AuthData | null) => {
|
||||
isLoggedIn(authData);
|
||||
return builder.plaidLink
|
||||
.where(({ cmp, and, or }) =>
|
||||
and(
|
||||
cmp("user_id", "=", authData.user.id),
|
||||
cmp("createdAt", ">", new Date().getTime() - 1000 * 60 * 60 * 4),
|
||||
or(
|
||||
cmp("completeAt", ">", new Date().getTime() - 1000 * 5),
|
||||
cmp("completeAt", "IS", null),
|
||||
),
|
||||
),
|
||||
)
|
||||
.orderBy("createdAt", "desc")
|
||||
.one();
|
||||
},
|
||||
),
|
||||
getBalances: syncedQueryWithContext(
|
||||
"getBalances",
|
||||
z.tuple([]),
|
||||
(authData: AuthData | null) => {
|
||||
isLoggedIn(authData);
|
||||
return builder.balance
|
||||
.where("user_id", "=", authData.user.id)
|
||||
.orderBy("name", "asc");
|
||||
},
|
||||
),
|
||||
getItems: syncedQueryWithContext(
|
||||
"getItems",
|
||||
z.tuple([]),
|
||||
(authData: AuthData | null) => {
|
||||
isLoggedIn(authData);
|
||||
return builder.plaidAccessTokens
|
||||
.where("userId", "=", authData.user.id)
|
||||
.orderBy("createdAt", "desc");
|
||||
},
|
||||
),
|
||||
};
|
||||
|
||||
@@ -214,6 +214,16 @@ export const schema = {
|
||||
"token"
|
||||
>,
|
||||
},
|
||||
completeAt: {
|
||||
type: "number",
|
||||
optional: true,
|
||||
customType: null as unknown as ZeroCustomType<
|
||||
ZeroSchema,
|
||||
"plaidLink",
|
||||
"completeAt"
|
||||
>,
|
||||
serverName: "complete_at",
|
||||
},
|
||||
createdAt: {
|
||||
type: "number",
|
||||
optional: true,
|
||||
|
||||
Reference in New Issue
Block a user