fix: transaction service, account validation
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user