fix: transaction service, account validation

This commit is contained in:
Julien Calixte
2019-09-01 11:33:13 +02:00
parent 7a3f168218
commit 07e5102ea7
2 changed files with 6 additions and 6 deletions

View File

@@ -62,7 +62,7 @@ class TransactionService {
transaction: ITransaction transaction: ITransaction
): Promise<PouchDB.Core.Response> { ): Promise<PouchDB.Core.Response> {
try { try {
transaction._id = couchService.newId('tra', accountId) transaction._id = couchService.newId(`tra-${accountId}`, true)
transaction.doctype = 'transaction' transaction.doctype = 'transaction'
transaction = await this.encrypt(transaction) transaction = await this.encrypt(transaction)
return await couchService.save(transaction) return await couchService.save(transaction)

View File

@@ -130,12 +130,12 @@ export default class AccountNew extends Vue {
this.currencyShow = !this.currencyShow this.currencyShow = !this.currencyShow
} }
public validate(): boolean { public validate(users: IUser[]): boolean {
if (!this.name) { if (!this.name) {
notif.error('Le nom doit être rempli.') notif.error('Le nom doit être rempli.')
return false return false
} }
const aliases: string[] = this.users.map((user: IUser) => const aliases: string[] = users.map((user: IUser) =>
user.alias ? user.alias.toLowerCase() : '' user.alias ? user.alias.toLowerCase() : ''
) )
if (aliases.length === 0) { if (aliases.length === 0) {
@@ -148,7 +148,7 @@ export default class AccountNew extends Vue {
} }
if (this.user) { 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) { if (userIds.length !== new Set(userIds).size) {
notif.error('Les identifiants doivent être uniques.') notif.error('Les identifiants doivent être uniques.')
return false return false
@@ -159,10 +159,10 @@ export default class AccountNew extends Vue {
} }
public async submitAccount(): Promise<void> { public async submitAccount(): Promise<void> {
if (!this.validate()) { let users: IUser[] = this.user ? [this.user, ...this.users] : this.users
if (!this.validate(users)) {
return return
} }
let users: IUser[] = this.user ? [this.user, ...this.users] : this.users
users = users.map((u: IUser) => ({ users = users.map((u: IUser) => ({
userId: u.userId, userId: u.userId,
email: u.email, email: u.email,