2025-01-10 15:59:44 +05:00
|
|
|
"use server";
|
2025-01-10 21:58:13 +05:00
|
|
|
import type { TNationalPerson } from "@/lib/types";
|
2025-01-10 15:59:44 +05:00
|
|
|
import type { User } from "@prisma/client";
|
|
|
|
|
2025-01-10 21:58:13 +05:00
|
|
|
export async function getNationalPerson({
|
|
|
|
idCard,
|
|
|
|
}: { idCard: string }): Promise<TNationalPerson> {
|
|
|
|
const nationalInformation = await fetch(
|
|
|
|
`${process.env.PERSON_VERIFY_API_BASE}/api/person/${idCard}`,
|
|
|
|
{
|
|
|
|
next: {
|
|
|
|
revalidate: 60,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
const nationalData = (await nationalInformation.json()) as TNationalPerson;
|
|
|
|
return nationalData;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function VerifyUserDetails({ user }: { user: User }) {
|
2025-01-10 23:34:53 +05:00
|
|
|
const phoneNumber = String(user.phoneNumber).slice(4);
|
|
|
|
console.log({ phoneNumber });
|
2025-01-10 21:58:13 +05:00
|
|
|
const nationalData = await getNationalPerson({ idCard: user.id_card ?? "" });
|
2025-01-10 15:59:44 +05:00
|
|
|
const dob = new Date(nationalData.dob);
|
|
|
|
const age = new Date().getFullYear() - dob.getFullYear();
|
|
|
|
|
2025-01-10 23:34:53 +05:00
|
|
|
console.log("ID card", user.id_card === nationalData.nic);
|
|
|
|
console.log("name", user.name === nationalData.name_en);
|
|
|
|
console.log("house", user.address === nationalData.house_name_en);
|
|
|
|
console.log("phone", phoneNumber === nationalData.primary_contact);
|
|
|
|
console.log("db phone", phoneNumber);
|
|
|
|
console.log("national phone", nationalData.primary_contact);
|
|
|
|
|
2025-01-10 15:59:44 +05:00
|
|
|
if (
|
|
|
|
user.id_card === nationalData.nic &&
|
|
|
|
user.name === nationalData.name_en &&
|
|
|
|
user.address === nationalData.house_name_en &&
|
|
|
|
phoneNumber === nationalData.primary_contact &&
|
|
|
|
age >= 18
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|