Proposed segment model design
Proposed mongoose Schema and associated interfaces.
interface Segment {
userId: number;
name: string;
groupId: string;
contactSize: number;
deleted: boolean;
filters: {
field: string;
operator: string;
value: string;
}[]
}
const schema = mongoose.Schema<Segment>({
userId: {
type: Number,
index: true,
},
name: {
type: String,
},
groupId: {
type: mongoose.Schema.Types.ObjectId,
ref: "groups",
},
contactSize: Number,
deleted: {
type: Boolean,
default: false,
select: false,
},
// Group segment filter
filters: [
{
field: {
type: String,
enum: Object.values(CONTACT_FIELDS),
},
operator: {
type: String,
enum: Object.values(GROUP_SEGMENT_OPERATORS),
},
value: String,
},
],
// Prebuilt segment filter
filters: [
{
condition: {
type: String,
enum: Object.values(SEGMENT_PROPERTIES),
},
range: Array,
},
],
});