mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-02-20 19:42:00 +00:00
Refactor user verification and data handling
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 55s
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.
This commit is contained in:
parent
fcf4f37561
commit
a3f0759731
@ -2,7 +2,7 @@
|
||||
|
||||
import { authClient } from "@/lib/auth-client";
|
||||
import prisma from "@/lib/db";
|
||||
import VerifyUserDetails from "@/lib/person";
|
||||
import { VerifyUserDetails } from "@/lib/person";
|
||||
import { signUpFormSchema } from "@/lib/schemas";
|
||||
import { headers } from "next/headers";
|
||||
// import type { User } from "@prisma/client";
|
||||
|
@ -1,8 +1,7 @@
|
||||
"use server";
|
||||
|
||||
import usePerson from "@/hooks/use-person";
|
||||
import prisma from "@/lib/db";
|
||||
import VerifyUserDetails from "@/lib/person";
|
||||
import { VerifyUserDetails } from "@/lib/person";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
import { CreateClient } from "./ninja/client";
|
||||
|
@ -2,7 +2,7 @@ import InputReadOnly from '@/components/input-read-only';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import UserRejectDialog from '@/components/user/user-reject-dialog';
|
||||
import { UserVerifyDialog } from '@/components/user/user-verify-dialog';
|
||||
import usePerson from '@/hooks/use-person';
|
||||
import { getNationalPerson } from '@/lib/person';
|
||||
|
||||
import prisma from '@/lib/db';
|
||||
import Image from 'next/image';
|
||||
@ -28,7 +28,7 @@ export default async function VerifyUserPage({
|
||||
}
|
||||
})
|
||||
|
||||
const nationalData = await usePerson({ idCard: dbUser?.id_card ?? "" })
|
||||
const nationalData = await getNationalPerson({ idCard: dbUser?.id_card ?? "" })
|
||||
return (
|
||||
<div>
|
||||
<div className='flex items-center justify-between text-gray-500 text-2xl font-bold title-bg py-4 px-2 mb-4'>
|
||||
|
@ -21,8 +21,12 @@ export async function GET(request: Request) {
|
||||
blocked: false,
|
||||
},
|
||||
include: {
|
||||
payment: true,
|
||||
User: true,
|
||||
payments: true,
|
||||
User: {
|
||||
include: {
|
||||
devices: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
let devicesNeedingNotification = 0;
|
||||
@ -31,7 +35,7 @@ export async function GET(request: Request) {
|
||||
for (const device of devices) {
|
||||
let expiryDate = new Date();
|
||||
|
||||
const payment = device.payment;
|
||||
const payment = device.payments[0];
|
||||
expiryDate = addMonths(
|
||||
payment?.paidAt || new Date(),
|
||||
payment?.numberOfMonths || 0,
|
||||
@ -43,8 +47,8 @@ export async function GET(request: Request) {
|
||||
const currentDate = new Date();
|
||||
|
||||
console.log("device name -> ", device.name);
|
||||
console.log("paid date -> ", device.payment?.paidAt);
|
||||
console.log("no of months paid -> ", device.payment?.numberOfMonths);
|
||||
console.log("paid date -> ", device.payments[0]?.paidAt);
|
||||
console.log("no of months paid -> ", device.payments[0]?.numberOfMonths);
|
||||
console.log("calculated expire date -> ", expiryDate);
|
||||
console.log("notification threshold -> ", notificationThreshold);
|
||||
console.log("current date -> ", currentDate);
|
||||
@ -60,7 +64,7 @@ export async function GET(request: Request) {
|
||||
if (device.User?.phoneNumber) {
|
||||
await sendNotifySms(
|
||||
new Date(expiryDate),
|
||||
device.User.phoneNumber,
|
||||
device.User?.phoneNumber ?? "",
|
||||
device.name,
|
||||
);
|
||||
devicesNeedingNotification++;
|
||||
|
@ -110,8 +110,8 @@ export default function DevicesToPay({
|
||||
case res?.success === true:
|
||||
toast.success(res.message);
|
||||
break;
|
||||
case res.success === false:
|
||||
toast.error(res.message);
|
||||
case res?.success === false:
|
||||
toast.error(res?.message);
|
||||
break;
|
||||
default:
|
||||
toast.error("Unexpected error occurred.");
|
||||
|
@ -1,16 +0,0 @@
|
||||
import type { TNationalPerson } from "@/lib/types";
|
||||
|
||||
export default async function usePerson({
|
||||
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;
|
||||
}
|
@ -1,10 +1,25 @@
|
||||
"use server";
|
||||
import usePerson from "@/hooks/use-person";
|
||||
import type { TNationalPerson } from "@/lib/types";
|
||||
import type { User } from "@prisma/client";
|
||||
|
||||
export default async function VerifyUserDetails({ user }: { user: User }) {
|
||||
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 usePerson({ idCard: user.id_card ?? "" });
|
||||
const nationalData = await getNationalPerson({ idCard: user.id_card ?? "" });
|
||||
const dob = new Date(nationalData.dob);
|
||||
const age = new Date().getFullYear() - dob.getFullYear();
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
"lint": "next lint",
|
||||
"studio": "bunx prisma studio",
|
||||
"push": "bunx prisma db push",
|
||||
"db-setup": "bunx prisma migrate deploy && bunx prisma generate && bunx prisma db push"
|
||||
"db-setup": "bunx prisma migrate deploy && bunx prisma generate && bunx prisma db push"
|
||||
},
|
||||
"prisma": {
|
||||
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
|
||||
@ -66,5 +66,6 @@
|
||||
"tailwindcss": "^3.4.17",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.7.2"
|
||||
}
|
||||
},
|
||||
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user