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.master
parent
b83f13f480
commit
742955a671
|
@ -244,7 +244,7 @@ function _initExportService( db, callback )
|
||||||
ExportService
|
ExportService
|
||||||
.use( TokenedService(
|
.use( TokenedService(
|
||||||
'c1import',
|
'c1import',
|
||||||
new TokenDao( collection ),
|
new TokenDao( collection, "exports" ),
|
||||||
function tokgen()
|
function tokgen()
|
||||||
{
|
{
|
||||||
var shasum = crypto.createHash( 'sha1' );
|
var shasum = crypto.createHash( 'sha1' );
|
||||||
|
|
|
@ -50,15 +50,21 @@ export = class TokenDao
|
||||||
*/
|
*/
|
||||||
private readonly _collection: MongoCollection;
|
private readonly _collection: MongoCollection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Field storing token data, relative to document root
|
||||||
|
*/
|
||||||
|
private readonly _rootField: string;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize connection
|
* Initialize connection
|
||||||
*
|
*
|
||||||
* @param collection Mongo collection
|
* @param collection Mongo collection
|
||||||
*/
|
*/
|
||||||
constructor( collection: MongoCollection )
|
constructor( collection: MongoCollection, root_field: string )
|
||||||
{
|
{
|
||||||
this._collection = collection;
|
this._collection = collection;
|
||||||
|
this._rootField = root_field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -169,7 +175,7 @@ export = class TokenDao
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const field = <TokenNamespaceResults>data.exports || {};
|
const field = <TokenNamespaceResults>data[ this._rootField ] || {};
|
||||||
|
|
||||||
if ( !field[ ns ] )
|
if ( !field[ ns ] )
|
||||||
{
|
{
|
||||||
|
@ -252,7 +258,7 @@ export = class TokenDao
|
||||||
private _genRoot( ns: string ): string
|
private _genRoot( ns: string ): string
|
||||||
{
|
{
|
||||||
// XXX: injectable
|
// XXX: injectable
|
||||||
return 'exports.' + ns;
|
return this._rootField + '.' + ns;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue