From 07e5102ea7b850a8a90c64761e065fd9329cef5d Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sun, 1 Sep 2019 11:33:13 +0200 Subject: [PATCH] fix: transaction service, account validation --- src/services/TransactionService.ts | 2 +- src/views/accounts/AccountNew.vue | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/services/TransactionService.ts b/src/services/TransactionService.ts index 246bc04..3c49a03 100644 --- a/src/services/TransactionService.ts +++ b/src/services/TransactionService.ts @@ -62,7 +62,7 @@ class TransactionService { transaction: ITransaction ): Promise { try { - transaction._id = couchService.newId('tra', accountId) + transaction._id = couchService.newId(`tra-${accountId}`, true) transaction.doctype = 'transaction' transaction = await this.encrypt(transaction) return await couchService.save(transaction) diff --git a/src/views/accounts/AccountNew.vue b/src/views/accounts/AccountNew.vue index 65ede1a..98f344a 100644 --- a/src/views/accounts/AccountNew.vue +++ b/src/views/accounts/AccountNew.vue @@ -130,12 +130,12 @@ export default class AccountNew extends Vue { this.currencyShow = !this.currencyShow } - public validate(): boolean { + public validate(users: IUser[]): boolean { if (!this.name) { notif.error('Le nom doit ĂȘtre rempli.') return false } - const aliases: string[] = this.users.map((user: IUser) => + const aliases: string[] = users.map((user: IUser) => user.alias ? user.alias.toLowerCase() : '' ) if (aliases.length === 0) { @@ -148,7 +148,7 @@ export default class AccountNew extends Vue { } if (this.user) { - const userIds: string[] = this.users.map((user: IUser) => user.userId) + const userIds: string[] = users.map((user: IUser) => user.userId) if (userIds.length !== new Set(userIds).size) { notif.error('Les identifiants doivent ĂȘtre uniques.') return false @@ -159,10 +159,10 @@ export default class AccountNew extends Vue { } public async submitAccount(): Promise { - if (!this.validate()) { + let users: IUser[] = this.user ? [this.user, ...this.users] : this.users + if (!this.validate(users)) { return } - let users: IUser[] = this.user ? [this.user, ...this.users] : this.users users = users.map((u: IUser) => ({ userId: u.userId, email: u.email,