Skip to content

Commit

Permalink
refactor : replace MongoDB ObjectId with Mongoose ObjectId
Browse files Browse the repository at this point in the history
- Uninstalled the mongodb package as it is no longer needed
  • Loading branch information
ad956 committed Jul 3, 2024
1 parent 0a122eb commit faf0259
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/api/patient/appointment/pending/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dbConfig from "@utils/db";
import { ObjectId } from "mongodb";
import { decrypt } from "@sessions/sessionUtils";
import { Patient, BookedAppointment } from "@models/index";
import { Type } from "mongoose";

export async function POST(req: Request) {
const session = req.headers.get("Authorization");
Expand All @@ -27,7 +27,7 @@ export async function POST(req: Request) {
// Checking if a pending appointment request exists with the hospital
const alreadyBookedAppointment = await BookedAppointment.findOne({
patient_id: patient._id,
"hospital.id": new ObjectId(hospital_id),
"hospital.id": new Types.ObjectId(hospital_id),
approved: "pending",
});

Expand Down
4 changes: 2 additions & 2 deletions app/api/patient/appointment/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dbConfig from "@utils/db";
import { bookingAppointment } from "@types";
import { decrypt } from "@sessions/sessionUtils";
import { ObjectId } from "mongodb";
import { Types } from "mongoose";
import sendEmail from "@lib/sendemail";
import { render } from "@react-email/render";
import { AppointmentBookedTemplate } from "@lib/emails/templates";
Expand Down Expand Up @@ -110,7 +110,7 @@ export async function POST(req: Request) {
state,
city,
hospital: {
id: new ObjectId(hospital.hospital_id),
id: new Types.ObjectId(hospital.hospital_id),
name: hospital.hospital_name,
},
disease,
Expand Down
1 change: 0 additions & 1 deletion app/api/patient/paymenthistory/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ObjectId } from "mongodb";
import dbConfig from "@utils/db";
import { decrypt } from "@sessions/sessionUtils";
import { Patient, Hospital, Transaction } from "@models/index";
Expand Down
4 changes: 2 additions & 2 deletions app/api/receptionist/appointments/approve/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dbConfig from "@utils/db";
import { decrypt } from "@sessions/sessionUtils";
import { ObjectId } from "mongodb";
import { BookedAppointment, Receptionist } from "@models/index";
import { Types } from "mongoose";

// get approved appointments
export async function GET(request: Request) {
Expand Down Expand Up @@ -36,7 +36,7 @@ export async function GET(request: Request) {
}

// Convert the patient_id string to an ObjectId
const patientObjectId = new ObjectId(patient_id);
const patientObjectId = new Types.ObjectId(patient_id);

await dbConfig();

Expand Down
4 changes: 2 additions & 2 deletions app/api/receptionist/scan/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dbConfig from "@utils/db";
import { ObjectId } from "mongodb";
import { BookedAppointment, Patient, Receptionist } from "@models/index";
import { Types } from "mongoose";

export async function POST(req: Request) {
try {
Expand All @@ -21,7 +21,7 @@ export async function POST(req: Request) {
}

const appointment = await BookedAppointment.findOne({
patient_id: new ObjectId(patient._id),
patient_id: new Types.ObjectId(patient._id),
approved: "pending",
});

Expand Down
6 changes: 3 additions & 3 deletions app/api/transactions/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dbConfig from "@utils/db";
import { Transaction as TransactionType } from "@types";
import { ObjectId } from "mongodb";
import Transaction from "@models/transaction";
import { Types } from "mongoose";

// saving transaction details in db
export async function POST(req: Request) {
Expand All @@ -27,8 +27,8 @@ export async function POST(req: Request) {
const transactionData = {
transaction_id,
timestamp,
patient: new ObjectId(patient_id),
hospital: new ObjectId(hospital_id),
patient: new Types.ObjectId(patient_id),
hospital: new Types.ObjectId(hospital_id),
disease,
description,
amount,
Expand Down
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"dom-to-image": "^2.6.0",
"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",
Expand Down

0 comments on commit faf0259

Please sign in to comment.