@feardread/fear 1.0.8 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/controllers/crud/crud.js +10 -17
- package/package.json +1 -1
package/controllers/crud/crud.js
CHANGED
|
@@ -101,32 +101,25 @@ exports.read = tryCatch(async (Model, req, res) => {
|
|
|
101
101
|
*/
|
|
102
102
|
exports.create = tryCatch(async (Model, req, res) => {
|
|
103
103
|
const documentData = { ...req.body };
|
|
104
|
-
|
|
105
104
|
// Handle image uploads if present
|
|
106
105
|
if (documentData.images) {
|
|
107
|
-
// Parse comma-separated string to array if needed
|
|
108
|
-
const imageArray = typeof documentData.images === 'string'
|
|
109
|
-
? documentData.images.split(',').map(item => item.trim())
|
|
110
|
-
: documentData.images;
|
|
111
106
|
|
|
112
|
-
|
|
107
|
+
documentData.images.split(',').map(item => item.trim());
|
|
113
108
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
109
|
+
const imageLinks = await cloud.uploadImages(documentData.images);
|
|
110
|
+
|
|
111
|
+
if ( imageLinks ) documentData.images = imageLinks;
|
|
118
112
|
}
|
|
119
113
|
|
|
120
114
|
console.log('Creating document:', documentData);
|
|
121
115
|
|
|
122
116
|
const document = new Model(documentData);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
});
|
|
117
|
+
await document.save()
|
|
118
|
+
.then((result) => {
|
|
119
|
+
return res.status(201).json({ result, success: true,
|
|
120
|
+
message: `Document created successfully in ${Model.modelName} collection`});
|
|
121
|
+
})
|
|
122
|
+
.catch((error) => {console.log('Error Saving document :: ', error);});
|
|
130
123
|
});
|
|
131
124
|
|
|
132
125
|
/**
|