feat: add mutations

This commit is contained in:
Max Koon
2025-10-13 23:45:20 -04:00
parent fb6b7ff683
commit 032f38b711
5 changed files with 56 additions and 52 deletions

View File

@@ -1,2 +1,4 @@
export * from "./schema";
export * from "./queries";
export * from "./mutators";
export * from "./zql";

24
shared/src/mutators.ts Normal file
View File

@@ -0,0 +1,24 @@
import type { Transaction } from "@rocicorp/zero";
import type { AuthData } from "./auth";
import type { Schema } from "./schema";
import { isLoggedIn } from "./zql";
type Tx = Transaction<Schema>;
export function createMutators(authData: AuthData | null) {
return {
transaction: {
async create(tx: Tx, { name, amount }: { name: string, amount: number }) {
isLoggedIn(authData);
await tx.mutate.transaction.insert({
id: 'id-' + Math.random().toString(),
user_id: authData.user.id,
name,
amount,
})
}
}
} as const;
}
export type Mutators = ReturnType<typeof createMutators>;