From 7a3f16821820e34bddb94b821127ee310215de58 Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Tue, 27 Aug 2019 00:28:05 +0200 Subject: [PATCH] feat: add uuid to account ids --- package-lock.json | 15 ++++++++++++--- package.json | 2 ++ src/services/AccountService.ts | 2 +- src/services/CouchService.ts | 5 +++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9b670fd..de9b336 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1346,6 +1346,15 @@ "integrity": "sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==", "dev": true }, + "@types/uuid": { + "version": "3.4.5", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-3.4.5.tgz", + "integrity": "sha512-MNL15wC3EKyw1VLF+RoVO4hJJdk9t/Hlv3rt1OL65Qvuadm4BYo6g9ZJQqoq7X8NBFSsQXgAujWciovh2lpVjA==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/webpack-env": { "version": "1.14.0", "resolved": "https://registry.npmjs.org/@types/webpack-env/-/webpack-env-1.14.0.tgz", @@ -15175,9 +15184,9 @@ "dev": true }, "uuid": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", - "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==" + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz", + "integrity": "sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ==" }, "validate-npm-package-license": { "version": "3.0.4", diff --git a/package.json b/package.json index b0e0a62..0bac07f 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "pouchdb-authentication": "^1.1.3", "pouchdb-browser": "^7.1.1", "register-service-worker": "^1.6.2", + "uuid": "^3.3.3", "vue": "^2.6.10", "vue-class-component": "^7.1.0", "vue-click-outside": "^1.0.7", @@ -43,6 +44,7 @@ "@types/md5": "^2.1.33", "@types/notyf": "^2.0.0", "@types/pouchdb": "^6.4.0", + "@types/uuid": "^3.4.5", "@vue/cli-plugin-babel": "^3.10.0", "@vue/cli-plugin-pwa": "^3.10.0", "@vue/cli-plugin-typescript": "^3.10.0", diff --git a/src/services/AccountService.ts b/src/services/AccountService.ts index 40db63f..2bea357 100644 --- a/src/services/AccountService.ts +++ b/src/services/AccountService.ts @@ -26,7 +26,7 @@ class AccountService { public async add(account: IAccount): Promise { try { account.slug = slug(account.name) - const id = couchService.newId('acc') + const id = couchService.newId('acc', true) account._id = id account.doctype = 'account' const response = await couchService.save(account) diff --git a/src/services/CouchService.ts b/src/services/CouchService.ts index 128b3b2..0ea76a4 100644 --- a/src/services/CouchService.ts +++ b/src/services/CouchService.ts @@ -1,4 +1,5 @@ import axios from 'axios' +import uuid from 'uuid/v4' import PouchDb from 'pouchdb-browser' import PouchDbAuthentication from 'pouchdb-authentication' import bus, { SYNC } from '@/utils/bus-event' @@ -340,8 +341,8 @@ class CouchService { return false } - public newId(...prefixes: string[]): string { - return `${prefixes.join('-')}${Date.now().toString()}` + public newId(prefix: string, withUuid: boolean = false): string { + return `${prefix}${Date.now().toString()}${withUuid ? uuid() : ''}` } public async purgeDb(): Promise {