Display failed imported addresses
This commit is contained in:
parent
873d88658c
commit
172c8ce56f
12 changed files with 201 additions and 25 deletions
|
@ -317,7 +317,10 @@ module.exports.insert = (listId, meta, subscription, callback) => {
|
|||
});
|
||||
}
|
||||
connection.release();
|
||||
return callback(null, entryId);
|
||||
return callback(null, {
|
||||
entryId,
|
||||
inserted: !existing
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
|
@ -329,7 +332,10 @@ module.exports.insert = (listId, meta, subscription, callback) => {
|
|||
});
|
||||
}
|
||||
connection.release();
|
||||
return callback(null, entryId);
|
||||
return callback(null, {
|
||||
entryId,
|
||||
inserted: !existing
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -692,7 +698,7 @@ module.exports.updateImport = (listId, importId, data, callback) => {
|
|||
let keys = [];
|
||||
let values = [];
|
||||
|
||||
let allowedKeys = ['type', 'path', 'size', 'delimiter', 'status', 'error', 'processed', 'mapping', 'finished'];
|
||||
let allowedKeys = ['type', 'path', 'size', 'delimiter', 'status', 'error', 'processed', 'new', 'failed', 'mapping', 'finished'];
|
||||
Object.keys(data).forEach(key => {
|
||||
let value = data[key];
|
||||
key = tools.toDbKey(key);
|
||||
|
@ -708,11 +714,25 @@ module.exports.updateImport = (listId, importId, data, callback) => {
|
|||
}
|
||||
let query = 'UPDATE importer SET ' + keys.map(key => '`' + key + '`=?') + ' WHERE id=? AND list=? LIMIT 1';
|
||||
connection.query(query, values.concat([importId, listId]), (err, result) => {
|
||||
connection.release();
|
||||
if (err) {
|
||||
connection.release();
|
||||
return callback(err);
|
||||
}
|
||||
return callback(null, result && result.affectedRows || false);
|
||||
|
||||
let affected = result && result.affectedRows || false;
|
||||
|
||||
if (data.failed === 0) {
|
||||
// remove entries from import_failed table
|
||||
let query = 'DELETE FROM `import_failed` WHERE `import`=?';
|
||||
connection.query(query, [importId], () => {
|
||||
connection.release();
|
||||
return callback(null, affected);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
connection.release();
|
||||
return callback(null, affected);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -758,6 +778,29 @@ module.exports.getImport = (listId, importId, callback) => {
|
|||
});
|
||||
};
|
||||
|
||||
module.exports.getFailedImports = (importId, callback) => {
|
||||
importId = Number(importId) || 0;
|
||||
|
||||
if (importId < 1) {
|
||||
return callback(new Error('Missing Import ID'));
|
||||
}
|
||||
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
let query = 'SELECT * FROM import_failed WHERE import=? LIMIT 1000';
|
||||
connection.query(query, [importId], (err, rows) => {
|
||||
connection.release();
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
return callback(null, (rows || []).map(tools.convertKeys));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.listImports = (listId, callback) => {
|
||||
listId = Number(listId) || 0;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue