MCPcopy
hub / github.com/diegohaz/rest / view

Function view

generators/api/templates/model.js:29–49  ·  view source on GitHub ↗
(full)

Source from the content-addressed store, hash-verified

27
28<%= camel %>Schema.methods = {
29 view (full) {
30 const view = {
31 // simple view
32 id: this.id,
33 <%_ if (storeUser) { _%>
34 <%= userField %>: this.<%= userField %>.view(full),
35 <%_ } _%>
36 <%_ if (modelFields.length) { _%>
37 <%_ modelFields.forEach(function (field) { _%>
38 <%= field %>: this.<%= field %>,
39 <%_ }) _%>
40 <%_ } _%>
41 createdAt: this.createdAt,
42 updatedAt: this.updatedAt
43 }
44
45 return full ? {
46 ...view
47 // add properties for a full view
48 } : view
49 }
50}
51
52const model = mongoose.model('<%= pascal %>', <%= camel %>Schema)

Callers 2

controller.jsFile · 0.70
model.test.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected