RSS campaigns
This commit is contained in:
parent
2486f7b9d8
commit
8bc85a0b63
9 changed files with 92 additions and 30 deletions
|
@ -193,18 +193,23 @@ module.exports.subscribe = (cid, optInIp, callback) => {
|
|||
optInIp,
|
||||
optInCountry,
|
||||
status: 1
|
||||
}, subscription, err => {
|
||||
}, subscription, (err, result) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!result.entryId) {
|
||||
return callback(new Error('Could not save subscription'));
|
||||
}
|
||||
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
connection.query('DELETE FROM confirmations WHERE `cid`=? LIMIT 1', [cid], () => {
|
||||
connection.release();
|
||||
callback(null, subscription);
|
||||
// reload full data from db in case it was an update, not insert
|
||||
return module.exports.getById(listId, result.entryId, callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -371,6 +376,38 @@ module.exports.get = (listId, cid, callback) => {
|
|||
}
|
||||
|
||||
let subscription = tools.convertKeys(rows[0]);
|
||||
// ensure list id in response
|
||||
subscription.list = subscription.list || listId;
|
||||
return callback(null, subscription);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getById = (listId, id, callback) => {
|
||||
id = Number(id) || 0;
|
||||
|
||||
if (!id) {
|
||||
return callback(new Error('Missing Subbscription ID'));
|
||||
}
|
||||
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
connection.query('SELECT * FROM `subscription__' + listId + '` WHERE id=?', [id], (err, rows) => {
|
||||
connection.release();
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!rows || !rows.length) {
|
||||
return callback(null, false);
|
||||
}
|
||||
|
||||
let subscription = tools.convertKeys(rows[0]);
|
||||
// ensure list id in response
|
||||
subscription.list = subscription.list || listId;
|
||||
return callback(null, subscription);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue