Skip to content

Commit

Permalink
update to use promises
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Jankovsky committed May 19, 2016
1 parent 471a100 commit 14256f7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 70 deletions.
41 changes: 6 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,15 @@
const tgConfig = require('tg-node-lib/lib/tg-config');

exports.handler = function(event, context, callback) {
var res;
if (typeof event.key === 'undefined') {
// grab the whole table
res = tgConfig.getAllConfig();
callback(res[0], res[1]);
// dynamodb.scan({
// TableName: 'TokenGoodsConfig'
// }, function(err, data){
// if (err)
// callback(err);
// else {
// var config = {};
// for (var i=0; i < data.Items.length; i++) {
// config[data.Items[i].key.S] = data.Items[i].value.S;
// }
// callback(null, config);
// }
// });
tgConfig.getAllConfig()
.then((config) => callback(null, config))
.catch((err) => callback(err, null));
} else {
// grab just a single key
res = tgConfig.getConfig(event.key);
callback(res[0], res[1]);
// dynamodb.getItem({
// Key: {
// key: {
// S: String(event.key)
// }
// },
// TableName: 'TokenGoodsConfig'
// }, function(err, data){
// if (err)
// callback(err);
// else {
// if (typeof data.Item === 'undefined')
// callback('Config value not found');
// else
// callback(null, data.Item.value.S);
// }
// });
tgConfig.getConfig(event.key)
.then((value) => callback(null, value))
.catch((err) => callback(err, null));
}
};
68 changes: 36 additions & 32 deletions node_modules/tg-node-lib/lib/tg-config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions node_modules/tg-node-lib/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 14256f7

Please sign in to comment.