wingbot-mongodb
Advanced tools
Comparing version 2.5.6 to 2.10.0
{ | ||
"name": "wingbot-mongodb", | ||
"version": "2.5.6", | ||
"version": "2.10.0", | ||
"description": "MongoDB storage for wingbot.ai", | ||
@@ -38,21 +38,21 @@ "main": "src/main.js", | ||
"cross-env": "^5.2.0", | ||
"eslint": "^5.12.1", | ||
"eslint": "^5.16.0", | ||
"eslint-config-airbnb": "^17.1.0", | ||
"eslint-mocha": "^0.5.0", | ||
"eslint-plugin-import": "^2.16.0", | ||
"eslint-plugin-jsdoc": "^4.1.0", | ||
"eslint-plugin-jsx-a11y": "^6.2.0", | ||
"eslint-plugin-mocha": "^5.2.1", | ||
"eslint-plugin-react": "^7.12.4", | ||
"jsdoc-to-markdown": "^4.0.1", | ||
"mocha": "^5.2.0", | ||
"mongodb": "^3.1.13", | ||
"nyc": "^13.1.0", | ||
"wingbot": "^2.5.0" | ||
"eslint-plugin-import": "^2.17.2", | ||
"eslint-plugin-jsdoc": "^4.8.4", | ||
"eslint-plugin-jsx-a11y": "^6.2.1", | ||
"eslint-plugin-mocha": "^5.3.0", | ||
"eslint-plugin-react": "^7.13.0", | ||
"jsdoc-to-markdown": "^5.0.0", | ||
"mocha": "^6.1.4", | ||
"mongodb": "^3.2.4", | ||
"nyc": "^14.1.1", | ||
"wingbot": "^2.10.0" | ||
}, | ||
"peerDependencies": { | ||
"mongodb": ">=3.0.0", | ||
"wingbot": "^2.5.0" | ||
"wingbot": "^2.10.0" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -71,2 +71,4 @@ /** | ||
* @prop {number} [insEnqueue] | ||
* @prop {boolean} [reaction] - user reacted | ||
* @prop {number} [leaved] - time the event was not sent because user left | ||
*/ | ||
@@ -137,2 +139,7 @@ | ||
options: { name: 'search_by_delivery' } | ||
}, { | ||
index: { | ||
campaignId: 1, leaved: -1, reaction: -1 | ||
}, | ||
options: { name: 'search_left_or_reacted' } | ||
} | ||
@@ -332,2 +339,30 @@ ]); | ||
* | ||
* @param {string} campaignId | ||
* @param {boolean} [sentWithoutReaction] | ||
* @param {string} [pageId] | ||
*/ | ||
async getUnsuccessfulSubscribersByCampaign ( | ||
campaignId, | ||
sentWithoutReaction = false, | ||
pageId = null | ||
) { | ||
const c = await this._getCollection(this.taksCollection); | ||
const condition = { campaignId, leaved: null }; | ||
if (pageId) Object.assign(condition, { pageId }); | ||
if (sentWithoutReaction) { | ||
Object.assign(condition, { leaved: null, reaction: false }); | ||
} else { | ||
Object.assign(condition, { leaved: { $gt: 0 } }); | ||
} | ||
return c.find(condition) | ||
.project({ _id: 0, senderId: 1, pageId: 1 }) | ||
.toArray(); | ||
} | ||
/** | ||
* | ||
* @param {string} taskId | ||
@@ -448,5 +483,6 @@ * @param {Object} data | ||
* @param {Object} campaign | ||
* @param {Object} [updateCampaign] | ||
* @returns {Promise<Campaign>} | ||
*/ | ||
async upsertCampaign (campaign) { | ||
async upsertCampaign (campaign, updateCampaign = null) { | ||
const c = await this._getCollection(this.campaignsCollection); | ||
@@ -458,7 +494,16 @@ | ||
delete $setOnInsert.id; | ||
const update = {}; | ||
if (Object.keys($setOnInsert).length !== 0) { | ||
Object.assign(update, { | ||
$setOnInsert | ||
}); | ||
} | ||
if (updateCampaign) { | ||
Object.assign(update, { | ||
$set: updateCampaign | ||
}); | ||
} | ||
const res = await c.findOneAndUpdate({ | ||
id: campaign.id | ||
}, { | ||
$setOnInsert | ||
}, { | ||
}, update, { | ||
upsert: true, | ||
@@ -471,2 +516,5 @@ returnOriginal: false | ||
ret = Object.assign({ id: id.toHexString(), _id: id }, campaign); | ||
if (updateCampaign) { | ||
Object.assign(ret, updateCampaign); | ||
} | ||
await c.insertOne(ret); | ||
@@ -473,0 +521,0 @@ delete ret._id; |
152483
19
1320