From 742955a671a73527e5481a1df198aad5f9ce4d77 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Thu, 5 Sep 2019 16:44:53 -0400 Subject: [PATCH] TokenDao: Make root field configurable This was previously hard-coded to "exports", which is so named because the system is currently used only to export data to another system. This change retains the previous functionality. * src/server/daemon/controller.js (_initExportService): Pass new TokenDao argument. * src/server/token/TokenDao.ts (TokenDao)[_rootField]: New property. (constructor, getToken, _genRoot): Use it. --- src/server/daemon/controller.js | 2 +- src/server/token/TokenDao.ts | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/server/daemon/controller.js b/src/server/daemon/controller.js index 8092b89..0900b60 100644 --- a/src/server/daemon/controller.js +++ b/src/server/daemon/controller.js @@ -244,7 +244,7 @@ function _initExportService( db, callback ) ExportService .use( TokenedService( 'c1import', - new TokenDao( collection ), + new TokenDao( collection, "exports" ), function tokgen() { var shasum = crypto.createHash( 'sha1' ); diff --git a/src/server/token/TokenDao.ts b/src/server/token/TokenDao.ts index 49ec7cf..0fbe1a0 100644 --- a/src/server/token/TokenDao.ts +++ b/src/server/token/TokenDao.ts @@ -50,15 +50,21 @@ export = class TokenDao */ private readonly _collection: MongoCollection; + /** + * Field storing token data, relative to document root + */ + private readonly _rootField: string; + /** * Initialize connection * * @param collection Mongo collection */ - constructor( collection: MongoCollection ) + constructor( collection: MongoCollection, root_field: string ) { this._collection = collection; + this._rootField = root_field; } @@ -169,7 +175,7 @@ export = class TokenDao return; } - const field = data.exports || {}; + const field = data[ this._rootField ] || {}; if ( !field[ ns ] ) { @@ -252,7 +258,7 @@ export = class TokenDao private _genRoot( ns: string ): string { // XXX: injectable - return 'exports.' + ns; + return this._rootField + '.' + ns; } };