// src/controllers/students.js
import { saveFileToCloudinary } from '../utils/saveFileToCloudinary.js';
import { env } from '../utils/env.js';
/* Інший код файлу */
export const patchStudentController = async (req, res, next) => {
const { studentId } = req.params;
const photo = req.file;
let photoUrl;
if (photo) {
if (env('ENABLE_CLOUDINARY') === 'true') {
photoUrl = await saveFileToCloudinary(photo);
} else {
photoUrl = await saveFileToUploadDir(photo);
}
}
const result = await updateStudent(studentId, {
...req.body,
photo: photoUrl,
});
if (!result) {
next(createHttpError(404, 'Student not found'));
return;
}
res.json({
status: 200,
message: `Successfully patched a student!`,
data: result.student,
});
};