diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-01-30 12:51:55 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-01-30 12:51:55 +0100 |
commit | 41e8ec164713dc6b51754575e6da92995dd55df9 (patch) | |
tree | 080e849b8870f3bfdc0ef448b0ee25553e654c68 /src/services | |
parent | a1561dfe3a728f3b636852df05d36c1947883dd7 (diff) |
Fix string detection, put delete in last and fix properties scoping
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src/services')
-rw-r--r-- | src/services/checks/missingFN.js | 21 | ||||
-rw-r--r-- | src/services/validate.js | 20 |
2 files changed, 27 insertions, 14 deletions
diff --git a/src/services/checks/missingFN.js b/src/services/checks/missingFN.js index 449f4a43..86a92c7a 100644 --- a/src/services/checks/missingFN.js +++ b/src/services/checks/missingFN.js @@ -30,8 +30,9 @@ export default { return !contact.vCard.hasProperty('fn') // No FN || contact.vCard.getFirstPropertyValue('fn') === '' // Empty FN || ( // we don't want to fix newly created contacts - contact.dav // Existing contact - && contact.vCard.getFirstPropertyValue('fn') === t('contacts', 'New contact') // AND Unchanged FN + contact.dav // Existing contact + && contact.vCard.getFirstPropertyValue('fn') + .toLowerCase() === t('contacts', 'New contact').toLowerCase() // AND Unchanged FN ) }, fix: contact => { @@ -39,14 +40,22 @@ export default { // Stevenson;John;Philip,Paul;Dr.;Jr.,M.D.,A.C.P. // -> John Stevenson const n = contact.vCard.getFirstPropertyValue('n') - contact.fullName = n.slice(0, 2).reverse().join(' ') - return true + const fullName = n.slice(0, 2).reverse().join(' ') + if (fullName.trim() !== '') { + contact.fullName = fullName + return true + } + return false } else if (contact.vCard.hasProperty('org')) { const org = contact.vCard.getFirstPropertyValue('org') // ABC, Inc.;North American Division;Marketing // -> ABC, Inc. - contact.fullName = org[0] - return true + const fullName = org[0] + if (fullName.trim() !== '') { + contact.fullName = fullName + return true + } + return false } return false } diff --git a/src/services/validate.js b/src/services/validate.js index be080988..c80542f9 100644 --- a/src/services/validate.js +++ b/src/services/validate.js @@ -28,16 +28,20 @@ export default function(contact) { // Going through every checks checks.forEach(check => { - if (check.run(contact)) { + try { + if (check.run(contact)) { - // A fix is needed, running ⏳ - if (!check.fix(contact)) { - // FAILURE 🙅 - console.warn('The following contact needed a correction that failed:', check.name, contact) - } else { - // SUCCESS 💪 - console.info('The following contact has been repaired:', check.name, contact) + // A fix is needed, running ⏳ + if (!check.fix(contact)) { + // FAILURE 🙅 + console.warn('The following contact needed a correction that failed:', check.name, contact) + } else { + // SUCCESS 💪 + console.info('The following contact has been repaired:', check.name, contact) + } } + } catch (error) { + console.error('Error during the check:', check.name, contact, error) } }) |