sarlink-portal/actions/user-actions.ts
i701 490150f9b7 Refactor user actions and authentication components
- Updated user verification logic to include atoll and island relationships.
- Introduced CreateClient function for integrating with external client API.
- Replaced 'house_name' with 'address' in user signup data handling.
- Added new Checkbox component for improved UI interactions.
- Migrated database provider from SQLite to PostgreSQL and redefined user schema.
- Removed obsolete migration files and ensured database integrity with new structure.
2024-11-30 23:38:20 +05:00

49 lines
1.0 KiB
TypeScript

"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");
}