(validation) add a validation file

This commit is contained in:
Julien Calixte
2020-02-29 19:46:06 +01:00
parent 5db9dd2d16
commit 03408d1b7b
6 changed files with 25 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
import IAccount from '@/models/IAccount'
import ITransaction from '@/models/ITransaction'
import IExchange from '@/models/IExchange'
type Doc = IAccount | ITransaction | IExchange
interface IUserContext {
db: string
name: string | null
roles: string[]
}
export default {
validate_doc_update(newDoc: Doc, oldDoc: Doc, userCtx: IUserContext) {
if (newDoc.doctype === 'account' && oldDoc.doctype === 'account') {
if (newDoc.userIds.indexOf(userCtx.name || '') < 0) {
throw { forbidden: 'You do not have rights to update this account' }
}
}
}
}

View File

@@ -3,6 +3,7 @@ import IUser from '@/models/IUser'
import ICurrency from '@/models/ICurrency'
export default interface IAccount extends IModel {
doctype: 'account'
name: string
color: string | null
slug?: string

View File

@@ -1,6 +1,7 @@
import IModel from '@/models/IModel'
export default interface IExchange extends IModel {
doctype: 'exchange'
base: string
date: string
timestamp?: string

View File

@@ -3,5 +3,4 @@ export default interface IModel {
_rev?: string
_deleted?: boolean
_conflicts?: string[]
doctype?: string
}

View File

@@ -7,6 +7,7 @@ import ISplit from '@/models/ISplit'
import ILocation from './ILocation'
export default interface ITransaction extends IModel {
doctype: 'transaction'
name: string
accountId: string
date: Date

View File

@@ -35,6 +35,7 @@ class ExchangeService {
if (!needFetch) {
exchange = {
base,
doctype: 'exchange',
date: formattedDate,
rates: {
[base]: 1