Skip to content

Commit 370223c

Browse files
committed
Enable Model properties
1 parent 9973e14 commit 370223c

2 files changed

Lines changed: 11 additions & 72 deletions

File tree

common/models/meta.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,36 @@ module.exports = function (Meta) {
77
* Helper method for format the type of the properties
88
*/
99
function formatProperties (properties) {
10-
//for (var key in properties) {
11-
// var type = properties[key].type.toString().toLowerCase().substr('function '.length);
12-
// type = type.substr(0, type.indexOf('('));
13-
// properties[key].type = type;
14-
//}
10+
for (var key in properties) {
11+
var type = properties[key].type.toString().toLowerCase().substr('function '.length);
12+
type = type.substr(0, type.indexOf('('));
13+
properties[key].propertyType = type;
14+
}
1515
return properties;
1616
}
1717

18-
/**
19-
* Get the definition of the model
20-
*/
21-
function getModelDefinition (modelName) {
22-
return Meta.app.models[modelName].definition;
23-
}
2418

2519
/**
2620
* Get the definition of a model and format the result in a way that's similar to a LoopBack model definition file
2721
*/
2822
function getModelInfo (modelName) {
2923

30-
// Get the model definition
31-
var definition = getModelDefinition(modelName);
24+
// Get the model
25+
var model = Meta.app.models[modelName];
3226

3327
// Create the base return object
3428
var result = {
35-
id: definition.name,
36-
name: definition.name,
37-
properties: formatProperties(definition.properties)
29+
id: model.definition.name,
30+
name: model.definition.name,
31+
properties: formatProperties(model.definition.properties)
3832
};
3933

4034
// Get the following keys from the settings object, if they are set
4135
var keys = ['description', 'plural', 'base', 'idInjection', 'persistUndefinedAsNull', 'strict', 'hidden',
4236
'validations', 'relations', 'acls', 'methods', 'mixins'
4337
];
4438
keys.forEach(function (key) {
45-
result[key] = _.get(definition.settings, key);
39+
result[key] = _.get(model.definition.settings, key);
4640
});
4741
return result;
4842
}

common/models/meta.json

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -50,61 +50,6 @@
5050
"path": "/:name",
5151
"verb": "get"
5252
}
53-
},
54-
"getModelItem": {
55-
"isStatic": true,
56-
"accepts": [
57-
{
58-
"arg": "modelName",
59-
"type": "string",
60-
"required": true
61-
},
62-
{
63-
"arg": "modelId",
64-
"type": "string",
65-
"required": true
66-
}
67-
],
68-
"returns": {
69-
"arg": "result",
70-
"type": "object",
71-
"root": true
72-
},
73-
"description": "Retrieve an instance of a model by model name and id",
74-
"http": {
75-
"path": "/getModelItem",
76-
"verb": "get"
77-
}
78-
},
79-
"getModelItems": {
80-
"isStatic": true,
81-
"accepts": [
82-
{
83-
"arg": "modelName",
84-
"type": "string",
85-
"required": true
86-
},
87-
{
88-
"arg": "limit",
89-
"type": "number",
90-
"required": false
91-
},
92-
{
93-
"arg": "offset",
94-
"type": "number",
95-
"required": false
96-
}
97-
],
98-
"returns": {
99-
"arg": "result",
100-
"type": "array",
101-
"root": true
102-
},
103-
"description": "Retrieve instances of a model by model name",
104-
"http": {
105-
"path": "/getModelItems",
106-
"verb": "get"
107-
}
10853
}
10954
}
11055
}

0 commit comments

Comments
 (0)