1.0.9 • Published 7 years ago

@square-one/model-decorators v1.0.9

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

Model Decorators

Decorators that will allow for classes to be built as models for mongoose and also be used within client side frameworks like Angular 2 to build out custom elements.

Example

import { Field, FieldArray, Model, Method, StaticMethod } from "@add-io/model-decorators";

@Model("Example")
export class Example {

    @Field({ required: true })
    name: string;

    @Field()
    description: string;

    @Field({ ref: "ExampleRef" })
    example: ExampleRef;

    @FieldArray(String, { required: true })
    items: string[];

    @FieldArray(ExampleRef, { ref: "ExampleRef" })
    examples: ExampleRef[];

    @Method()
    save() {
        // Do save method stuff...
    }

    @StaticMethod()
    static loadExamples() {
        // Load examples from the database...
    }
}

@Model("ExampleRef")
export class ExampleRef {

    @Field({ required: true })
    name: string;
}

License

This library is under the MIT License