const updateSession = async (req, res) => {
const { id } = req.params;
const newData = req.body ;
// Si `newData.date` existe y está en formato "YYYY-MM-DD", ajusta la hora a medianoche UTC.
if (newData.date) {
const date = new Date(newData.date);
newData.date = new Date(Date.UTC(
date.getUTCFullYear(),
date.getUTCMonth(),
date.getUTCDate(),
date.getUTCHours(),
date.getUTCMinutes(),
date.getUTCSeconds()
));
}
console.log(newData)
try {
const data = await sessionsModel.findByIdAndUpdate(id, newData, {
new: true,
});
res.json({ data });
} catch (error) {
handleHttpError(res, "ERROR_UPDATE_SESSION");
}
};
const mongoose = require("mongoose");
const SessionSchema = new mongoose.Schema(
{
name: {
type: String,
required: true,
},
description: {
type: String,
},
isFree: {
type: Boolean,
default: false,
},
position: {
type: Number,
},
specialization: {
type: mongoose.Schema.Types.ObjectId,
ref: "Specialization",
required: true,
},
date: {
type: Date,
default: Date.now,
},
meetLink: {
type: String,
},
videoUrl: {
type: String,
},
videoDuration: {
type: String,
},
isPublished: {
type: Boolean,
default: false,
},
},
{
timestamps: true,
versionKey: false,
}
);
module.exports = mongoose.model("Session", SessionSchema);