@feardread/fear 1.0.7 → 1.0.9
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 +13 -14
- package/libs/cloud/index.js +1 -1
- package/package.json +1 -1
package/controllers/crud/crud.js
CHANGED
|
@@ -101,7 +101,7 @@ 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
|
-
|
|
104
|
+
console.log('raw document data = ', documentData);
|
|
105
105
|
// Handle image uploads if present
|
|
106
106
|
if (documentData.images) {
|
|
107
107
|
// Parse comma-separated string to array if needed
|
|
@@ -109,24 +109,23 @@ exports.create = tryCatch(async (Model, req, res) => {
|
|
|
109
109
|
? documentData.images.split(',').map(item => item.trim())
|
|
110
110
|
: documentData.images;
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
await cloud.uploadImages(imageArray)
|
|
113
|
+
.then((imageLinks) => {
|
|
114
|
+
if (imageLinks) documentData.images = imageLinks;
|
|
115
|
+
console.log('Uploaded Images:', imageLinks);
|
|
116
|
+
})
|
|
117
|
+
.catch((error) => { console.log('Error Uploading Images:: ', error);});
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
console.log('Creating document:', documentData);
|
|
121
121
|
|
|
122
122
|
const document = new Model(documentData);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
});
|
|
123
|
+
await document.save()
|
|
124
|
+
.then((result) => {
|
|
125
|
+
return res.status(201).json({ result, success: true,
|
|
126
|
+
message: `Document created successfully in ${Model.modelName} collection`});
|
|
127
|
+
})
|
|
128
|
+
.catch((error) => {console.log('Error Saving document :: ', error);});
|
|
130
129
|
});
|
|
131
130
|
|
|
132
131
|
/**
|
package/libs/cloud/index.js
CHANGED