From 17beeb8a5e2a891a16624ccdc1e8a5d166591622 Mon Sep 17 00:00:00 2001 From: Anand Suthar Date: Mon, 1 Jul 2024 23:43:23 +0530 Subject: [PATCH] Switched to src directory Added mongoose minor import alias fixes --- package-lock.json | 84 +++++++++++++++++-- package.json | 2 + src/app/api/auth/login/route.ts | 44 ++++++---- src/app/api/auth/signup/route.ts | 27 +++++- src/app/api/auth/verifyotp/route.ts | 6 +- src/app/api/city/route.ts | 2 +- src/app/api/doctor/route.ts | 2 +- src/app/api/gethospitals/disease/route.ts | 2 +- src/app/api/gethospitals/route.ts | 2 +- .../api/patient/appointment/pending/route.ts | 4 +- src/app/api/patient/appointment/route.ts | 10 +-- src/app/api/patient/medicalhistory/route.ts | 4 +- src/app/api/patient/notifications/route.ts | 4 +- src/app/api/patient/paymenthistory/route.ts | 4 +- src/app/api/patient/route.ts | 4 +- .../patient/update-profile/profile/route.ts | 4 +- src/app/api/patient/update-profile/route.ts | 4 +- src/app/api/payment/create-order/route.ts | 2 +- .../appointments/approve/route.ts | 4 +- .../appointments/pending/route.ts | 4 +- src/app/api/receptionist/route.ts | 4 +- src/app/api/receptionist/scan/route.ts | 2 +- src/app/api/states/route.ts | 2 +- src/app/api/transactions/route.ts | 2 +- src/app/components/error-boundary/index.tsx | 2 +- src/app/components/headbar/index.tsx | 2 +- src/app/components/otp/index.tsx | 2 +- src/{ => app}/lib/actions.ts | 0 src/app/lib/db.ts | 39 +++++++++ src/{ => app}/lib/email.ts | 0 src/{ => app}/lib/emails/templates.tsx | 0 src/{ => app}/lib/logs/index.tsx | 0 src/{ => app}/lib/novu/index.tsx | 0 src/{ => app}/lib/patient/bookAppointment.tsx | 0 src/{ => app}/lib/patient/getPatientData.tsx | 0 .../lib/patient/getPatientMedicalHistory.tsx | 0 .../lib/patient/getPaymentsHistory.tsx | 0 .../lib/patient/getUpcomingAppointments.tsx | 0 src/{ => app}/lib/patient/index.tsx | 0 src/{ => app}/lib/patient/misc/getCities.tsx | 0 .../lib/patient/misc/getDiseases.tsx | 0 .../lib/patient/misc/getHospitals.tsx | 0 src/{ => app}/lib/patient/misc/getStates.tsx | 0 src/{ => app}/lib/patient/misc/index.tsx | 0 .../lib/patient/pendingAppointmentsReq.tsx | 0 .../patient/saveAppointmentTransaction.tsx | 0 .../lib/patient/updateProfilePicture.tsx | 0 src/{ => app}/lib/razorpay/createOrderId.ts | 0 src/{ => app}/lib/razorpay/index.ts | 0 src/{ => app}/lib/razorpay/razorpay.ts | 0 .../lib/receptionist/approveAppointment.tsx | 0 .../receptionist/getPendingAppointments.tsx | 0 .../lib/receptionist/getReceptionistData.tsx | 0 src/{ => app}/lib/receptionist/index.tsx | 0 src/{ => app}/lib/receptionist/scanQrCode.tsx | 0 src/{ => app}/lib/sessions/sessionUtils.ts | 0 src/{ => app}/lib/verifyOtp.ts | 0 src/lib/db.ts | 18 ---- tsconfig.json | 4 +- 59 files changed, 210 insertions(+), 86 deletions(-) rename src/{ => app}/lib/actions.ts (100%) create mode 100644 src/app/lib/db.ts rename src/{ => app}/lib/email.ts (100%) rename src/{ => app}/lib/emails/templates.tsx (100%) rename src/{ => app}/lib/logs/index.tsx (100%) rename src/{ => app}/lib/novu/index.tsx (100%) rename src/{ => app}/lib/patient/bookAppointment.tsx (100%) rename src/{ => app}/lib/patient/getPatientData.tsx (100%) rename src/{ => app}/lib/patient/getPatientMedicalHistory.tsx (100%) rename src/{ => app}/lib/patient/getPaymentsHistory.tsx (100%) rename src/{ => app}/lib/patient/getUpcomingAppointments.tsx (100%) rename src/{ => app}/lib/patient/index.tsx (100%) rename src/{ => app}/lib/patient/misc/getCities.tsx (100%) rename src/{ => app}/lib/patient/misc/getDiseases.tsx (100%) rename src/{ => app}/lib/patient/misc/getHospitals.tsx (100%) rename src/{ => app}/lib/patient/misc/getStates.tsx (100%) rename src/{ => app}/lib/patient/misc/index.tsx (100%) rename src/{ => app}/lib/patient/pendingAppointmentsReq.tsx (100%) rename src/{ => app}/lib/patient/saveAppointmentTransaction.tsx (100%) rename src/{ => app}/lib/patient/updateProfilePicture.tsx (100%) rename src/{ => app}/lib/razorpay/createOrderId.ts (100%) rename src/{ => app}/lib/razorpay/index.ts (100%) rename src/{ => app}/lib/razorpay/razorpay.ts (100%) rename src/{ => app}/lib/receptionist/approveAppointment.tsx (100%) rename src/{ => app}/lib/receptionist/getPendingAppointments.tsx (100%) rename src/{ => app}/lib/receptionist/getReceptionistData.tsx (100%) rename src/{ => app}/lib/receptionist/index.tsx (100%) rename src/{ => app}/lib/receptionist/scanQrCode.tsx (100%) rename src/{ => app}/lib/sessions/sessionUtils.ts (100%) rename src/{ => app}/lib/verifyOtp.ts (100%) delete mode 100644 src/lib/db.ts diff --git a/package-lock.json b/package-lock.json index b2c004ac..ca9c6b11 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,7 @@ "framer-motion": "^11.1.7", "jose": "^5.2.3", "mongodb": "^6.5.0", + "mongoose": "^8.4.4", "next": "14.1.0", "next-cloudinary": "^6.6.2", "next-qrcode": "^2.5.1", @@ -44,6 +45,7 @@ "@types/bcrypt": "^5.0.2", "@types/dom-to-image": "^2.6.7", "@types/js-cookie": "^3.0.6", + "@types/mongoose": "^5.11.97", "@types/node": "^20", "@types/nodemailer": "^6.4.14", "@types/react": "^18", @@ -5961,6 +5963,16 @@ "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.5.tgz", "integrity": "sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag==" }, + "node_modules/@types/mongoose": { + "version": "5.11.97", + "resolved": "https://registry.npmjs.org/@types/mongoose/-/mongoose-5.11.97.tgz", + "integrity": "sha512-cqwOVYT3qXyLiGw7ueU2kX9noE8DPGRY6z8eUxudhXY8NZ7DMKYAxyZkLSevGfhCX3dO/AoX5/SO9lAzfjon0Q==", + "deprecated": "Mongoose publishes its own types, so you do not need to install this package.", + "dev": true, + "dependencies": { + "mongoose": "*" + } + }, "node_modules/@types/node": { "version": "20.11.20", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.20.tgz", @@ -6986,9 +6998,9 @@ } }, "node_modules/bson": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/bson/-/bson-6.5.0.tgz", - "integrity": "sha512-DXf1BTAS8vKyR90BO4x5v3rKVarmkdkzwOrnYDFdjAY694ILNDkmA3uRh1xXJEl+C1DAh8XCvAQ+Gh3kzubtpg==", + "version": "6.8.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-6.8.0.tgz", + "integrity": "sha512-iOJg8pr7wq2tg/zSlCCHMi3hMm5JTOxLTagf3zxhcenHsFp+c6uOs6K7W5UE7A4QIJGtqh/ZovFNMP4mOPJynQ==", "engines": { "node": ">=16.20.1" } @@ -10177,6 +10189,14 @@ "node": ">=4.0" } }, + "node_modules/kareem": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.6.3.tgz", + "integrity": "sha512-C3iHfuGUXK2u8/ipq9LfjFfXFxAZMQJJq7vLS45r3D9Y2xQ/m4S8zaR4zMLFWh9AsNPXmcFfUDhTEO8UIC/V6Q==", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -10595,12 +10615,12 @@ } }, "node_modules/mongodb": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.5.0.tgz", - "integrity": "sha512-Fozq68InT+JKABGLqctgtb8P56pRrJFkbhW0ux+x1mdHeyinor8oNzJqwLjV/t5X5nJGfTlluxfyMnOXNggIUA==", + "version": "6.6.2", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.6.2.tgz", + "integrity": "sha512-ZF9Ugo2JCG/GfR7DEb4ypfyJJyiKbg5qBYKRintebj8+DNS33CyGMkWbrS9lara+u+h+yEOGSRiLhFO/g1s1aw==", "dependencies": { "@mongodb-js/saslprep": "^1.1.5", - "bson": "^6.4.0", + "bson": "^6.7.0", "mongodb-connection-string-url": "^3.0.0" }, "engines": { @@ -10648,6 +10668,51 @@ "whatwg-url": "^13.0.0" } }, + "node_modules/mongoose": { + "version": "8.4.4", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.4.4.tgz", + "integrity": "sha512-Nya808odIJoHP4JuJKbWA2eIaerXieu59kE8pQlvJpUBoSKWUyhLji0g1WMVaYXWmzPYXP2Jd6XdR4KJE8RELw==", + "dependencies": { + "bson": "^6.7.0", + "kareem": "2.6.3", + "mongodb": "6.6.2", + "mpath": "0.9.0", + "mquery": "5.0.0", + "ms": "2.1.3", + "sift": "17.1.3" + }, + "engines": { + "node": ">=16.20.1" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mongoose" + } + }, + "node_modules/mongoose/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/mpath": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", + "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/mquery": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz", + "integrity": "sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==", + "dependencies": { + "debug": "4.x" + }, + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -12726,6 +12791,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sift": { + "version": "17.1.3", + "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", + "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==" + }, "node_modules/signal-exit": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", diff --git a/package.json b/package.json index 0dc7641c..1594ad68 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "framer-motion": "^11.1.7", "jose": "^5.2.3", "mongodb": "^6.5.0", + "mongoose": "^8.4.4", "next": "14.1.0", "next-cloudinary": "^6.6.2", "next-qrcode": "^2.5.1", @@ -47,6 +48,7 @@ "@types/bcrypt": "^5.0.2", "@types/dom-to-image": "^2.6.7", "@types/js-cookie": "^3.0.6", + "@types/mongoose": "^5.11.97", "@types/node": "^20", "@types/nodemailer": "^6.4.14", "@types/react": "^18", diff --git a/src/app/api/auth/login/route.ts b/src/app/api/auth/login/route.ts index d599a1b5..d6982ded 100644 --- a/src/app/api/auth/login/route.ts +++ b/src/app/api/auth/login/route.ts @@ -4,6 +4,7 @@ import { sendEmail } from "@lib/email"; import { render } from "@react-email/render"; import { generateSecureOTP } from "@utils/generateOtp"; import bcrypt from "bcrypt"; +import { Patient } from "@/app/models/"; type LoginBody = { email: string; @@ -37,23 +38,9 @@ export async function POST(req: Request) { } async function setOTP(loginBody: LoginBody) { - const db = await dbConfig(); + await dbConfig(); - const collection = db.collection(loginBody.role); - const email = loginBody.email; - const projection = { - _id: 0, - email: 1, - firstname: 1, - lastname: 1, - password: 1, - }; - const user = await collection.findOne( - { email }, - { - projection, - } - ); + const user = await getUserModel(loginBody.email, loginBody.role); if (!user || !(await bcrypt.compare(loginBody.password, user.password))) { return Response.json( @@ -63,7 +50,10 @@ async function setOTP(loginBody: LoginBody) { } const generatedOTP = generateSecureOTP(); - await collection.updateOne({ email }, { $set: { otp: generatedOTP } }); + await user.updateOne( + { email: loginBody.email }, + { $set: { otp: generatedOTP } } + ); const send = { to: user.email, @@ -85,3 +75,23 @@ async function setOTP(loginBody: LoginBody) { if (!mailsent) return Response.json({ error: "Email Sending Failed" }); return Response.json({ message: "ok" }, { status: 201 }); } + +export async function getUserModel(email: string, role: string) { + const projection = { + _id: 0, + email: 1, + firstname: 1, + lastname: 1, + password: 1, + }; + switch (role) { + case "patient": + return await Patient.findOne({ email }, projection); + // case "hospital": + // return await Hospital.findOne({ email }, projection); + case "receptionist": + return await Receptionist.findOne({ email }, projection); + default: + return null; + } +} diff --git a/src/app/api/auth/signup/route.ts b/src/app/api/auth/signup/route.ts index d883bccf..129de3a5 100644 --- a/src/app/api/auth/signup/route.ts +++ b/src/app/api/auth/signup/route.ts @@ -1,6 +1,6 @@ -import dbConfig from "@lib/db"; -import { OtpTemplate } from "@/lib/emails/templates"; -import { sendEmail } from "@lib/email"; +import dbConfig from "@/app/lib/db"; +import { OtpTemplate } from "@/app/lib/emails/templates"; +import { sendEmail } from "@/app/lib/email"; import { render } from "@react-email/render"; import { generateSecureOTP } from "@utils/generateOtp"; import { @@ -10,6 +10,7 @@ import { receptionistadditionalDetails, } from "@constants/index"; import bcrypt from "bcrypt"; +import { Patient } from "@/app/models/Patient"; type SignupBody = { firstname: string; @@ -145,3 +146,23 @@ async function hashPassword(password: string) { const hashedPassword = await bcrypt.hash(password, saltRounds); return hashedPassword; } + +export async function getUserModel(email: string, role: string) { + const projection = { + _id: 0, + email: 1, + firstname: 1, + lastname: 1, + password: 1, + }; + switch (role) { + case "patient": + return await Patient.findOne({ email }, projection); + case "hospital": + return await Hospital.findOne({ email }, projection); + case "receptionist": + return await Receptionist.findOne({ email }, projection); + default: + return null; + } +} diff --git a/src/app/api/auth/verifyotp/route.ts b/src/app/api/auth/verifyotp/route.ts index 24e45ca4..13b4f42f 100644 --- a/src/app/api/auth/verifyotp/route.ts +++ b/src/app/api/auth/verifyotp/route.ts @@ -1,6 +1,6 @@ -import { setSession } from "@sessions/sessionUtils"; -import dbConfig from "@lib/db"; -import logUserActivity from "@lib/logs"; +import { setSession } from "@/app/lib/sessions/sessionUtils"; +import dbConfig from "@/app/lib/db"; +import logUserActivity from "@/app/lib/logs"; type bodyType = { email: string; diff --git a/src/app/api/city/route.ts b/src/app/api/city/route.ts index 21a629fc..74ad6153 100644 --- a/src/app/api/city/route.ts +++ b/src/app/api/city/route.ts @@ -1,4 +1,4 @@ -import dbConfig from "@lib/db"; +import dbConfig from "@/app/lib/db"; export async function GET(req: Request) { const { searchParams } = new URL(req.url); diff --git a/src/app/api/doctor/route.ts b/src/app/api/doctor/route.ts index 482d0245..de9f8be1 100644 --- a/src/app/api/doctor/route.ts +++ b/src/app/api/doctor/route.ts @@ -1,4 +1,4 @@ -import dbConfig from "@lib/db"; +import dbConfig from "@/app/lib/db"; export async function GET(req: Request) { const { searchParams } = new URL(req.url); diff --git a/src/app/api/gethospitals/disease/route.ts b/src/app/api/gethospitals/disease/route.ts index 8a2630d8..e3efef6c 100644 --- a/src/app/api/gethospitals/disease/route.ts +++ b/src/app/api/gethospitals/disease/route.ts @@ -1,4 +1,4 @@ -import dbConfig from "@lib/db"; +import dbConfig from "@/app/lib/db"; export async function GET() { try { diff --git a/src/app/api/gethospitals/route.ts b/src/app/api/gethospitals/route.ts index 96e87bc4..5144b0c2 100644 --- a/src/app/api/gethospitals/route.ts +++ b/src/app/api/gethospitals/route.ts @@ -1,4 +1,4 @@ -import dbConfig from "@lib/db"; +import dbConfig from "@/app/lib/db"; export async function GET(req: Request) { const { searchParams } = new URL(req.url); diff --git a/src/app/api/patient/appointment/pending/route.ts b/src/app/api/patient/appointment/pending/route.ts index fbc9c6d7..6aeae06e 100644 --- a/src/app/api/patient/appointment/pending/route.ts +++ b/src/app/api/patient/appointment/pending/route.ts @@ -1,6 +1,6 @@ -import dbConfig from "@lib/db"; +import dbConfig from "@/app/lib/db"; import { ObjectId } from "mongodb"; -import { decrypt } from "@sessions/sessionUtils"; +import { decrypt } from "@/app/lib/sessions/sessionUtils"; export async function POST(req: Request) { const session = req.headers.get("Authorization"); diff --git a/src/app/api/patient/appointment/route.ts b/src/app/api/patient/appointment/route.ts index b032774b..aa0b54ce 100644 --- a/src/app/api/patient/appointment/route.ts +++ b/src/app/api/patient/appointment/route.ts @@ -1,12 +1,12 @@ -import dbConfig from "@lib/db"; +import dbConfig from "@/app/lib/db"; import { bookingAppointment } from "@/types"; -import { decrypt } from "@sessions/sessionUtils"; +import { decrypt } from "@/app/lib/sessions/sessionUtils"; import { ObjectId } from "mongodb"; -import { sendEmail } from "@lib/email"; +import { sendEmail } from "@/app/lib/email"; import { render } from "@react-email/render"; -import { AppointmentBookedTemplate } from "@lib/emails/templates"; +import { AppointmentBookedTemplate } from "@/app/lib/emails/templates"; import { getFormattedDate } from "@/app/utils/getDate"; -import sendNotification from "@lib/novu"; +import sendNotification from "@/app/lib/novu"; type BookingAppointmentType = bookingAppointment & { transaction_id: string | null; diff --git a/src/app/api/patient/medicalhistory/route.ts b/src/app/api/patient/medicalhistory/route.ts index a0ee1852..49a5fea8 100644 --- a/src/app/api/patient/medicalhistory/route.ts +++ b/src/app/api/patient/medicalhistory/route.ts @@ -1,5 +1,5 @@ -import dbConfig from "@lib/db"; -import { decrypt } from "@sessions/sessionUtils"; +import dbConfig from "@/app/lib/db"; +import { decrypt } from "@/app/lib/sessions/sessionUtils"; export async function GET(request: Request) { const session = request.headers.get("Authorization"); diff --git a/src/app/api/patient/notifications/route.ts b/src/app/api/patient/notifications/route.ts index d11f6d4a..cfda7ce5 100644 --- a/src/app/api/patient/notifications/route.ts +++ b/src/app/api/patient/notifications/route.ts @@ -1,5 +1,5 @@ -import dbConfig from "@lib/db"; -import { decrypt } from "@sessions/sessionUtils"; +import dbConfig from "@/app/lib/db"; +import { decrypt } from "@/app/lib/sessions/sessionUtils"; export async function GET(request: Request) { const session = request.headers.get("Authorization"); diff --git a/src/app/api/patient/paymenthistory/route.ts b/src/app/api/patient/paymenthistory/route.ts index 240335d4..2e845dd6 100644 --- a/src/app/api/patient/paymenthistory/route.ts +++ b/src/app/api/patient/paymenthistory/route.ts @@ -1,6 +1,6 @@ import { ObjectId } from "mongodb"; -import dbConfig from "@lib/db"; -import { decrypt } from "@sessions/sessionUtils"; +import dbConfig from "@/app/lib/db"; +import { decrypt } from "@/app/lib/sessions/sessionUtils"; interface Transaction { _id: ObjectId; diff --git a/src/app/api/patient/route.ts b/src/app/api/patient/route.ts index 5a67c9e6..1c10910d 100644 --- a/src/app/api/patient/route.ts +++ b/src/app/api/patient/route.ts @@ -1,5 +1,5 @@ -import dbConfig from "@lib/db"; -import { decrypt } from "@sessions/sessionUtils"; +import dbConfig from "@/app/lib/db"; +import { decrypt } from "@/app/lib/sessions/sessionUtils"; export async function GET(request: Request) { const session = request.headers.get("Authorization"); diff --git a/src/app/api/patient/update-profile/profile/route.ts b/src/app/api/patient/update-profile/profile/route.ts index 4be70318..29d62a36 100644 --- a/src/app/api/patient/update-profile/profile/route.ts +++ b/src/app/api/patient/update-profile/profile/route.ts @@ -1,5 +1,5 @@ -import dbConfig from "@lib/db"; -import { decrypt } from "@sessions/sessionUtils"; +import dbConfig from "@/app/lib/db"; +import { decrypt } from "@/app/lib/sessions/sessionUtils"; export async function PUT(request: Request) { // const session = request.headers.get("Authorization"); diff --git a/src/app/api/patient/update-profile/route.ts b/src/app/api/patient/update-profile/route.ts index 3e620cdd..cd2806be 100644 --- a/src/app/api/patient/update-profile/route.ts +++ b/src/app/api/patient/update-profile/route.ts @@ -1,6 +1,6 @@ import { User } from "@/types"; -import dbConfig from "@lib/db"; -import { decrypt } from "@sessions/sessionUtils"; +import dbConfig from "@/app/lib/db"; +import { decrypt } from "@/app/lib/sessions/sessionUtils"; type UpdatedUserType = Omit; diff --git a/src/app/api/payment/create-order/route.ts b/src/app/api/payment/create-order/route.ts index 19261324..e7b7df3f 100644 --- a/src/app/api/payment/create-order/route.ts +++ b/src/app/api/payment/create-order/route.ts @@ -1,5 +1,5 @@ import { NextRequest } from "next/server"; -import { razorpay } from "@lib/razorpay"; +import { razorpay } from "@/app/lib/razorpay"; export async function POST(request: NextRequest) { const { amount, currency } = (await request.json()) as { diff --git a/src/app/api/receptionist/appointments/approve/route.ts b/src/app/api/receptionist/appointments/approve/route.ts index 33e89c1f..bce7b568 100644 --- a/src/app/api/receptionist/appointments/approve/route.ts +++ b/src/app/api/receptionist/appointments/approve/route.ts @@ -1,5 +1,5 @@ -import dbConfig from "@lib/db"; -import { decrypt } from "@sessions/sessionUtils"; +import dbConfig from "@/app/lib/db"; +import { decrypt } from "@/app/lib/sessions/sessionUtils"; import { ObjectId } from "mongodb"; export async function GET(request: Request) { diff --git a/src/app/api/receptionist/appointments/pending/route.ts b/src/app/api/receptionist/appointments/pending/route.ts index bbbf7b82..14d09b98 100644 --- a/src/app/api/receptionist/appointments/pending/route.ts +++ b/src/app/api/receptionist/appointments/pending/route.ts @@ -1,5 +1,5 @@ -import dbConfig from "@lib/db"; -import { decrypt } from "@sessions/sessionUtils"; +import dbConfig from "@/app/lib/db"; +import { decrypt } from "@/app/lib/sessions/sessionUtils"; export async function GET(request: Request) { const session = request.headers.get("Authorization"); diff --git a/src/app/api/receptionist/route.ts b/src/app/api/receptionist/route.ts index 36751dd2..e0fc8614 100644 --- a/src/app/api/receptionist/route.ts +++ b/src/app/api/receptionist/route.ts @@ -1,5 +1,5 @@ -import dbConfig from "@lib/db"; -import { decrypt } from "@sessions/sessionUtils"; +import dbConfig from "@/app/lib/db"; +import { decrypt } from "@/app/lib/sessions/sessionUtils"; export async function GET(request: Request) { const session = request.headers.get("Authorization"); diff --git a/src/app/api/receptionist/scan/route.ts b/src/app/api/receptionist/scan/route.ts index c7541153..d2307718 100644 --- a/src/app/api/receptionist/scan/route.ts +++ b/src/app/api/receptionist/scan/route.ts @@ -1,4 +1,4 @@ -import dbConfig from "@lib/db"; +import dbConfig from "@/app/lib/db"; import { ObjectId } from "mongodb"; export async function POST(req: Request) { diff --git a/src/app/api/states/route.ts b/src/app/api/states/route.ts index 15b65556..d105be55 100644 --- a/src/app/api/states/route.ts +++ b/src/app/api/states/route.ts @@ -1,4 +1,4 @@ -import dbConfig from "@lib/db"; +import dbConfig from "@/app/lib/db"; export async function GET(req: Request) { try { diff --git a/src/app/api/transactions/route.ts b/src/app/api/transactions/route.ts index 349365e4..40aa8b47 100644 --- a/src/app/api/transactions/route.ts +++ b/src/app/api/transactions/route.ts @@ -1,4 +1,4 @@ -import dbConfig from "@lib/db"; +import dbConfig from "@/app/lib/db"; import { Transaction } from "@/types"; import { ObjectId } from "mongodb"; diff --git a/src/app/components/error-boundary/index.tsx b/src/app/components/error-boundary/index.tsx index 297fdd99..ce714c4d 100644 --- a/src/app/components/error-boundary/index.tsx +++ b/src/app/components/error-boundary/index.tsx @@ -1,5 +1,5 @@ "use client"; -import { logoutAction } from "@/lib/actions"; +import { logoutAction } from "@/app/lib/actions"; import { Button, Image } from "@nextui-org/react"; import React, { ErrorInfo, ReactNode } from "react"; diff --git a/src/app/components/headbar/index.tsx b/src/app/components/headbar/index.tsx index cc6f3d70..c314e262 100644 --- a/src/app/components/headbar/index.tsx +++ b/src/app/components/headbar/index.tsx @@ -3,7 +3,7 @@ import { Button, Divider, User } from "@nextui-org/react"; import { CiLogin } from "react-icons/ci"; import { GoPlus } from "react-icons/go"; import { User as UserType } from "@/types"; -import { logoutAction } from "@lib/actions"; +import { logoutAction } from "@/app/lib/actions"; import Notifications from "../notifications"; type HeadbarProps = { diff --git a/src/app/components/otp/index.tsx b/src/app/components/otp/index.tsx index a221229a..13a35069 100644 --- a/src/app/components/otp/index.tsx +++ b/src/app/components/otp/index.tsx @@ -12,7 +12,7 @@ import { import { useRouter } from "next/navigation"; import React, { useRef, useState } from "react"; import toast, { Toaster } from "react-hot-toast"; -import verifyOtp from "@lib/verifyOtp"; +import verifyOtp from "@/app/lib/verifyOtp"; type userDataType = { userData: { diff --git a/src/lib/actions.ts b/src/app/lib/actions.ts similarity index 100% rename from src/lib/actions.ts rename to src/app/lib/actions.ts diff --git a/src/app/lib/db.ts b/src/app/lib/db.ts new file mode 100644 index 00000000..437baba0 --- /dev/null +++ b/src/app/lib/db.ts @@ -0,0 +1,39 @@ +// import { MongoClient } from "mongodb"; + +// export default async function dbConfig() { +// let uri: string; +// if (process.env.NODE_ENV === "production") { +// uri = process.env.MONGODB_URI || "mongodb://localhost:27017/"; +// } else { +// uri = "mongodb://localhost:27017/"; +// } + +// const client = await MongoClient.connect(uri); +// if (!client) { +// throw new Error("Error connecting mongodb."); +// } +// const db = client.db("pft"); + +// return db; +// } + +import mongoose from "mongoose"; + +const connection: { isConnected?: number } = {}; + +let uri: string; +if (process.env.NODE_ENV === "production") { + uri = process.env.MONGODB_URI || "mongodb://localhost:27017/pft"; +} else { + uri = "mongodb://localhost:27017/pft"; +} + +export default async function dbConfig() { + if (connection.isConnected) { + return; + } + + const db = await mongoose.connect(uri); + + connection.isConnected = db.connections[0].readyState; +} diff --git a/src/lib/email.ts b/src/app/lib/email.ts similarity index 100% rename from src/lib/email.ts rename to src/app/lib/email.ts diff --git a/src/lib/emails/templates.tsx b/src/app/lib/emails/templates.tsx similarity index 100% rename from src/lib/emails/templates.tsx rename to src/app/lib/emails/templates.tsx diff --git a/src/lib/logs/index.tsx b/src/app/lib/logs/index.tsx similarity index 100% rename from src/lib/logs/index.tsx rename to src/app/lib/logs/index.tsx diff --git a/src/lib/novu/index.tsx b/src/app/lib/novu/index.tsx similarity index 100% rename from src/lib/novu/index.tsx rename to src/app/lib/novu/index.tsx diff --git a/src/lib/patient/bookAppointment.tsx b/src/app/lib/patient/bookAppointment.tsx similarity index 100% rename from src/lib/patient/bookAppointment.tsx rename to src/app/lib/patient/bookAppointment.tsx diff --git a/src/lib/patient/getPatientData.tsx b/src/app/lib/patient/getPatientData.tsx similarity index 100% rename from src/lib/patient/getPatientData.tsx rename to src/app/lib/patient/getPatientData.tsx diff --git a/src/lib/patient/getPatientMedicalHistory.tsx b/src/app/lib/patient/getPatientMedicalHistory.tsx similarity index 100% rename from src/lib/patient/getPatientMedicalHistory.tsx rename to src/app/lib/patient/getPatientMedicalHistory.tsx diff --git a/src/lib/patient/getPaymentsHistory.tsx b/src/app/lib/patient/getPaymentsHistory.tsx similarity index 100% rename from src/lib/patient/getPaymentsHistory.tsx rename to src/app/lib/patient/getPaymentsHistory.tsx diff --git a/src/lib/patient/getUpcomingAppointments.tsx b/src/app/lib/patient/getUpcomingAppointments.tsx similarity index 100% rename from src/lib/patient/getUpcomingAppointments.tsx rename to src/app/lib/patient/getUpcomingAppointments.tsx diff --git a/src/lib/patient/index.tsx b/src/app/lib/patient/index.tsx similarity index 100% rename from src/lib/patient/index.tsx rename to src/app/lib/patient/index.tsx diff --git a/src/lib/patient/misc/getCities.tsx b/src/app/lib/patient/misc/getCities.tsx similarity index 100% rename from src/lib/patient/misc/getCities.tsx rename to src/app/lib/patient/misc/getCities.tsx diff --git a/src/lib/patient/misc/getDiseases.tsx b/src/app/lib/patient/misc/getDiseases.tsx similarity index 100% rename from src/lib/patient/misc/getDiseases.tsx rename to src/app/lib/patient/misc/getDiseases.tsx diff --git a/src/lib/patient/misc/getHospitals.tsx b/src/app/lib/patient/misc/getHospitals.tsx similarity index 100% rename from src/lib/patient/misc/getHospitals.tsx rename to src/app/lib/patient/misc/getHospitals.tsx diff --git a/src/lib/patient/misc/getStates.tsx b/src/app/lib/patient/misc/getStates.tsx similarity index 100% rename from src/lib/patient/misc/getStates.tsx rename to src/app/lib/patient/misc/getStates.tsx diff --git a/src/lib/patient/misc/index.tsx b/src/app/lib/patient/misc/index.tsx similarity index 100% rename from src/lib/patient/misc/index.tsx rename to src/app/lib/patient/misc/index.tsx diff --git a/src/lib/patient/pendingAppointmentsReq.tsx b/src/app/lib/patient/pendingAppointmentsReq.tsx similarity index 100% rename from src/lib/patient/pendingAppointmentsReq.tsx rename to src/app/lib/patient/pendingAppointmentsReq.tsx diff --git a/src/lib/patient/saveAppointmentTransaction.tsx b/src/app/lib/patient/saveAppointmentTransaction.tsx similarity index 100% rename from src/lib/patient/saveAppointmentTransaction.tsx rename to src/app/lib/patient/saveAppointmentTransaction.tsx diff --git a/src/lib/patient/updateProfilePicture.tsx b/src/app/lib/patient/updateProfilePicture.tsx similarity index 100% rename from src/lib/patient/updateProfilePicture.tsx rename to src/app/lib/patient/updateProfilePicture.tsx diff --git a/src/lib/razorpay/createOrderId.ts b/src/app/lib/razorpay/createOrderId.ts similarity index 100% rename from src/lib/razorpay/createOrderId.ts rename to src/app/lib/razorpay/createOrderId.ts diff --git a/src/lib/razorpay/index.ts b/src/app/lib/razorpay/index.ts similarity index 100% rename from src/lib/razorpay/index.ts rename to src/app/lib/razorpay/index.ts diff --git a/src/lib/razorpay/razorpay.ts b/src/app/lib/razorpay/razorpay.ts similarity index 100% rename from src/lib/razorpay/razorpay.ts rename to src/app/lib/razorpay/razorpay.ts diff --git a/src/lib/receptionist/approveAppointment.tsx b/src/app/lib/receptionist/approveAppointment.tsx similarity index 100% rename from src/lib/receptionist/approveAppointment.tsx rename to src/app/lib/receptionist/approveAppointment.tsx diff --git a/src/lib/receptionist/getPendingAppointments.tsx b/src/app/lib/receptionist/getPendingAppointments.tsx similarity index 100% rename from src/lib/receptionist/getPendingAppointments.tsx rename to src/app/lib/receptionist/getPendingAppointments.tsx diff --git a/src/lib/receptionist/getReceptionistData.tsx b/src/app/lib/receptionist/getReceptionistData.tsx similarity index 100% rename from src/lib/receptionist/getReceptionistData.tsx rename to src/app/lib/receptionist/getReceptionistData.tsx diff --git a/src/lib/receptionist/index.tsx b/src/app/lib/receptionist/index.tsx similarity index 100% rename from src/lib/receptionist/index.tsx rename to src/app/lib/receptionist/index.tsx diff --git a/src/lib/receptionist/scanQrCode.tsx b/src/app/lib/receptionist/scanQrCode.tsx similarity index 100% rename from src/lib/receptionist/scanQrCode.tsx rename to src/app/lib/receptionist/scanQrCode.tsx diff --git a/src/lib/sessions/sessionUtils.ts b/src/app/lib/sessions/sessionUtils.ts similarity index 100% rename from src/lib/sessions/sessionUtils.ts rename to src/app/lib/sessions/sessionUtils.ts diff --git a/src/lib/verifyOtp.ts b/src/app/lib/verifyOtp.ts similarity index 100% rename from src/lib/verifyOtp.ts rename to src/app/lib/verifyOtp.ts diff --git a/src/lib/db.ts b/src/lib/db.ts deleted file mode 100644 index b825eaa4..00000000 --- a/src/lib/db.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { MongoClient } from "mongodb"; - -export default async function dbConfig() { - let uri: string; - if (process.env.NODE_ENV === "production") { - uri = process.env.MONGODB_URI || "mongodb://localhost:27017/"; - } else { - uri = "mongodb://localhost:27017/"; - } - - const client = await MongoClient.connect(uri); - if (!client) { - throw new Error("Error connecting mongodb."); - } - const db = client.db("pft"); - - return db; -} diff --git a/tsconfig.json b/tsconfig.json index 81e560ef..0ab2a177 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,8 +25,8 @@ "@constants/*": ["./src/app/utils/constants/*"], "@patient/*": ["./src/app/(pages)/patient/*"], "@receptionist/*": ["./src/app/(pages)/receptionist/*"], - "@lib/*": ["./src/lib/*"], - "@sessions/*": ["./src/lib/sessions/*"] + "@lib/*": ["./src/app/lib/*"], + "@sessions/*": ["./src/app/lib/sessions/*"] } }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],