Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | 1x 1x 1x 1x 1x 1x 1x 1x 1x | var AWS = require('aws-sdk');
var https = require('https');
/**
* initializes DynomaDB Doc class
* conf may not be necessary if AWS_PROFILE is initialised in the caller app/module
* @param {*} conf
*/
function CrudService(conf) {
this.dynamo = new AWS.DynamoDB.DocumentClient({
httpOptions: {
agent: new https.Agent({
rejectUnauthorized: true
})
}
});
}
/**
*
* @param {*} putStuff
* @param {*} callback
*/
CrudService.prototype.putItem = function (putStuff, callback) {
var _putStuff = putStuff;
this.dynamo.put(_putStuff, (err, data) => {
if (err) {
if (err.code == "ConditionalCheckFailedException") {
return callback({message: "recordexists", stackTrace: err}, null);
}
else {
return callback(err, null);
}
}
else {
return callback(null, data);
}
});
};
/**
*
* @param {*} putStuff
* @param {*} callback
*/
CrudService.prototype.updateItemInPlace = function (putStuff, callback) {
var _putStuff = putStuff;
this.dynamo.put(_putStuff, (err, data) => {
if (err) {
if (err.code == "ConditionalCheckFailedException") {
return callback({message: "recordDoesNotExist", stackTrace: err}, null);
}
else {
return callback(err, null);
}
}
else {
return callback(null, data);
}
});
};
/**
*
* @param {*} updatedStuff
* @param {*} callback
*/
CrudService.prototype.updateItem = function (updatedStuff, callback) {
var _updatedStuff = updatedStuff;
this.dynamo.update(_updatedStuff, (err, data) => {
if (err) {
if (err.code == "ConditionalCheckFailedException") {
return callback("update", null);
}
else {
return callback(err, null);
}
}
else {
return callback(null, data);
}
});
};
/**
*
* @param {*} getStuff
* @param {*} callback
*/
CrudService.prototype.getItem = function (getStuff, callback) {
var _getStuff = getStuff;
this.dynamo.get(_getStuff, (err, data) => {
return callback(err, data);
});
};
/**
*
* @param {*} deleteStuff
* @param {*} callback
*/
CrudService.prototype.deleteItem = function (deleteStuff, callback) {
var _deleteStuff = deleteStuff;
this.dynamo.delete(_deleteStuff, (err, data) => {
return callback(err, data);
});
};
/**
*
* @param {*} queryStuff
* @param {*} callback
*/
CrudService.prototype.queryItem = function (queryStuff, callback) {
var _queryStuff = queryStuff;
this.dynamo.query(_queryStuff, (err, data) => {
return callback(err, data);
});
};
module.exports = exports = CrudService;
|