var debug = require('debug')('ff:tcrud:build:server:api:url'); var configTCrud = require('./tcrud-config'); var mod = (function () { var createSlugApi = function(pluginId,postfix,slugType) { var troot = configTCrud.getRootTEntity(); var pluginSlug = pluginId; if (troot.tmeta.tplugin[pluginId] !== undefined && troot.tmeta.tplugin[pluginId].tslug !== undefined) { pluginSlug = troot.tmeta.tplugin[pluginId].tslug; } var result = troot.tmeta.tserver.tslugs.tbase+ '/'+troot.tmeta.tserver.tslugs[slugType]+ '/'+pluginSlug; if (postfix) { result +='/'+postfix; } debug('createSlugApi plugin: '+pluginId+' result: '+result); return result; }; var createSlugApiTEntityAction = function(pluginId,tview, action) { var uriEntity = tview.tmeta.tserver.tslugs.tentity; var uriView = tview.tslug; var uriTech = tview.tmeta.tplugin[pluginId].tslug; var uriAction = ''; if (action) { uriAction = '/' + tview[action].tplugin[pluginId].tslug; } //debug('createBaseApiUri uriTech: '+uriTech+' uriView: '+uriView+' uriAction: '+uriAction); if (tview.tmeta.tserver.tpopfix) { return uriEntity + '/' + uriTech + '/' + uriView + uriAction; } else { return uriEntity + '/' +uriView + '/' + uriTech + uriAction; } }; return function BuildServerApiUrl() { this.createSlugApiServerBase = function(pluginId,postfix) { return createSlugApi(pluginId,postfix,'tserver'); }; this.createSlugApiPluginBase = function(pluginId,postfix) { return createSlugApi(pluginId,postfix,'tplugin'); }; this.createSlugApiTEntityBase = function(pluginId,tview,action) { var troot = configTCrud.getRootTEntity(); return troot.tmeta.tserver.tslugs.tbase+'/'+createSlugApiTEntityAction(pluginId,tview,action); }; this.createSlugApiTEntity = function(pluginId,tview,action) { return createSlugApiTEntityAction(pluginId,tview,action); }; }; })(); module.exports = new mod();