mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-02 09:48:22 +00:00
Implement Omada device management and enhance payment processing
- Added new omada-actions.ts file to handle fetching and updating device groups in Omada. - Updated authMiddleware to include new payment routes. - Enhanced createPayment function to add devices to a group upon successful payment verification. - Improved payment verification process to include device management. - Refactored PaymentsTable and DevicesToPay components for better UI and state handling. - Removed unused hasSession function from auth-guard.ts for cleaner code.
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
import prisma from "@/lib/db";
|
||||
import type { PaymentType } from "@/lib/types";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { addDevicesToGroup } from "./omada-actions";
|
||||
|
||||
export async function createPayment(data: PaymentType) {
|
||||
console.log("data", data);
|
||||
@ -40,6 +41,9 @@ export async function verifyPayment(data: VerifyPaymentType) {
|
||||
where: {
|
||||
id: data.paymentId,
|
||||
},
|
||||
include: {
|
||||
devices: true,
|
||||
},
|
||||
});
|
||||
const response = await fetch(
|
||||
"https://verifypaymentsapi.baraveli.dev/verify-payment",
|
||||
@ -53,19 +57,38 @@ export async function verifyPayment(data: VerifyPaymentType) {
|
||||
);
|
||||
const json = await response.json();
|
||||
console.log(json);
|
||||
const newDevices = payment?.devices.map((d) => {
|
||||
return {
|
||||
name: d.name,
|
||||
macAddress: d.mac,
|
||||
};
|
||||
});
|
||||
if (json.success === true) {
|
||||
await prisma.payment.update({
|
||||
where: {
|
||||
id: payment?.id,
|
||||
},
|
||||
data: {
|
||||
paid: true,
|
||||
},
|
||||
});
|
||||
await Promise.all([
|
||||
prisma.payment.update({
|
||||
where: {
|
||||
id: payment?.id,
|
||||
},
|
||||
data: {
|
||||
paid: true,
|
||||
},
|
||||
}),
|
||||
addDevicesToGroup({
|
||||
groupId: process.env.OMADA_GROUP_ID,
|
||||
omadacId: process.env.OMADA_CID,
|
||||
siteId: process.env.OMADA_SITE_ID,
|
||||
newDevices: newDevices || [],
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
revalidatePath("/payment[paymentId]");
|
||||
return json;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function addDevicesToOmada() {
|
||||
console.log("hi");
|
||||
}
|
||||
|
Reference in New Issue
Block a user