mongoose#Schema TypeScript Examples

The following examples show how to use mongoose#Schema. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: analytics.ts    From one-platform with MIT License 6 votes vote down vote up
AnalyticsSchema: Schema = new Schema(
  {
    appId: {
      type: String,
      unique: true,
      required: true,
    },
    sentryTeamId: {
      type: String,
      default: process.env.OP_ANALYTICS_SENTRY_TEAM_ID || 'one-platform',
      required: true,
    },
    sentryProjectId: {
      type: String,
      default() {
        return `op-hosted-${(this as any).appId}-spa`;
      },
      unique: true,
      required: true,
    },
    createdBy: { type: String, required: true },
    updatedBy: { type: String, required: true },
  },
  { timestamps: { createdAt: 'createdOn', updatedAt: 'updatedOn' } },
)
Example #2
Source File: ChannelSchema.ts    From vt-api with GNU Affero General Public License v3.0 6 votes vote down vote up
ChannelSchema = new Schema({
  '_id': Number,
  'name': NameSchema,
  'organization': {
    type: String,
    required: true
  },
  'platform_id': {
    type: String,
    enum: ['yt', 'bb', 'tt'],
    required: true
  },
  'channel_name': String,
  'channel_id': {
    type: String,
    required: true,
    unique: true
  },
  'details': Schema.Types.Mixed,
  'channel_stats': new Schema({
    'published_at': Date,
    'views': Number,
    'subscribers': Number,
    'videos': Number
  }, { _id: false }),
  'description': String,
  'thumbnail': String,
  'updated_at': Date
})
Example #3
Source File: article.ts    From denote-md-backend with MIT License 6 votes vote down vote up
SchemaArticle = new Schema({
  uuid: { type: String, default: uuidv4, unique: true, index: true },
  title: String,
  author: { type: Schema.Types.ObjectId, ref: 'User' },
  content: String,
  tags: [String],
  created: { type: Date, default: Date.now },
  updated: { type: Date, default: Date.now },
  hidden: Boolean,
  vote: { type: Number, default: 0 },
  comments: [{ type: Schema.Types.ObjectId, ref: 'Comment' }],
})
Example #4
Source File: FileMongoose.ts    From node-experience with MIT License 6 votes vote down vote up
FileSchema: any = new Schema({
    _id: { type: Schema.Types.String, default: uuidV4 },
    name: { type: Schema.Types.String, required: true },
    originalName: { type: Schema.Types.String, required: true },
    mimeType: { type: Schema.Types.String, required: true },
    path: { type: Schema.Types.String },
    extension: { type: Schema.Types.String },
    size: { type: Schema.Types.Number, required: true },
    version: { type: Schema.Types.Number, required: true },
    isPublic: { type: Schema.Types.Boolean, default: false }
}, { timestamps: true })
Example #5
Source File: User.ts    From dropify with MIT License 6 votes vote down vote up
UserSchema: Schema = new Schema(
  {
    email: { type: String, required: true, min: 4, unique: true },
    firstName: { type: String, required: true, min: 2 },
    lastName: { type: String, required: true, min: 2 },
    userName: { type: String, required: true, min: 2, unique: true },
    password: { type: String, required: true, select: false },
    role: {
      type: String,
      enum: userRoles, // you can add as many as roles you like
      default: userRoles.USER,
    },
    passwordResetToken: String,
    passwordResetExpiry: Date,
    profilePic: { type: String },
    bio: { type: String },
    stripeAccountId: { type: String },
    stripeAccount: { type: Object },
    stripeSession: { type: Object },
  },
  { timestamps: true }
)
Example #6
Source File: album.ts    From your_spotify with GNU General Public License v3.0 6 votes vote down vote up
AlbumSchema = new Schema<Album>(
  {
    album_type: String,
    artists: { type: [String], index: true },
    available_markets: [String],
    copyrights: [Object],
    external_ids: Object,
    external_urls: Object,
    genres: [String],
    href: String,
    id: { type: String, unique: true },
    images: [Object],
    name: String,
    popularity: Number,
    release_date: String,
    release_date_precision: String,
    //  "tracks": ,
    type: String,
    uri: String,
  },
  { toJSON: { virtuals: true }, toObject: { virtuals: true } },
)
Example #7
Source File: DashboardUser.ts    From aero-bot with MIT License 6 votes vote down vote up
dashboardUserSchema = new Schema({
    _id: {
        type: String,
        required: true,
    },
    username: {
        type: String,
        required: true,
    },
    avatar: {
        type: String,
        required: true,
    },
    guilds: {
        type: Array,
        required: true,
    },
    accessToken: {
        type: String,
        required: true,
    },
    refreshToken: {
        type: String,
        required: true,
    },
})
Example #8
Source File: ApiKey.ts    From nodejs-backend-architecture-typescript with Apache License 2.0 6 votes vote down vote up
schema = new Schema(
  {
    key: {
      type: Schema.Types.String,
      required: true,
      unique: true,
      maxlength: 1024,
    },
    version: {
      type: Schema.Types.Number,
      required: true,
      min: 1,
      max: 100,
    },
    metadata: {
      type: Schema.Types.String,
      required: true,
    },
    status: {
      type: Schema.Types.Boolean,
      default: true,
    },
    createdAt: {
      type: Date,
      required: true,
      select: false,
    },
    updatedAt: {
      type: Date,
      required: true,
      select: false,
    },
  },
  {
    versionKey: false,
  },
)
Example #9
Source File: Snip.ts    From snip with MIT License 6 votes vote down vote up
schema(): Schema<unknown> {
    // id, url, expireAt, timestamp data
    const SnipSchema = new mongoose.Schema(
      {
        id: { type: String, required: true },
        url: { type: String, required: true },
        expireAt: {
          type: Date,
          default: this.expire,
        },
      },
      { timestamps: true },
    );

    return SnipSchema;
  }
Example #10
Source File: Premium.ts    From Asena with MIT License 6 votes vote down vote up
PremiumSchema: Schema = new Schema({
    server_id: {
        type: String,
        required: true
    },
    status: {
        type: PremiumStatus,
        required: true
    },
    type: {
        type: PremiumType,
        required: true
    },
    startAt: {
        type: Date,
        required: true
    },
    finishAt: {
        type: Date,
        required: true
    }
})
Example #11
Source File: private.ts    From duckbot with MIT License 6 votes vote down vote up
privateSchema = new Schema({
  chat_id: {
    type: Number,
  },
  value: {
    type: Number,
    default: 0,
  },
  warns: {
    type: Array,
    default: new Array(),
  },
  lang: {
    type: String,
    default: 'en',
  },
  connected: {
    type: Number,
    default: 0,
  },
})
Example #12
Source File: assignment.controller.ts    From edu-server with MIT License 6 votes vote down vote up
@Post('/:courseId')
  @Roles(Role.ADMIN)
  @ApiCreatedResponse(responsedoc.addAssignment)
  @ApiParam(courseId)
  @ApiOperation({ summary: 'add an Assignment' })
  async addAssignment(
    @Param('courseId') courseId: Schema.Types.ObjectId,
    @Body() CreateAssignmentDTO: CreateAssignmentDTO,
  ) {
    return await this.assignmentService.addAssignment(
      courseId,
      CreateAssignmentDTO,
    );
  }