sarlink-portal/actions/user-actions.ts

49 lines
1.0 KiB
TypeScript
Raw Normal View History

"use server";
import prisma from "@/lib/db";
import { revalidatePath } from "next/cache";
import { CreateClient } from "./ninja/client";
export async function VerifyUser(userId: string) {
const user = await prisma.user.findUnique({
where: {
id: userId,
},
include: {
atoll: true,
island: true,
},
});
if (!user) {
throw new Error("User not found");
}
await prisma.user.update({
where: {
id: userId,
},
data: {
verified: true,
},
});
await CreateClient({
group_settings_id: "",
address1: "",
city: user.atoll?.name || "",
state: user.island?.name || "",
postal_code: "",
country_id: "462",
address2: user.address || "",
contacts: {
first_name: user.name?.split(" ")[0] || "",
last_name: user.name?.split(" ")[1] || "",
email: user.email || "",
phone: user.phoneNumber || "",
send_email: false,
custom_value1: user.dob?.toISOString().split("T")[0] || "",
custom_value2: user.id_card || "",
custom_value3: "",
},
});
revalidatePath("/users");
}