summaryrefslogtreecommitdiff
path: root/app/index.js
diff options
context:
space:
mode:
authorSean Fridman <fridman@mail.sfsu.edu>2015-04-03 12:39:01 -0400
committerSean Fridman <fridman@mail.sfsu.edu>2015-04-03 12:39:20 -0400
commit7d15bc8a49121dd85171d7837c4f6a97a7e096dc (patch)
tree88f06e2957cd4f1d0b91dd3cd2ebe0b41ac7401e /app/index.js
parent0c4f6ad96c2ee1b1c948dd227e291ff73023b95b (diff)
Beef up resource abstraction
Diffstat (limited to 'app/index.js')
-rw-r--r--app/index.js15
1 files changed, 9 insertions, 6 deletions
diff --git a/app/index.js b/app/index.js
index 29dcfd0..6d057d3 100644
--- a/app/index.js
+++ b/app/index.js
@@ -56,19 +56,22 @@ OKCMS.prototype._createSchemas = function(schemaConfig) {
OKCMS.prototype._createResources = function(resourceConfig, db, schemaCache) {
resourceConfig = resourceConfig || {};
- return resourceConfig.map(function(config) {
+ var typeCache = {};
+ return resourceConfig.reduce(function(cache, config) {
var type = config.type;
var schema = schemaCache[type];
if (!schema)
throw new Error('Resource config references nonexistent schema');
- // If no id is provided, default to "select all"
- var id = config.id || '*';
- return OKResource({
+ // If we already created resource class, just skip
+ if (cache[type])
+ return cache;
+ cache[type] = OKResource({
type: type,
- id: id,
+ db: db,
schema: schema
})
- });
+ return cache;
+ }, {});
};
OKCMS.prototype._createViews = function(viewConfig, db,