diff --git a/examples/todo/src/models/_generated/index.ts b/examples/todo/src/models/_generated/index.ts new file mode 100644 index 000000000000..34db877d1083 --- /dev/null +++ b/examples/todo/src/models/_generated/index.ts @@ -0,0 +1,6 @@ +// Copyright IBM Corp. 2017,2018. All Rights Reserved. +// Node module: @loopback/example-todo +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +export * from './todo.base.model'; diff --git a/examples/todo/src/models/_generated/todo.base.model.ts b/examples/todo/src/models/_generated/todo.base.model.ts new file mode 100644 index 000000000000..bd01d205f947 --- /dev/null +++ b/examples/todo/src/models/_generated/todo.base.model.ts @@ -0,0 +1,18 @@ +// Copyright IBM Corp. 2017,2018. All Rights Reserved. +// Node module: @loopback/example-todo +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +import {Entity, ModelDefinition} from '@loopback/repository'; +const modelDef = require('../todo.model.json'); + +export class TodoBase extends Entity { + static definition = new ModelDefinition(modelDef); + + id?: number; + title: string; + desc?: string; + isComplete: boolean; + remindAtAddress?: string; + remindAtGeo?: string; +} diff --git a/examples/todo/src/models/todo.model.json b/examples/todo/src/models/todo.model.json new file mode 100644 index 000000000000..350063efa1f8 --- /dev/null +++ b/examples/todo/src/models/todo.model.json @@ -0,0 +1,32 @@ +{ + "name": "Todo", + "extends": "Entity", + "properties": { + "id": { + "type": "number", + "id": true, + "required": false + }, + "title": { + "type": "string", + "required": true + }, + "desc": { + "type": "string", + "required": false + }, + "isComplete": { + "type": "boolean", + "required": true, + "defaultValue": "false" + }, + "remindAtAddress": { + "type": "string", + "required": false + }, + "remindAtGeo": { + "type": "string", + "required": false + } + } +} diff --git a/examples/todo/src/models/todo.model.ts b/examples/todo/src/models/todo.model.ts index 6f4c45de27f9..4c7cf8e7fa28 100644 --- a/examples/todo/src/models/todo.model.ts +++ b/examples/todo/src/models/todo.model.ts @@ -3,48 +3,6 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT -import {Entity, property, model} from '@loopback/repository'; +import {TodoBase} from './_generated'; -@model() -export class Todo extends Entity { - @property({ - type: 'number', - id: true, - }) - id?: number; - - @property({ - type: 'string', - required: true, - }) - title: string; - - @property({ - type: 'string', - }) - desc?: string; - - @property({ - type: 'boolean', - }) - isComplete: boolean; - - @property({ - type: 'string', - }) - remindAtAddress: string; // address,city,zipcode - - // TODO(bajtos) Use LoopBack's GeoPoint type here - @property({ - type: 'string', - }) - remindAtGeo: string; // latitude,longitude - - getId() { - return this.id; - } - - constructor(data?: Partial) { - super(data); - } -} +export class Todo extends TodoBase {}