Skip to content

cannot handle 2 mongoose.schema #47

Description

@sibelius

failing test

// @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);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions