mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-30 05:25:00 +02:00
Add min and max transformation functions (#10782)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -105,6 +105,8 @@ import {
|
||||
Insert,
|
||||
LastValue,
|
||||
LowerCase,
|
||||
Max,
|
||||
Min,
|
||||
Modulo,
|
||||
MonthFromDate,
|
||||
Multiply,
|
||||
@@ -696,7 +698,9 @@ export default async () => ({
|
||||
YearFromDate,
|
||||
MonthFromDate,
|
||||
DayFromDate,
|
||||
DateDifference
|
||||
DateDifference,
|
||||
Min,
|
||||
Max
|
||||
},
|
||||
rollbacks: {
|
||||
ToDoCloseRollback,
|
||||
|
||||
@@ -425,6 +425,40 @@ export function Floor (value: number): number {
|
||||
return value
|
||||
}
|
||||
|
||||
export async function Min (
|
||||
value: number,
|
||||
props: Record<string, any>,
|
||||
control: ProcessControl,
|
||||
execution: Execution
|
||||
): Promise<number> {
|
||||
const context = parseContext(props.value)
|
||||
if (context !== undefined) {
|
||||
const val = await getContextValue(props.value, control, execution)
|
||||
if (typeof val !== 'number') return value
|
||||
return Math.min(value, val)
|
||||
} else if (typeof value === 'number' && typeof props.value === 'number') {
|
||||
return Math.min(value, props.value)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
export async function Max (
|
||||
value: number,
|
||||
props: Record<string, any>,
|
||||
control: ProcessControl,
|
||||
execution: Execution
|
||||
): Promise<number> {
|
||||
const context = parseContext(props.value)
|
||||
if (context !== undefined) {
|
||||
const val = await getContextValue(props.value, control, execution)
|
||||
if (typeof val !== 'number') return value
|
||||
return Math.max(value, val)
|
||||
} else if (typeof value === 'number' && typeof props.value === 'number') {
|
||||
return Math.max(value, props.value)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region Func
|
||||
|
||||
Reference in New Issue
Block a user