Last active
October 19, 2017 12:23
-
-
Save wtrocki/a6010d5e52e0bf6dc0191fdb21a88a7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var $fh = require(‘fh-mbaas-api’); | |
| var _ = require(‘underscore’); | |
| var async = require(‘async’); | |
| function noop() {} | |
| // Generic wrapper for all database callbacks | |
| // Ensures logging occurs and a client friendly error is propogated up | |
| function dbCb(cb) { | |
| return function (err, res) { | |
| if (err) { | |
| return cb(‘Error in dal!!!!!!’); | |
| } | |
| return cb(null, res); | |
| }; | |
| } | |
| exports.create = function (col, fields, cb) { | |
| fields._createDateTime = Date.now(); | |
| $fh.db({ | |
| ‘act’: ‘create’, | |
| ‘type’: col, | |
| ‘fields’: fields | |
| }, dbCb(cb)); | |
| }; | |
| exports.list = function (col, restrictions, cb) { | |
| var params = { | |
| ‘act’: ‘list’, | |
| ‘type’: col | |
| }; | |
| if (restrictions && typeof restrictions === ‘function’) { | |
| cb = restrictions; | |
| restrictions = null; | |
| } else if (restrictions) { | |
| params = _.extend(params, restrictions); | |
| } | |
| console.log(‘params::: ’); | |
| console.log(JSON.stringify(params)); | |
| $fh.db(params, dbCb(cb)); | |
| }; | |
| exports.create(‘Test’, {‘a’:‘1’}, noop); | |
| exports.create(‘Test’, {‘a’:‘1’}, noop); | |
| exports.create(‘Test’, {‘a’:‘2’}, noop); | |
| exports.create(‘Test’, {‘a’:‘3’}, noop); | |
| exports.create(‘Test’, {‘a’:‘4’}, noop); | |
| exports.list(‘Test’, {}, function (err,data) { | |
| console.log(‘err1:::’ + err); | |
| console.log(‘data1:::’ + JSON.stringify(data)); | |
| }); | |
| exports.list(‘Test’, | |
| { | |
| ‘eq’: { | |
| ‘a’: ‘1’ | |
| } | |
| }, function (err,data) { | |
| console.log(‘err2:::’ + err); | |
| console.log(‘data2:::’ + JSON.stringify(data)); | |
| }); | |
| // FIXES ISSUE | |
| // exports.list(‘Test’, | |
| // { | |
| // ‘eq’: { | |
| // ‘fields.a’: ‘1’ | |
| // } | |
| // }, function (err,data) { | |
| // console.log(‘err2:::’ + err); | |
| // console.log(‘data2:::’ + JSON.stringify(data)); | |
| // }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment