feat: start using verb-specifications (#107)

* feat: start using verb-specifications

* fix: verb specification v2

* fix vulnerabilities

---------

Co-authored-by: Quan HL <quanluuhoang8@gmail.com>
Co-authored-by: Dave Horton <daveh@beachdognet.com>
This commit is contained in:
Hoan Luu Huu
2023-02-14 17:24:19 -05:00
committed by GitHub
co-authored by Quan HL Dave Horton
parent 5b48fc8a07
commit 4d48c6946c
5 changed files with 487 additions and 1150 deletions
+11 -3
View File
@@ -6,7 +6,7 @@ const Webhook = require('../../models/webhook');
const {promisePool} = require('../../db');
const decorate = require('./decorate');
const sysError = require('../error');
const jambonzAppJsonValidator = require('../../utils/jambonz-app-json-validation');
const { validate } = require('verb-specifications/jambonz-app-json-validation');
const preconditions = {
'add': validateAdd,
'update': validateUpdate
@@ -80,7 +80,11 @@ router.post('/', async(req, res) => {
// validate app json if required
if (obj['app_json']) {
const app_json = JSON.parse(obj['app_json']);
jambonzAppJsonValidator(logger, app_json);
try {
validate(logger, app_json);
} catch (err) {
throw new DbErrorBadRequest(err);
}
}
const uuid = await Application.make(obj);
@@ -189,7 +193,11 @@ router.put('/:sid', async(req, res) => {
// validate app json if required
if (obj['app_json']) {
const app_json = JSON.parse(obj['app_json']);
jambonzAppJsonValidator(logger, app_json);
try {
validate(logger, app_json);
} catch (err) {
throw new DbErrorBadRequest(err);
}
}
const rowsAffected = await Application.update(sid, obj);