mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-27 03:54:57 +02:00
Process should respect property type (#10050)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -26,7 +26,9 @@ import core, {
|
|||||||
Relation,
|
Relation,
|
||||||
splitMixinUpdate,
|
splitMixinUpdate,
|
||||||
Tx,
|
Tx,
|
||||||
TxProcessor
|
TxProcessor,
|
||||||
|
Type,
|
||||||
|
TypeNumber
|
||||||
} from '@hcengineering/core'
|
} from '@hcengineering/core'
|
||||||
import process, {
|
import process, {
|
||||||
Execution,
|
Execution,
|
||||||
@@ -164,6 +166,24 @@ export async function AddRelation (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function respectAttributeType (attrType: Type<any>, value: any): any {
|
||||||
|
switch (attrType._class) {
|
||||||
|
case core.class.TypeNumber: {
|
||||||
|
const type = attrType as TypeNumber
|
||||||
|
const { min, max, digits } = type
|
||||||
|
let res = value
|
||||||
|
if (min !== undefined && res < min) res = min
|
||||||
|
if (max !== undefined && res > max) res = max
|
||||||
|
if (digits !== undefined) {
|
||||||
|
return Number(Number(res).toFixed(digits))
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function UpdateCard (
|
export async function UpdateCard (
|
||||||
params: MethodParams<Card>,
|
params: MethodParams<Card>,
|
||||||
execution: Execution,
|
execution: Execution,
|
||||||
@@ -180,7 +200,12 @@ export async function UpdateCard (
|
|||||||
for (const key in params) {
|
for (const key in params) {
|
||||||
const prevKey = checkMixinKey(key, _process.masterTag, hierarchy)
|
const prevKey = checkMixinKey(key, _process.masterTag, hierarchy)
|
||||||
prevValue[key] = getObjectValue(prevKey, target)
|
prevValue[key] = getObjectValue(prevKey, target)
|
||||||
update[key] = (params as any)[key]
|
const attr = hierarchy.findAttribute(_process.masterTag, key)
|
||||||
|
if (attr === undefined) {
|
||||||
|
update[key] = (params as any)[key]
|
||||||
|
} else {
|
||||||
|
update[key] = respectAttributeType(attr.type, (params as any)[key])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const res: Tx[] = []
|
const res: Tx[] = []
|
||||||
|
|||||||
Reference in New Issue
Block a user