Skip to content

Commit

Permalink
Adds new inverse rule operators (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
pushchris authored Dec 28, 2024
1 parent 394504a commit 616fcf7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/platform/src/lists/ListService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const getListUsers = async (id: number, params: PageParams, projectId: nu
.where('list_id', id)
.select('users.*', 'user_list.created_at', 'user_list.id', 'user_list.user_id'),
App.main.db,
(item) => ({ ...item, id: item.user_id }) as any,
(item) => User.fromJson({ ...item, id: item.user_id }) as any,
)
}

Expand Down
2 changes: 1 addition & 1 deletion apps/platform/src/rules/Rule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Model, { ModelParams } from '../core/Model'

export type Operator = '=' | '!=' | '<' |'<=' | '>' | '>=' | '=' | 'is set' | 'is not set' | 'or' | 'and' | 'xor' | 'empty' | 'contains' | 'starts with' | 'ends with' | 'any' | 'none'
export type Operator = '=' | '!=' | '<' |'<=' | '>' | '>=' | '=' | 'is set' | 'is not set' | 'or' | 'and' | 'xor' | 'empty' | 'contains' | 'not contain' | 'starts with' | 'not start with' | 'ends with' | 'any' | 'none'
export type RuleType = 'wrapper' | 'string' | 'number' | 'boolean' | 'date' | 'array'
export type RuleGroup = 'user' | 'event' | 'parent'

Expand Down
4 changes: 4 additions & 0 deletions apps/platform/src/rules/StringRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ export default {
return v !== ruleValue
case 'starts with':
return v?.startsWith(ruleValue)
case 'not start with':
return !v?.startsWith(ruleValue)
case 'ends with':
return v?.endsWith(ruleValue)
case 'contains':
return v?.includes(ruleValue)
case 'not contain':
return !v?.includes(ruleValue)
default:
throw new RuleEvalException(rule, 'unknown operator: ' + rule.operator)
}
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface OAuthResponse {
refresh_expires_at: Date
}

export type Operator = '=' | '!=' | '<' | '<=' | '>' | '>=' | '=' | 'is set' | 'is not set' | 'or' | 'and' | 'xor' | 'empty' | 'contains' | 'starts with' | 'any' | 'none'
export type Operator = '=' | '!=' | '<' | '<=' | '>' | '>=' | '=' | 'is set' | 'is not set' | 'or' | 'and' | 'xor' | 'empty' | 'contains' | 'not contain' | 'starts with' | 'not start with' | 'any' | 'none'
export type RuleType = 'wrapper' | 'string' | 'number' | 'boolean' | 'date' | 'array'
export type RuleGroup = 'user' | 'event' | 'parent'

Expand Down
2 changes: 2 additions & 0 deletions apps/ui/src/views/users/RuleBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ const operatorTypes: Record<RuleType, OperatorOption[]> = {
...baseOperators,
{ key: 'empty', label: 'is empty' },
{ key: 'contains', label: 'contains' },
{ key: 'not contain', label: 'does not contain' },
{ key: 'starts with', label: 'starts with' },
{ key: 'not start with', label: 'does not start with' },
],
number: [
...baseOperators,
Expand Down

0 comments on commit 616fcf7

Please sign in to comment.