mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-02-22 17:22:17 +00:00
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 55s
- Updated `package.json` to add a new script for Prisma database setup. - Replaced `usePerson` hook with `getNationalPerson` function in `lib/person.ts` for improved national data fetching. - Refactored imports in `auth-actions.ts`, `user-actions.ts`, and `verify/page.tsx` to use the new `getNationalPerson` function. - Enhanced device notification logic in `check-devices/route.ts` to correctly handle payment data. - Improved error handling in `devices-to-pay.tsx` for better user feedback. These changes streamline user verification processes and enhance data integrity across the application.
37 lines
1003 B
TypeScript
37 lines
1003 B
TypeScript
"use server";
|
|
import type { TNationalPerson } from "@/lib/types";
|
|
import type { User } from "@prisma/client";
|
|
|
|
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 }) {
|
|
const phoneNumber = user.phoneNumber.slice(4);
|
|
const nationalData = await getNationalPerson({ idCard: user.id_card ?? "" });
|
|
const dob = new Date(nationalData.dob);
|
|
const age = new Date().getFullYear() - dob.getFullYear();
|
|
|
|
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;
|
|
}
|