@grouparoo/core
Version:
The Grouparoo Core
95 lines (79 loc) • 2.06 kB
text/typescript
import {
Table,
Column,
AllowNull,
ForeignKey,
BelongsTo,
BeforeSave,
DataType,
} from "sequelize-typescript";
import { Group } from "./Group";
import { Property } from "./Property";
import { APIData } from "../modules/apiData";
import { CommonModel } from "../classes/commonModel";
import {
GroupRuleOpType,
RelativeMatchDirectionType,
RelativeMatchUnitType,
} from "../modules/ruleOpsDictionary";
export class GroupRule extends CommonModel<GroupRule> {
idPrefix() {
return "grr";
}
groupId: string;
propertyId: string;
recordColumn: string;
position: number;
match: string;
op: GroupRuleOpType;
relativeMatchNumber: number;
relativeMatchUnit: RelativeMatchUnitType;
relativeMatchDirection: RelativeMatchDirectionType;
schedule: Group;
property: Property;
async apiData() {
return {
id: this.id,
groupId: this.groupId,
propertyId: this.propertyId,
recordColumn: this.recordColumn,
position: this.position,
match: this.match,
op: this.op,
relativeMatchNumber: this.relativeMatchNumber,
relativeMatchUnit: this.relativeMatchUnit,
relativeMatchDirection: this.relativeMatchDirection,
createdAt: APIData.formatDate(this.createdAt),
updatedAt: APIData.formatDate(this.updatedAt),
};
}
// --- Class Methods --- //
static async ensureEitherPropertyOrRecordColumn(instance: GroupRule) {
if (
(!instance.propertyId && !instance.recordColumn) ||
(instance.propertyId && instance.recordColumn)
) {
throw new Error(
"either propertyId or recordColumn is required for a GroupRule"
);
}
}
}