Implemented api for searching lists that have parameter email as a subscriber
This commit is contained in:
parent
eb8a5878dd
commit
c085faa157
2 changed files with 45 additions and 0 deletions
|
@ -4,6 +4,7 @@ let db = require('../db');
|
|||
let tools = require('../tools');
|
||||
let shortid = require('shortid');
|
||||
let segments = require('./segments');
|
||||
let subscriptions = require('./subscriptions');
|
||||
let _ = require('../translate')._;
|
||||
let tableHelpers = require('../table-helpers');
|
||||
|
||||
|
@ -64,6 +65,34 @@ module.exports.quicklist = callback => {
|
|||
});
|
||||
};
|
||||
|
||||
module.exports.getListsWithEmail = (email, callback) => {
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
connection.query('SELECT id, name FROM lists', (err, rows) => {
|
||||
connection.release();
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
let lists = (rows || []).map(tools.convertKeys);
|
||||
const results = [];
|
||||
lists.forEach((list, index, arr) => {
|
||||
subscriptions.getByEmail(list.id, email, (err, sub) => {
|
||||
if (sub) {
|
||||
results.push(list.id);
|
||||
}
|
||||
if (index === arr.length - 1) {
|
||||
callback(null, lists.filter(list => results.includes(list.id)));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.getByCid = (cid, callback) => {
|
||||
resolveCid(cid, (err, id) => {
|
||||
if (err) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue