How to use @tsed/mongoose - 6 common examples

To help you get started, we’ve selected a few @tsed/mongoose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TypedProject / ts-express-decorators / test / integration / mongoose / mongoose.spec.ts View on Github external
import {Allow, ConverterService, Property, PropertyType, Required} from "@tsed/common";
import {Model, MongooseModel} from "@tsed/mongoose";
import {inject} from "@tsed/testing";
import {expect} from "chai";

@Model()
export class TestModel {
  @Required()
  @Allow("", null)
  email: string;

  @Property() number: number;
}

export class AdminModel {
  @Property({name: "id"}) // this one looks like _id in response, but it should be just id
  _id: string;

  @Property() role: string;
}

@Model({
github TypedProject / ts-express-decorators / test / integration / mongoose / mongoose.spec.ts View on Github external
export class TestModel {
  @Required()
  @Allow("", null)
  email: string;

  @Property() number: number;
}

export class AdminModel {
  @Property({name: "id"}) // this one looks like _id in response, but it should be just id
  _id: string;

  @Property() role: string;
}

@Model({
  name: "Service"
})
export class ServiceModel {
  @Property({name: "id"}) // this one works as expected and turns into id
  _id: string;

  @PropertyType(AdminModel) admins: AdminModel[];
}

describe("Mongoose", () => {
  describe("TestModel", () => {
    describe("when null is given", () => {
      before(
        inject([TestModel], (testModel: MongooseModel) => {
          this.result = new testModel({email: null, number: 2});
          this.error = this.result.validateSync();
github TypedProject / ts-express-decorators / examples / mongoose / src / models / calendars / Calendar.ts View on Github external
import {Property, Required} from "@tsed/common";
import {Model, ObjectID} from "@tsed/mongoose";

@Model()
export class Calendar {
  @ObjectID("id")
  _id: string;

  @Required()
  name: string;

  @Property()
  owner: string;
}
github TypedProject / ts-express-decorators / examples / mongoose / src / models / events / CalendarEvent.ts View on Github external
import {Property, PropertyName, Required} from "@tsed/common";
import {Model, Ref} from "@tsed/mongoose";
import {Description} from "@tsed/swagger";
import {Calendar} from "../calendars/Calendar";

@Model()
export class CalendarEvent {
  @PropertyName("id")
  _id: string;

  @Ref(Calendar)
  @Description("Calendar ID")
  calendarId: Ref;

  @Property("name")
  @Description("The name of the event")
  name: string;

  @Property()
  @Description("Creation's date")
  dateCreate: Date = new Date();
github TypedProject / ts-express-decorators / examples / mongoose / src / models / calendars / Calendar.ts View on Github external
import {Property, Required} from "@tsed/common";
import {Model, ObjectID} from "@tsed/mongoose";

@Model()
export class Calendar {
  @ObjectID("id")
  _id: string;

  @Required()
  name: string;

  @Property()
  owner: string;
}
github TypedProject / ts-express-decorators / examples / mongoose / src / models / events / CalendarEvent.ts View on Github external
import {Property, PropertyName, Required} from "@tsed/common";
import {Model, Ref} from "@tsed/mongoose";
import {Description} from "@tsed/swagger";
import {Calendar} from "../calendars/Calendar";

@Model()
export class CalendarEvent {
  @PropertyName("id")
  _id: string;

  @Ref(Calendar)
  @Description("Calendar ID")
  calendarId: Ref;

  @Property("name")
  @Description("The name of the event")
  name: string;

  @Property()
  @Description("Creation's date")
  dateCreate: Date = new Date();

  @Property()
  @Description("Last modification date")
  dateUpdate: Date = new Date();

  @Property()

@tsed/mongoose

Mongoose package for Ts.ED framework

MIT
Latest version published 15 days ago

Package Health Score

89 / 100
Full package analysis