codehooks-js 1.2.10 → 1.2.12
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/crudlify/index.mjs +18 -5
- package/crudlify/lib/schema/yup/index.mjs +15 -2
- package/package.json +1 -1
- package/webserver.mjs +1 -1
package/crudlify/index.mjs
CHANGED
|
@@ -206,7 +206,7 @@ async function updateFunc(req, res) {
|
|
|
206
206
|
}
|
|
207
207
|
const document = req.body;
|
|
208
208
|
delete document._id; // avoid schema validation error
|
|
209
|
-
console.log(req.headers['x-real-ip'], req.method, req.originalUrl
|
|
209
|
+
console.log(req.headers['x-real-ip'], req.method, req.originalUrl);
|
|
210
210
|
if (_schema[collection] != null) {
|
|
211
211
|
_validate(_schema[collection], document, _opt)
|
|
212
212
|
.then(async function (value) {
|
|
@@ -214,6 +214,7 @@ async function updateFunc(req, res) {
|
|
|
214
214
|
const conn = await Datastore.open();
|
|
215
215
|
await _eventHooks.fireBefore(collection, 'PUT', document);
|
|
216
216
|
const result = await conn.replaceOne(collection, ID, document, {});
|
|
217
|
+
console.debug('replaceOne result 1', result)
|
|
217
218
|
await _eventHooks.fireAfter(collection, 'PUT', result);
|
|
218
219
|
res.json(result);
|
|
219
220
|
})
|
|
@@ -226,6 +227,7 @@ async function updateFunc(req, res) {
|
|
|
226
227
|
const conn = await Datastore.open();
|
|
227
228
|
await _eventHooks.fireBefore(collection, 'PUT', document);
|
|
228
229
|
const result = await conn.replaceOne(collection, ID, document, {});
|
|
230
|
+
console.debug('replaceOne result 2', result)
|
|
229
231
|
await _eventHooks.fireAfter(collection, 'PUT', result);
|
|
230
232
|
res.json(result);
|
|
231
233
|
}
|
|
@@ -251,11 +253,16 @@ async function patchFunc(req, res) {
|
|
|
251
253
|
const result = await conn.updateOne(collection, ID, document, {});
|
|
252
254
|
await _eventHooks.fireAfter(collection, 'PATCH', document);
|
|
253
255
|
res.json(result);
|
|
254
|
-
} catch (e) {
|
|
255
|
-
|
|
256
|
-
|
|
256
|
+
} catch (e) {
|
|
257
|
+
if (e.schemaError) {
|
|
258
|
+
res
|
|
259
|
+
.status(400) // validator
|
|
260
|
+
.end(e);
|
|
261
|
+
} else {
|
|
262
|
+
res
|
|
257
263
|
.status(404) // not found
|
|
258
264
|
.end(e.message);
|
|
265
|
+
}
|
|
259
266
|
}
|
|
260
267
|
}
|
|
261
268
|
|
|
@@ -277,9 +284,15 @@ async function patchManyFunc(req, res) {
|
|
|
277
284
|
await _eventHooks.fireAfter(collection, 'PATCH', result);
|
|
278
285
|
res.json(result);
|
|
279
286
|
} catch (e) {
|
|
280
|
-
|
|
287
|
+
if (e.schemaError) {
|
|
288
|
+
res
|
|
289
|
+
.status(400) // validator
|
|
290
|
+
.end(e);
|
|
291
|
+
} else {
|
|
292
|
+
res
|
|
281
293
|
.status(404) // not found
|
|
282
294
|
.end(e.message);
|
|
295
|
+
}
|
|
283
296
|
}
|
|
284
297
|
}
|
|
285
298
|
|
|
@@ -2,8 +2,21 @@ const debug = console.debug;
|
|
|
2
2
|
|
|
3
3
|
export const validate = (schema, document) => {
|
|
4
4
|
debug('Validate Yup', document, schema)
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
return new Promise(async (resolve, reject) => {
|
|
6
|
+
if (schema == null) {
|
|
7
|
+
debug('Null validator')
|
|
8
|
+
resolve(true)
|
|
9
|
+
}
|
|
10
|
+
const valid = await schema.validate(document);
|
|
11
|
+
|
|
12
|
+
if (valid) {
|
|
13
|
+
debug('Validate ok', valid)
|
|
14
|
+
resolve(valid)
|
|
15
|
+
} else {
|
|
16
|
+
debug('Validate error', valid)
|
|
17
|
+
resolve(valid)
|
|
18
|
+
}
|
|
19
|
+
});
|
|
7
20
|
}
|
|
8
21
|
|
|
9
22
|
export const cast = (schema, document) => {
|
package/package.json
CHANGED
package/webserver.mjs
CHANGED
|
@@ -157,7 +157,7 @@ async function handlebars(viewFile, data, settings, cb) {
|
|
|
157
157
|
if (layout) {
|
|
158
158
|
const layoutPath = `${layout}`;
|
|
159
159
|
//console.log('Layout path', layoutPath)
|
|
160
|
-
const layoutFile = await _coho_fs.readFile(layoutPath);
|
|
160
|
+
const layoutFile = await _coho_fs.readFile(layoutPath, {source: true});
|
|
161
161
|
//console.log('Layout file', layoutFile)
|
|
162
162
|
engine.registerPartial('layout', layoutFile);
|
|
163
163
|
}
|