Hello po! im new with mongodb and grabe pati si chatGPT di maka gets lol
anyways, can anyone help pano ma fix to? basically im posting a data in json format using postman pero nagkaka error ako pag i resubmit ko yug same data/json. Nagkaka error ako sa object (Patient).
heres my appointment.model.js:
tapos eto yung backend ko pag gumawa ng appointment (backend/appointment/create)
anyways, can anyone help pano ma fix to? basically im posting a data in json format using postman pero nagkaka error ako pag i resubmit ko yug same data/json. Nagkaka error ako sa object (Patient).
heres my appointment.model.js:
Code:
import mongoose from 'mongoose';
const appointmentSchema = new mongoose.Schema({
schedule: {
type: String,
},
technicianName: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
},
firstName: {
type: String,
required: true,
},
lastName: {
type: String,
required: true,
},
phone: {
type: String,
required: true,
},
patient: {
typeOfAnimal: {
type: String,
required: true,
},
numberOfHeads: {
type: Number,
required: true,
},
age: {
type: Number,
required: true,
},
services: [{
type: String,
}],
address: {
type: String,
required: true,
},
landmark: {
type: String,
required: true,
},
},
});
const Appointment = mongoose.model('Appointment', appointmentSchema);
export default Appointment;
tapos eto yung backend ko pag gumawa ng appointment (backend/appointment/create)
JavaScript:
// Create Appointment
export const createAppointment = async (req, res, next) => {
try {
const { schedule, technicianName, firstName, lastName, phone, patient } = req.body;
// Create a new appointment instance
const newAppointment = new Appointment({
schedule,
technicianName,
firstName,
lastName,
phone,
patient,
});
// Save the appointment to the database
const savedAppointment = await newAppointment.save();
res.status(201).json(savedAppointment);
} catch (error) {
next(error);
}
};