Refactor user verification and data handling
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:
2025-01-10 21:58:13 +05:00
parent fcf4f37561
commit a3f0759731
8 changed files with 37 additions and 34 deletions

View File

@ -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'>

View File

@ -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++;