✨ (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'
|
import ICurrency from '@/models/ICurrency'
|
||||||
|
|
||||||
export default interface IAccount extends IModel {
|
export default interface IAccount extends IModel {
|
||||||
|
doctype: 'account'
|
||||||
name: string
|
name: string
|
||||||
color: string | null
|
color: string | null
|
||||||
slug?: string
|
slug?: string
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import IModel from '@/models/IModel'
|
import IModel from '@/models/IModel'
|
||||||
|
|
||||||
export default interface IExchange extends IModel {
|
export default interface IExchange extends IModel {
|
||||||
|
doctype: 'exchange'
|
||||||
base: string
|
base: string
|
||||||
date: string
|
date: string
|
||||||
timestamp?: string
|
timestamp?: string
|
||||||
|
|||||||
@@ -3,5 +3,4 @@ export default interface IModel {
|
|||||||
_rev?: string
|
_rev?: string
|
||||||
_deleted?: boolean
|
_deleted?: boolean
|
||||||
_conflicts?: string[]
|
_conflicts?: string[]
|
||||||
doctype?: string
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import ISplit from '@/models/ISplit'
|
|||||||
import ILocation from './ILocation'
|
import ILocation from './ILocation'
|
||||||
|
|
||||||
export default interface ITransaction extends IModel {
|
export default interface ITransaction extends IModel {
|
||||||
|
doctype: 'transaction'
|
||||||
name: string
|
name: string
|
||||||
accountId: string
|
accountId: string
|
||||||
date: Date
|
date: Date
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class ExchangeService {
|
|||||||
if (!needFetch) {
|
if (!needFetch) {
|
||||||
exchange = {
|
exchange = {
|
||||||
base,
|
base,
|
||||||
|
doctype: 'exchange',
|
||||||
date: formattedDate,
|
date: formattedDate,
|
||||||
rates: {
|
rates: {
|
||||||
[base]: 1
|
[base]: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user