Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions server-plugins/process-resources/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import core, {
Relation,
splitMixinUpdate,
Tx,
TxProcessor
TxProcessor,
Type,
TypeNumber
} from '@hcengineering/core'
import process, {
Execution,
Expand Down Expand Up @@ -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 (
params: MethodParams<Card>,
execution: Execution,
Expand All @@ -180,7 +200,12 @@ export async function UpdateCard (
for (const key in params) {
const prevKey = checkMixinKey(key, _process.masterTag, hierarchy)
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[] = []
Expand Down
Loading