summaryrefslogtreecommitdiffstats
path: root/src/services
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-04-06 13:49:34 +0200
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2019-04-06 13:49:34 +0200
commitc37000eb7a1067ee5c6dfd0cb0f734d3b12780da (patch)
tree841ba36ede66516c536a48ab5f690977ddfeaad3 /src/services
parentb4ecd33d10cc5ecc2ca85e21b2b24067c6343ade (diff)
Automatic repair of duplicate types
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src/services')
-rw-r--r--src/services/checks/duplicateTypes.js62
-rw-r--r--src/services/checks/index.js2
2 files changed, 64 insertions, 0 deletions
diff --git a/src/services/checks/duplicateTypes.js b/src/services/checks/duplicateTypes.js
new file mode 100644
index 00000000..2642aa82
--- /dev/null
+++ b/src/services/checks/duplicateTypes.js
@@ -0,0 +1,62 @@
+/**
+ * @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @author John Molakvoæ <skjnldsv@protonmail.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+export default {
+ name: 'duplicate types',
+ run: contact => {
+ try {
+ const props = contact.vCard.getAllProperties()
+ .map(prop => prop.getParameter('type'))
+ .filter(prop => prop)
+ const fixed = props.map(prop => [...new Set(prop)])
+ if (props
+ && Array.isArray(props)
+ && props.length > 0
+ && props.join('') !== fixed.join('')) {
+ return true
+ }
+ } catch (error) {
+ return false
+ }
+ return false
+ },
+ fix: contact => {
+ let results = false
+ try {
+ const props = contact.vCard.getAllProperties()
+ props.forEach(prop => {
+ // ['WORK', 'pref', 'pref'] => ['WORK', 'pref']
+ const param = prop.getParameter('type')
+ const fixed = [...new Set(param)]
+ if (param
+ && Array.isArray(param)
+ && param.join('') !== fixed.join('')) {
+ prop.setParameter('type', fixed)
+ results = true
+ }
+ })
+ } catch (error) {
+ console.error(error)
+ }
+ return results
+ }
+}
diff --git a/src/services/checks/index.js b/src/services/checks/index.js
index 2ac0871d..170bd846 100644
--- a/src/services/checks/index.js
+++ b/src/services/checks/index.js
@@ -21,11 +21,13 @@
*/
import badGenderType from './badGenderType'
+import duplicateTypes from './duplicateTypes'
import invalidREV from './invalidREV'
import missingFN from './missingFN'
export default [
badGenderType,
+ duplicateTypes,
invalidREV,
missingFN
]