✨ (validation) add a validation file
This commit is contained in:
21
src/couch-design/validate-doc-update.ts
Normal file
21
src/couch-design/validate-doc-update.ts
Normal 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' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import IModel from '@/models/IModel'
|
||||
|
||||
export default interface IExchange extends IModel {
|
||||
doctype: 'exchange'
|
||||
base: string
|
||||
date: string
|
||||
timestamp?: string
|
||||
|
||||
@@ -3,5 +3,4 @@ export default interface IModel {
|
||||
_rev?: string
|
||||
_deleted?: boolean
|
||||
_conflicts?: string[]
|
||||
doctype?: string
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -35,6 +35,7 @@ class ExchangeService {
|
||||
if (!needFetch) {
|
||||
exchange = {
|
||||
base,
|
||||
doctype: 'exchange',
|
||||
date: formattedDate,
|
||||
rates: {
|
||||
[base]: 1
|
||||
|
||||
Reference in New Issue
Block a user