export async function updateDoorContent(fileData, data, door) {
...
const file = fileData.get("file");
const isFileUpdate = data.isFileUpdate;
const deleteOgFile = data.deleteOgFile;
const ogImageFileKey = door.contentImage.fileKey;
...
if (deleteOgFile) {
await utapi.deleteFiles(ogImageFileKey);
await Door.findByIdAndUpdate(...);
}
if (isFileUpdate) {
const { data } = await utapi.uploadFiles(file);
await Door.findByIdAndUpdate(doorId, {
$set: {
"contentImage.fileUrl": data.url,
...
},
});
}
export async function updateDoorContent(fileData, data, door) {
...
const file = fileData.get("file");
const isFileUpdate = data.isFileUpdate;
const deleteOgFile = data.deleteOgFile;
const ogImageFileKey = door.contentImage.fileKey;
...
if (deleteOgFile) {
await utapi.deleteFiles(ogImageFileKey);
await Door.findByIdAndUpdate(...);
}
if (isFileUpdate) {
const { data } = await utapi.uploadFiles(file);
await Door.findByIdAndUpdate(doorId, {
$set: {
"contentImage.fileUrl": data.url,
...
},
});
}