UNPKG

dbl-coins-invest

Version:

Sharade DBL package over other coins invest services

88 lines (78 loc) 2.16 kB
const dynamoose = require('dynamoose'); if (!!process.env.LOCAL) { dynamoose.local(); } else { dynamoose.AWS.config.credentials = new dynamoose.AWS.SharedIniFileCredentials({profile: 'coinsProfile'}); } dynamoose.AWS.config.update({ region: 'us-east-1' }); const Schema = dynamoose.Schema; const configSchema = new Schema({ id: { type: String, rangeKey: true }, userSub: { type: String, validate: function (v) { return v.length > 0; }, required: true, hashKey: true }, userData: { firstName: String, lastName: String, email: String }, type: { // absPrice / pctPrice / absMCup / pctMCup type: String, index: { global: true, rangeKey: 'userSub', name: 'TypeIndex', project: true, // ProjectionType: ALL throughput: 5 // read and write are both 5 }, }, isActive: { type: Boolean, }, config: { type: Object, get: (val) => { try { return JSON.parse(val); } catch (err) { return val; } } }, idleInterval: { type: Number // interval in mlseconds between lastNotified }, lastNotified: { type: Number }, notificationStatus: { type: String // status of notification failed.... error... success... } }, { throughput: {read: 5, write: 5} }); let schemaOptions = { update: true, waitForActive: true, waitForActiveTimeout: 180000 }; let tableName; if (!!process.env.DYNAMO_ALERT_TABLE) tableName = process.env.DYNAMO_ALERT_TABLE; else throw new Error('No table name provided (DYNAMO_ALERT_TABLE)'); const NotificationModel = dynamoose.model(tableName, configSchema, schemaOptions); module.exports = { NotificationModel: NotificationModel };