// @flow
import mongoose from 'mongoose';
const { ObjectId } = mongoose.Schema.Types;
const Filter = new mongoose.Schema(
{
key: {
type: String,
trim: true,
description: 'Filter key',
},
value: {
type: String,
trim: true,
description: 'Filter value',
},
},
{
_id: false, // do not generated _id for Filter
},
);
const Schema = new mongoose.Schema(
{
name: {
type: String,
description: 'Name of this segmentation',
required: true,
},
description: {
type: String,
description: 'Description of this segmentation',
},
// list of users of this segmentation
users: [
{
type: ObjectId,
ref: 'User',
},
],
company: {
type: ObjectId,
ref: 'Company',
description: 'Company owner of this segmentation',
required: true,
index: true,
},
createdBy: {
type: ObjectId,
ref: 'User',
description: 'User that created this segmentation',
required: true,
},
fields: {
type: [Filter],
description: 'filter that was used to generate this segmentation',
},
removedAt: {
type: Date, // when this model was soft deleted
},
},
{
timestamps: {
createdAt: 'createdAt',
updatedAt: 'updatedAt',
},
collection: 'UserSegmentation',
},
);
export default mongoose.model('UserSegmentation', Schema);
failing test