entria / entria-graphql

GraphQL Generators for Entria Projects
MIT License
19 stars 1 forks source link

cannot handle 2 mongoose.schema #47

Open sibelius opened 6 years ago

sibelius commented 6 years ago

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