refactor: add tryCatch utility for error handling, update device-related components and types, and clean up unused code in payment actions
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 13m55s

This commit is contained in:
2025-04-05 16:07:11 +05:00
parent dbdc1df7d5
commit aa18484475
16 changed files with 641 additions and 599 deletions

View File

@ -1,31 +1,29 @@
"use server";
import prisma from "@/lib/db";
import type { PaymentType } from "@/lib/types";
import { formatMacAddress } from "@/lib/utils";
import type { Prisma } from "@prisma/client";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { addDevicesToGroup } from "./omada-actions";
export async function createPayment(data: PaymentType) {
console.log("data", data);
const payment = await prisma.payment.create({
data: {
amount: data.amount,
numberOfMonths: data.numberOfMonths,
paid: data.paid,
userId: data.userId,
devices: {
connect: data.deviceIds.map((id) => {
return {
id,
};
}),
},
},
});
redirect(`/payments/${payment.id}`);
// const payment = await prisma.payment.create({
// data: {
// amount: data.amount,
// numberOfMonths: data.numberOfMonths,
// paid: data.paid,
// userId: data.userId,
// devices: {
// connect: data.deviceIds.map((id) => {
// return {
// id,
// };
// }),
// },
// },
// });
// redirect(`/payments/${payment.id}`);
}
type VerifyPaymentType = {
@ -38,12 +36,6 @@ type VerifyPaymentType = {
type?: "TRANSFER" | "WALLET";
};
type PaymentWithDevices = Prisma.PaymentGetPayload<{
include: {
devices: true;
};
}>;
class InsufficientFundsError extends Error {
constructor() {
super("Insufficient funds in wallet");