combine endpoints for saving
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
import { User } from '../../../models/User';
|
||||
import { connectDB } from '../../../lib/utils';
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export async function PUT(req) {
|
||||
console.log('Processing patient update request...');
|
||||
|
||||
await connectDB();
|
||||
|
||||
try {
|
||||
const url = new URL(req.url);
|
||||
const email = url.searchParams.get('email');
|
||||
|
||||
if (!email) {
|
||||
console.log('No email provided');
|
||||
return NextResponse.json(
|
||||
{ message: 'Email is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const body = await req.json();
|
||||
const { medications, medicalConditions } = body;
|
||||
|
||||
console.log('Updating patient with email:', email);
|
||||
console.log('Medications:', medications);
|
||||
console.log('Medical Conditions:', medicalConditions);
|
||||
|
||||
const patient = await User.findOne({ email });
|
||||
|
||||
if (!patient) {
|
||||
console.log('Patient not found for email:', email);
|
||||
return NextResponse.json(
|
||||
{ message: 'Patient not found' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
patient.medications = medications;
|
||||
patient.medicalConditions = medicalConditions;
|
||||
await patient.save();
|
||||
|
||||
console.log('Patient data updated successfully:', patient);
|
||||
return NextResponse.json(patient, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error('Error updating patient data:', error);
|
||||
return NextResponse.json(
|
||||
{ message: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -19,3 +19,51 @@ export async function GET() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(req, { params }) {
|
||||
console.log('Processing patient update request...');
|
||||
|
||||
await connectDB();
|
||||
|
||||
try {
|
||||
const { email } = params;
|
||||
|
||||
if (!email) {
|
||||
console.log('No email provided');
|
||||
return NextResponse.json(
|
||||
{ message: 'Email is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const body = await req.json();
|
||||
const { medications, medicalConditions } = body;
|
||||
|
||||
console.log('Updating patient with email:', email);
|
||||
console.log('Medications:', medications);
|
||||
console.log('Medical Conditions:', medicalConditions);
|
||||
|
||||
const patient = await User.findOne({ email });
|
||||
|
||||
if (!patient) {
|
||||
console.log('Patient not found for email:', email);
|
||||
return NextResponse.json(
|
||||
{ message: 'Patient not found' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
patient.medications = medications;
|
||||
patient.medicalConditions = medicalConditions;
|
||||
await patient.save();
|
||||
|
||||
console.log('Patient data updated successfully:', patient);
|
||||
return NextResponse.json(patient, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error('Error updating patient data:', error);
|
||||
return NextResponse.json(
|
||||
{ message: 'Internal server error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user