Seems that hierarchical error handling works..
TreeTable component seems to work too. Edit is half-way through. Create / delete are TBD.
This commit is contained in:
parent
79ea9e1897
commit
5e4c86f626
24 changed files with 9967 additions and 261 deletions
|
@ -2,20 +2,8 @@
|
|||
|
||||
const knex = require('../knex');
|
||||
const hasher = require('node-object-hash')();
|
||||
const { filterObject } = require('../helpers');
|
||||
const interoperableErrors = require('../interoperable-errors');
|
||||
|
||||
class ChangedError extends interoperableErrors.InteroperableError {
|
||||
constructor(msg, data) {
|
||||
super('namespaces.ChangedError', msg, data);
|
||||
}
|
||||
}
|
||||
|
||||
class NotFoundError extends interoperableErrors.InteroperableError {
|
||||
constructor(msg, data) {
|
||||
super('namespaces.NotFoundError', msg, data);
|
||||
}
|
||||
}
|
||||
const { enforce, filterObject } = require('../helpers');
|
||||
const interoperableErrors = require('../../shared/interoperable-errors');
|
||||
|
||||
const allowedKeys = new Set(['id', 'name', 'description', 'parent']);
|
||||
const allowedUpdateKeys = new Set(['name', 'description', 'parent']);
|
||||
|
@ -31,7 +19,7 @@ function hash(ns) {
|
|||
async function getById(nsId) {
|
||||
const ns = await knex('namespaces').where('id', nsId).first();
|
||||
if (!ns) {
|
||||
throw new NotFoundError();
|
||||
throw new interoperableErrors.NotFoundError();
|
||||
}
|
||||
|
||||
ns.hash = hash(ns);
|
||||
|
@ -45,18 +33,20 @@ async function create(ns) {
|
|||
}
|
||||
|
||||
async function updateWithConsistencyCheck(ns) {
|
||||
enforce(ns.id !== 1 || ns.parent === null, 'Cannot assign a parent to the root namespace.');
|
||||
|
||||
await knex.transaction(async tx => {
|
||||
const existingNs = await tx('namespaces').where('id', ns.id).first();
|
||||
if (!ns) {
|
||||
throw new NotFoundError();
|
||||
throw new interoperableErrors.NotFoundError();
|
||||
}
|
||||
|
||||
const existingNsHash = hash(existingNs);
|
||||
if (existingNsHash != ns.originalHash) {
|
||||
throw new ChangedError();
|
||||
throw new interoperableErrors.ChangedError();
|
||||
}
|
||||
|
||||
tx('namespaces').where('id', ns.id).update(filterObject(ns, allowedUpdateKeys));
|
||||
await tx('namespaces').where('id', ns.id).update(filterObject(ns, allowedUpdateKeys));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -65,8 +55,6 @@ async function remove(nsId) {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
NotFoundError,
|
||||
ChangedError,
|
||||
hash,
|
||||
list,
|
||||
getById,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue