Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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({
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();
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;
}
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();