This commit is contained in:
 Илья Шалонин 2025-10-29 13:43:43 +05:00
commit 8538ab969a
434 changed files with 44051 additions and 0 deletions

View file

@ -0,0 +1,69 @@
import type { z } from "zod";
import { db } from "../client";
import type {
PurchaseUncheckedCreateInputSchema,
PurchaseUncheckedUpdateInputSchema,
} from "../zod";
export async function getPurchaseById(id: string) {
return db.purchase.findUnique({
where: { id },
});
}
export async function getPurchasesByOrganizationId(organizationId: string) {
return db.purchase.findMany({
where: {
organizationId,
},
});
}
export async function getPurchasesByUserId(userId: string) {
return db.purchase.findMany({
where: {
userId,
},
});
}
export async function getPurchaseBySubscriptionId(subscriptionId: string) {
return db.purchase.findFirst({
where: {
subscriptionId,
},
});
}
export async function createPurchase(
purchase: z.infer<typeof PurchaseUncheckedCreateInputSchema>,
) {
const created = await db.purchase.create({
data: purchase,
});
return getPurchaseById(created.id);
}
export async function updatePurchase(
purchase: z.infer<typeof PurchaseUncheckedUpdateInputSchema> & {
id: string;
},
) {
const updated = await db.purchase.update({
where: {
id: purchase.id,
},
data: purchase,
});
return getPurchaseById(updated.id);
}
export async function deletePurchaseBySubscriptionId(subscriptionId: string) {
await db.purchase.delete({
where: {
subscriptionId,
},
});
}