@loopback/cli 4.0.0-alpha.9 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.yo-rc.json +1719 -0
- package/{generators/project/templates/LICENSE → LICENSE} +2 -1
- package/README.md +44 -43
- package/bin/cli-main.js +61 -0
- package/generators/app/index.js +109 -15
- package/generators/app/templates/.dockerignore +5 -0
- package/generators/app/templates/Dockerfile +28 -0
- package/generators/app/templates/README.md.ejs +130 -0
- package/generators/app/templates/public/index.html.ejs +88 -0
- package/generators/app/templates/{test → src/__tests__}/README.md +0 -1
- package/generators/app/templates/src/__tests__/acceptance/home-page.acceptance.ts.ejs +31 -0
- package/generators/app/templates/src/__tests__/acceptance/ping.controller.acceptance.ts.ejs +21 -0
- package/generators/app/templates/src/__tests__/acceptance/test-helper.ts.ejs +32 -0
- package/generators/app/templates/src/application.ts.ejs +70 -0
- package/generators/app/templates/src/controllers/README.md +6 -0
- package/generators/app/templates/src/controllers/index.ts.ejs +1 -0
- package/generators/app/templates/src/controllers/ping.controller.ts.ejs +55 -0
- package/generators/app/templates/src/datasources/README.md +3 -0
- package/generators/app/templates/src/index.ts.ejs +39 -0
- package/generators/app/templates/src/migrate.ts.ejs +20 -0
- package/generators/app/templates/src/models/README.md +3 -0
- package/generators/app/templates/src/openapi-spec.ts.ejs +23 -0
- package/generators/app/templates/src/sequence.ts.ejs +3 -0
- package/generators/controller/index.js +240 -23
- package/generators/controller/templates/src/controllers/controller-rest-template.ts.ejs +150 -0
- package/generators/controller/templates/src/controllers/{controller-template.ts → controller-template.ts.ejs} +2 -2
- package/generators/copyright/fs.js +46 -0
- package/generators/copyright/git.js +78 -0
- package/generators/copyright/header.js +306 -0
- package/generators/copyright/index.js +230 -0
- package/generators/copyright/license.js +105 -0
- package/generators/datasource/index.js +341 -0
- package/generators/datasource/templates/datasource.ts.ejs +22 -0
- package/generators/discover/import-discovered-model.js +70 -0
- package/generators/discover/index.js +411 -0
- package/generators/example/downloader.js +16 -0
- package/generators/example/index.js +176 -0
- package/generators/extension/index.js +34 -5
- package/generators/extension/templates/README.md.ejs +32 -0
- package/generators/extension/templates/{test → src/__tests__}/acceptance/README.md +0 -0
- package/generators/extension/templates/{test → src/__tests__}/integration/README.md +0 -0
- package/generators/extension/templates/{test → src/__tests__}/unit/README.md +0 -0
- package/generators/extension/templates/src/component.ts.ejs +22 -0
- package/generators/extension/templates/src/controllers/README.md +3 -2
- package/generators/extension/templates/src/decorators/README.md +10 -4
- package/generators/extension/templates/src/index.ts.ejs +3 -0
- package/generators/extension/templates/src/keys.ts.ejs +11 -0
- package/generators/extension/templates/src/mixins/README.md +77 -21
- package/generators/extension/templates/src/providers/README.md +51 -25
- package/generators/extension/templates/src/repositories/README.md +1 -1
- package/generators/extension/templates/src/types.ts.ejs +15 -0
- package/generators/import-lb3-models/index.js +197 -0
- package/generators/import-lb3-models/lb3app-loader.js +31 -0
- package/generators/import-lb3-models/migrate-model.js +249 -0
- package/generators/import-lb3-models/model-names.js +32 -0
- package/generators/interceptor/index.js +178 -0
- package/generators/interceptor/templates/interceptor-template.ts.ejs +62 -0
- package/generators/model/index.js +536 -0
- package/generators/model/property-definition.js +85 -0
- package/generators/model/templates/model.ts.ejs +49 -0
- package/generators/observer/index.js +132 -0
- package/generators/observer/templates/observer-template.ts.ejs +40 -0
- package/generators/openapi/README.md +211 -0
- package/generators/openapi/index.js +535 -0
- package/generators/openapi/schema-helper.js +447 -0
- package/generators/openapi/spec-helper.js +484 -0
- package/generators/openapi/spec-loader.js +75 -0
- package/generators/openapi/templates/src/controllers/controller-template.ts.ejs +43 -0
- package/generators/openapi/templates/src/datasources/datasource.ts.ejs +42 -0
- package/generators/openapi/templates/src/models/model-template.ts.ejs +71 -0
- package/generators/openapi/templates/src/models/type-template.ts.ejs +13 -0
- package/generators/openapi/templates/src/services/service-proxy-template.ts.ejs +55 -0
- package/generators/openapi/utils.js +322 -0
- package/generators/project/templates/.eslintignore +4 -0
- package/generators/project/templates/.eslintrc.js.ejs +3 -0
- package/generators/project/templates/.mocharc.json +5 -0
- package/generators/project/templates/.prettierignore +0 -2
- package/generators/project/templates/.prettierrc +2 -1
- package/generators/project/templates/.vscode/launch.json +38 -0
- package/generators/project/templates/.vscode/settings.json +32 -0
- package/generators/project/templates/.vscode/tasks.json +29 -0
- package/generators/project/templates/DEVELOPING.md +36 -0
- package/generators/project/templates/_.gitignore +3 -5
- package/generators/project/templates/package.json.ejs +175 -0
- package/generators/project/templates/package.plain.json.ejs +176 -0
- package/generators/project/templates/tsconfig.json.ejs +39 -0
- package/generators/relation/base-relation.generator.js +220 -0
- package/generators/relation/belongs-to-relation.generator.js +196 -0
- package/generators/relation/has-many-relation.generator.js +200 -0
- package/generators/relation/has-many-through-relation.generator.js +331 -0
- package/generators/relation/has-one-relation.generator.js +200 -0
- package/generators/relation/index.js +795 -0
- package/generators/relation/references-many-relation.generator.js +142 -0
- package/generators/relation/templates/controller-relation-template-belongs-to.ts.ejs +38 -0
- package/generators/relation/templates/controller-relation-template-has-many-through.ts.ejs +110 -0
- package/generators/relation/templates/controller-relation-template-has-many.ts.ejs +110 -0
- package/generators/relation/templates/controller-relation-template-has-one.ts.ejs +110 -0
- package/generators/relation/utils.generator.js +260 -0
- package/generators/repository/index.js +576 -0
- package/generators/repository/templates/src/repositories/repository-crud-default-template.ts.ejs +21 -0
- package/generators/repository/templates/src/repositories/repository-kv-template.ts.ejs +19 -0
- package/generators/rest-crud/crud-rest-component.js +63 -0
- package/generators/rest-crud/index.js +423 -0
- package/generators/rest-crud/templates/src/model-endpoints/model.rest-config-template.ts.ejs +11 -0
- package/generators/service/index.js +351 -0
- package/generators/service/templates/local-service-class-template.ts.ejs +10 -0
- package/generators/service/templates/local-service-provider-template.ts.ejs +19 -0
- package/generators/service/templates/remote-service-proxy-template.ts.ejs +21 -0
- package/generators/update/index.js +55 -0
- package/intl/cs/messages.json +204 -0
- package/intl/de/messages.json +204 -0
- package/intl/en/messages.json +204 -0
- package/intl/es/messages.json +204 -0
- package/intl/fr/messages.json +204 -0
- package/intl/it/messages.json +204 -0
- package/intl/ja/messages.json +204 -0
- package/intl/ko/messages.json +204 -0
- package/intl/nl/messages.json +204 -0
- package/intl/pl/messages.json +204 -0
- package/intl/pt/messages.json +204 -0
- package/intl/ru/messages.json +204 -0
- package/intl/tr/messages.json +204 -0
- package/intl/zh-Hans/messages.json +204 -0
- package/intl/zh-Hant/messages.json +204 -0
- package/lib/artifact-generator.js +138 -39
- package/lib/ast-helper.js +214 -0
- package/lib/base-generator.js +509 -0
- package/lib/cli.js +233 -0
- package/lib/connectors.json +894 -0
- package/lib/debug.js +16 -0
- package/lib/globalize.js +12 -0
- package/lib/model-discoverer.js +118 -0
- package/lib/project-generator.js +154 -57
- package/lib/tab-completion.js +127 -0
- package/lib/update-index.js +44 -0
- package/lib/utils.js +689 -20
- package/lib/version-helper.js +299 -0
- package/package.json +183 -39
- package/CHANGELOG.md +0 -86
- package/bin/cli.js +0 -66
- package/generators/app/templates/index.js +0 -14
- package/generators/app/templates/src/application.ts +0 -27
- package/generators/app/templates/src/controllers/ping-controller.ts +0 -25
- package/generators/app/templates/src/index.ts +0 -25
- package/generators/app/templates/test/ping-controller.test.ts +0 -46
- package/generators/extension/templates/index.js +0 -8
- package/generators/extension/templates/src/component.ts +0 -14
- package/generators/extension/templates/src/index.ts +0 -6
- package/generators/project/templates/.npmrc +0 -1
- package/generators/project/templates/.yo-rc.json +0 -1
- package/generators/project/templates/README.md +0 -4
- package/generators/project/templates/index.d.ts +0 -6
- package/generators/project/templates/index.ts +0 -11
- package/generators/project/templates/package.json +0 -79
- package/generators/project/templates/package.plain.json +0 -82
- package/generators/project/templates/test/mocha.opts +0 -1
- package/generators/project/templates/tsconfig.json +0 -29
- package/generators/project/templates/tslint.build.json +0 -17
- package/generators/project/templates/tslint.json +0 -33
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/cli
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const BaseRelationGenerator = require('./base-relation.generator');
|
|
9
|
+
const utils = require('../../lib/utils');
|
|
10
|
+
const relationUtils = require('./utils.generator');
|
|
11
|
+
|
|
12
|
+
module.exports = class ReferencesManyRelationGenerator extends (
|
|
13
|
+
BaseRelationGenerator
|
|
14
|
+
) {
|
|
15
|
+
constructor(args, opts) {
|
|
16
|
+
super(args, opts);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async generateControllers(options) {
|
|
20
|
+
// no controllers
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async generateModels(options) {
|
|
24
|
+
// for repo to generate relation name
|
|
25
|
+
this.artifactInfo.relationName = options.relationName;
|
|
26
|
+
const modelDir = this.artifactInfo.modelDir;
|
|
27
|
+
const sourceModel = options.sourceModel;
|
|
28
|
+
|
|
29
|
+
const targetModel = options.destinationModel;
|
|
30
|
+
const relationType = options.relationType;
|
|
31
|
+
const relationName = options.relationName;
|
|
32
|
+
const defaultRelationName = options.defaultRelationName;
|
|
33
|
+
const foreignKeyName = options.foreignKeyName;
|
|
34
|
+
const fkType = options.destinationModelPrimaryKeyType;
|
|
35
|
+
|
|
36
|
+
const project = new relationUtils.AstLoopBackProject();
|
|
37
|
+
const sourceFile = relationUtils.addFileToProject(
|
|
38
|
+
project,
|
|
39
|
+
modelDir,
|
|
40
|
+
sourceModel,
|
|
41
|
+
);
|
|
42
|
+
const sourceClass = relationUtils.getClassObj(sourceFile, sourceModel);
|
|
43
|
+
// this checks if the foreign key already exists, so the 2nd param should be foreignKeyName
|
|
44
|
+
relationUtils.doesRelationExist(sourceClass, foreignKeyName);
|
|
45
|
+
|
|
46
|
+
const modelProperty = this.getReferencesMany(
|
|
47
|
+
targetModel,
|
|
48
|
+
relationName,
|
|
49
|
+
defaultRelationName,
|
|
50
|
+
foreignKeyName,
|
|
51
|
+
fkType,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
relationUtils.addProperty(sourceClass, modelProperty);
|
|
55
|
+
const imports = relationUtils.getRequiredImports(targetModel, relationType);
|
|
56
|
+
relationUtils.addRequiredImports(sourceFile, imports);
|
|
57
|
+
|
|
58
|
+
sourceClass.formatText();
|
|
59
|
+
await sourceFile.save();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getReferencesMany(
|
|
63
|
+
className,
|
|
64
|
+
relationName,
|
|
65
|
+
defaultRelationName,
|
|
66
|
+
foreignKeyName,
|
|
67
|
+
fkType,
|
|
68
|
+
) {
|
|
69
|
+
// checks if relation name is customized
|
|
70
|
+
let relationDecorator = [
|
|
71
|
+
{
|
|
72
|
+
name: 'referencesMany',
|
|
73
|
+
arguments: [`() => ${className}`],
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
// already checked if the relation name is the same as the source key before
|
|
77
|
+
if (defaultRelationName !== relationName) {
|
|
78
|
+
relationDecorator = [
|
|
79
|
+
{
|
|
80
|
+
name: 'referencesMany',
|
|
81
|
+
arguments: [`() => ${className}, {name: '${relationName}'}`],
|
|
82
|
+
},
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
decorators: relationDecorator,
|
|
87
|
+
name: foreignKeyName,
|
|
88
|
+
type: fkType + '[]',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
_getRepositoryRequiredImports(dstModelClassName, dstRepositoryClassName) {
|
|
93
|
+
const importsArray = super._getRepositoryRequiredImports(
|
|
94
|
+
dstModelClassName,
|
|
95
|
+
dstRepositoryClassName,
|
|
96
|
+
);
|
|
97
|
+
importsArray.push({
|
|
98
|
+
name: 'ReferencesManyAccessor',
|
|
99
|
+
module: '@loopback/repository',
|
|
100
|
+
});
|
|
101
|
+
return importsArray;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
_getRepositoryRelationPropertyName() {
|
|
105
|
+
return this.artifactInfo.relationName;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_initializeProperties(options) {
|
|
109
|
+
super._initializeProperties(options);
|
|
110
|
+
this.artifactInfo.dstModelPrimaryKey = options.destinationModelPrimaryKey;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
_getRepositoryRelationPropertyType() {
|
|
114
|
+
return (
|
|
115
|
+
`ReferencesManyAccessor<` +
|
|
116
|
+
`${utils.toClassName(this.artifactInfo.dstModelClass)}` +
|
|
117
|
+
`, typeof ${utils.toClassName(this.artifactInfo.srcModelClass)}` +
|
|
118
|
+
`.prototype.${this.artifactInfo.srcModelPrimaryKey}>`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
_addCreatorToRepositoryConstructor(classConstructor) {
|
|
123
|
+
const relationName = this.artifactInfo.relationName;
|
|
124
|
+
const statement =
|
|
125
|
+
`this.${relationName} = ` +
|
|
126
|
+
`this.createReferencesManyAccessorFor('` +
|
|
127
|
+
`${relationName}',` +
|
|
128
|
+
` ${utils.camelCase(this.artifactInfo.dstRepositoryClassName)}` +
|
|
129
|
+
`Getter,);`;
|
|
130
|
+
classConstructor.insertStatements(1, statement);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
_registerInclusionResolverForRelation(classConstructor, options) {
|
|
134
|
+
const relationName = this.artifactInfo.relationName;
|
|
135
|
+
if (options.registerInclusionResolver) {
|
|
136
|
+
const statement =
|
|
137
|
+
`this.registerInclusionResolver(` +
|
|
138
|
+
`'${relationName}', this.${relationName}.inclusionResolver);`;
|
|
139
|
+
classConstructor.insertStatements(2, statement);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
repository,
|
|
3
|
+
} from '@loopback/repository';
|
|
4
|
+
import {
|
|
5
|
+
param,
|
|
6
|
+
get,
|
|
7
|
+
getModelSchemaRef,
|
|
8
|
+
} from '@loopback/rest';
|
|
9
|
+
import {
|
|
10
|
+
<%= sourceModelClassName %>,
|
|
11
|
+
<%= targetModelClassName %>,
|
|
12
|
+
} from '../models';
|
|
13
|
+
import {<%= sourceRepositoryClassName %>} from '../repositories';
|
|
14
|
+
|
|
15
|
+
export class <%= controllerClassName %> {
|
|
16
|
+
constructor(
|
|
17
|
+
@repository(<%= sourceRepositoryClassName %>)
|
|
18
|
+
public <%= paramSourceRepository %>: <%= sourceRepositoryClassName %>,
|
|
19
|
+
) { }
|
|
20
|
+
|
|
21
|
+
@get('/<%= sourceModelPath %>/{id}/<%= targetModelName %>', {
|
|
22
|
+
responses: {
|
|
23
|
+
'200': {
|
|
24
|
+
description: '<%= targetModelClassName %> belonging to <%= sourceModelClassName %>',
|
|
25
|
+
content: {
|
|
26
|
+
'application/json': {
|
|
27
|
+
schema: {type: 'array', items: getModelSchemaRef(<%= targetModelClassName %>)},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
async get<%= targetModelClassName %>(
|
|
34
|
+
@param.path.<%= sourceModelPrimaryKeyType %>('id') id: typeof <%= sourceModelClassName %>.prototype.<%= sourceModelPrimaryKey %>,
|
|
35
|
+
): Promise<<%= targetModelClassName %>> {
|
|
36
|
+
return this.<%= paramSourceRepository %>.<%= relationPropertyName %>(id);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Count,
|
|
3
|
+
CountSchema,
|
|
4
|
+
Filter,
|
|
5
|
+
repository,
|
|
6
|
+
Where,
|
|
7
|
+
} from '@loopback/repository';
|
|
8
|
+
import {
|
|
9
|
+
del,
|
|
10
|
+
get,
|
|
11
|
+
getModelSchemaRef,
|
|
12
|
+
getWhereSchemaFor,
|
|
13
|
+
param,
|
|
14
|
+
patch,
|
|
15
|
+
post,
|
|
16
|
+
requestBody,
|
|
17
|
+
} from '@loopback/rest';
|
|
18
|
+
import {
|
|
19
|
+
<%= sourceModelClassName %>,
|
|
20
|
+
<%= throughModelClassName %>,
|
|
21
|
+
<%= targetModelClassName %>,
|
|
22
|
+
} from '../models';
|
|
23
|
+
import {<%= sourceRepositoryClassName %>} from '../repositories';
|
|
24
|
+
|
|
25
|
+
export class <%= controllerClassName %> {
|
|
26
|
+
constructor(
|
|
27
|
+
@repository(<%= sourceRepositoryClassName %>) protected <%= paramSourceRepository %>: <%= sourceRepositoryClassName %>,
|
|
28
|
+
) { }
|
|
29
|
+
|
|
30
|
+
@get('/<%= sourceModelPath %>/{id}/<%= targetModelPath %>', {
|
|
31
|
+
responses: {
|
|
32
|
+
'200': {
|
|
33
|
+
description: 'Array of <%= sourceModelClassName %> has many <%= targetModelClassName %> through <%= throughModelClassName %>',
|
|
34
|
+
content: {
|
|
35
|
+
'application/json': {
|
|
36
|
+
schema: {type: 'array', items: getModelSchemaRef(<%= targetModelClassName %>)},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
async find(
|
|
43
|
+
@param.path.<%= sourceModelPrimaryKeyType %>('id') id: <%= sourceModelPrimaryKeyType %>,
|
|
44
|
+
@param.query.object('filter') filter?: Filter<<%= targetModelClassName %>>,
|
|
45
|
+
): Promise<<%= targetModelClassName %>[]> {
|
|
46
|
+
return this.<%= paramSourceRepository %>.<%= relationPropertyName %>(id).find(filter);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@post('/<%= sourceModelPath %>/{id}/<%= targetModelPath %>', {
|
|
50
|
+
responses: {
|
|
51
|
+
'200': {
|
|
52
|
+
description: 'create a <%= targetModelClassName %> model instance',
|
|
53
|
+
content: {'application/json': {schema: getModelSchemaRef(<%= targetModelClassName %>)}},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
async create(
|
|
58
|
+
@param.path.<%= sourceModelPrimaryKeyType %>('id') id: typeof <%= sourceModelClassName %>.prototype.<%= sourceModelPrimaryKey %>,
|
|
59
|
+
@requestBody({
|
|
60
|
+
content: {
|
|
61
|
+
'application/json': {
|
|
62
|
+
schema: getModelSchemaRef(<%= targetModelClassName %>, {
|
|
63
|
+
title: 'New<%= targetModelClassName %>In<%= sourceModelClassName %>',
|
|
64
|
+
exclude: ['<%= targetModelPrimaryKey %>'],
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
}) <%= targetModelRequestBody %>: Omit<<%= targetModelClassName %>, '<%= targetModelPrimaryKey %>'>,
|
|
69
|
+
): Promise<<%= targetModelClassName %>> {
|
|
70
|
+
return this.<%= paramSourceRepository %>.<%= relationPropertyName %>(id).create(<%= targetModelRequestBody %>);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@patch('/<%= sourceModelPath %>/{id}/<%= targetModelPath %>', {
|
|
74
|
+
responses: {
|
|
75
|
+
'200': {
|
|
76
|
+
description: '<%= sourceModelClassName %>.<%= targetModelClassName %> PATCH success count',
|
|
77
|
+
content: {'application/json': {schema: CountSchema}},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
async patch(
|
|
82
|
+
@param.path.<%= sourceModelPrimaryKeyType %>('id') id: <%= sourceModelPrimaryKeyType %>,
|
|
83
|
+
@requestBody({
|
|
84
|
+
content: {
|
|
85
|
+
'application/json': {
|
|
86
|
+
schema: getModelSchemaRef(<%= targetModelClassName %>, {partial: true}),
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
})
|
|
90
|
+
<%= targetModelRequestBody %>: Partial<<%= targetModelClassName %>>,
|
|
91
|
+
@param.query.object('where', getWhereSchemaFor(<%= targetModelClassName %>)) where?: Where<<%= targetModelClassName %>>,
|
|
92
|
+
): Promise<Count> {
|
|
93
|
+
return this.<%= paramSourceRepository %>.<%= relationPropertyName %>(id).patch(<%= targetModelRequestBody %>, where);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@del('/<%= sourceModelPath %>/{id}/<%= targetModelPath %>', {
|
|
97
|
+
responses: {
|
|
98
|
+
'200': {
|
|
99
|
+
description: '<%= sourceModelClassName %>.<%= targetModelClassName %> DELETE success count',
|
|
100
|
+
content: {'application/json': {schema: CountSchema}},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
})
|
|
104
|
+
async delete(
|
|
105
|
+
@param.path.<%= sourceModelPrimaryKeyType %>('id') id: <%= sourceModelPrimaryKeyType %>,
|
|
106
|
+
@param.query.object('where', getWhereSchemaFor(<%= targetModelClassName %>)) where?: Where<<%= targetModelClassName %>>,
|
|
107
|
+
): Promise<Count> {
|
|
108
|
+
return this.<%= paramSourceRepository %>.<%= relationPropertyName %>(id).delete(where);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Count,
|
|
3
|
+
CountSchema,
|
|
4
|
+
Filter,
|
|
5
|
+
repository,
|
|
6
|
+
Where,
|
|
7
|
+
} from '@loopback/repository';
|
|
8
|
+
import {
|
|
9
|
+
del,
|
|
10
|
+
get,
|
|
11
|
+
getModelSchemaRef,
|
|
12
|
+
getWhereSchemaFor,
|
|
13
|
+
param,
|
|
14
|
+
patch,
|
|
15
|
+
post,
|
|
16
|
+
requestBody,
|
|
17
|
+
} from '@loopback/rest';
|
|
18
|
+
import {
|
|
19
|
+
<%= sourceModelClassName %>,
|
|
20
|
+
<%= targetModelClassName %>,
|
|
21
|
+
} from '../models';
|
|
22
|
+
import {<%= sourceRepositoryClassName %>} from '../repositories';
|
|
23
|
+
|
|
24
|
+
export class <%= controllerClassName %> {
|
|
25
|
+
constructor(
|
|
26
|
+
@repository(<%= sourceRepositoryClassName %>) protected <%= paramSourceRepository %>: <%= sourceRepositoryClassName %>,
|
|
27
|
+
) { }
|
|
28
|
+
|
|
29
|
+
@get('/<%= sourceModelPath %>/{id}/<%= targetModelPath %>', {
|
|
30
|
+
responses: {
|
|
31
|
+
'200': {
|
|
32
|
+
description: 'Array of <%= sourceModelClassName %> has many <%= targetModelClassName %>',
|
|
33
|
+
content: {
|
|
34
|
+
'application/json': {
|
|
35
|
+
schema: {type: 'array', items: getModelSchemaRef(<%= targetModelClassName %>)},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
async find(
|
|
42
|
+
@param.path.<%= sourceModelPrimaryKeyType %>('id') id: <%= sourceModelPrimaryKeyType %>,
|
|
43
|
+
@param.query.object('filter') filter?: Filter<<%= targetModelClassName %>>,
|
|
44
|
+
): Promise<<%= targetModelClassName %>[]> {
|
|
45
|
+
return this.<%= paramSourceRepository %>.<%= relationPropertyName %>(id).find(filter);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@post('/<%= sourceModelPath %>/{id}/<%= targetModelPath %>', {
|
|
49
|
+
responses: {
|
|
50
|
+
'200': {
|
|
51
|
+
description: '<%= sourceModelClassName %> model instance',
|
|
52
|
+
content: {'application/json': {schema: getModelSchemaRef(<%= targetModelClassName %>)}},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
async create(
|
|
57
|
+
@param.path.<%= sourceModelPrimaryKeyType %>('id') id: typeof <%= sourceModelClassName %>.prototype.<%= sourceModelPrimaryKey %>,
|
|
58
|
+
@requestBody({
|
|
59
|
+
content: {
|
|
60
|
+
'application/json': {
|
|
61
|
+
schema: getModelSchemaRef(<%= targetModelClassName %>, {
|
|
62
|
+
title: 'New<%= targetModelClassName %>In<%= sourceModelClassName %>',
|
|
63
|
+
exclude: ['<%= targetModelPrimaryKey %>'],
|
|
64
|
+
optional: ['<%= foreignKeyName %>']
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
}) <%= targetModelRequestBody %>: Omit<<%= targetModelClassName %>, '<%= targetModelPrimaryKey %>'>,
|
|
69
|
+
): Promise<<%= targetModelClassName %>> {
|
|
70
|
+
return this.<%= paramSourceRepository %>.<%= relationPropertyName %>(id).create(<%= targetModelRequestBody %>);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@patch('/<%= sourceModelPath %>/{id}/<%= targetModelPath %>', {
|
|
74
|
+
responses: {
|
|
75
|
+
'200': {
|
|
76
|
+
description: '<%= sourceModelClassName %>.<%= targetModelClassName %> PATCH success count',
|
|
77
|
+
content: {'application/json': {schema: CountSchema}},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
async patch(
|
|
82
|
+
@param.path.<%= sourceModelPrimaryKeyType %>('id') id: <%= sourceModelPrimaryKeyType %>,
|
|
83
|
+
@requestBody({
|
|
84
|
+
content: {
|
|
85
|
+
'application/json': {
|
|
86
|
+
schema: getModelSchemaRef(<%= targetModelClassName %>, {partial: true}),
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
})
|
|
90
|
+
<%= targetModelRequestBody %>: Partial<<%= targetModelClassName %>>,
|
|
91
|
+
@param.query.object('where', getWhereSchemaFor(<%= targetModelClassName %>)) where?: Where<<%= targetModelClassName %>>,
|
|
92
|
+
): Promise<Count> {
|
|
93
|
+
return this.<%= paramSourceRepository %>.<%= relationPropertyName %>(id).patch(<%= targetModelRequestBody %>, where);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@del('/<%= sourceModelPath %>/{id}/<%= targetModelPath %>', {
|
|
97
|
+
responses: {
|
|
98
|
+
'200': {
|
|
99
|
+
description: '<%= sourceModelClassName %>.<%= targetModelClassName %> DELETE success count',
|
|
100
|
+
content: {'application/json': {schema: CountSchema}},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
})
|
|
104
|
+
async delete(
|
|
105
|
+
@param.path.<%= sourceModelPrimaryKeyType %>('id') id: <%= sourceModelPrimaryKeyType %>,
|
|
106
|
+
@param.query.object('where', getWhereSchemaFor(<%= targetModelClassName %>)) where?: Where<<%= targetModelClassName %>>,
|
|
107
|
+
): Promise<Count> {
|
|
108
|
+
return this.<%= paramSourceRepository %>.<%= relationPropertyName %>(id).delete(where);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Count,
|
|
3
|
+
CountSchema,
|
|
4
|
+
Filter,
|
|
5
|
+
repository,
|
|
6
|
+
Where,
|
|
7
|
+
} from '@loopback/repository';
|
|
8
|
+
import {
|
|
9
|
+
del,
|
|
10
|
+
get,
|
|
11
|
+
getModelSchemaRef,
|
|
12
|
+
getWhereSchemaFor,
|
|
13
|
+
param,
|
|
14
|
+
patch,
|
|
15
|
+
post,
|
|
16
|
+
requestBody,
|
|
17
|
+
} from '@loopback/rest';
|
|
18
|
+
import {
|
|
19
|
+
<%= sourceModelClassName %>,
|
|
20
|
+
<%= targetModelClassName %>,
|
|
21
|
+
} from '../models';
|
|
22
|
+
import {<%= sourceRepositoryClassName %>} from '../repositories';
|
|
23
|
+
|
|
24
|
+
export class <%= controllerClassName %> {
|
|
25
|
+
constructor(
|
|
26
|
+
@repository(<%= sourceRepositoryClassName %>) protected <%= paramSourceRepository %>: <%= sourceRepositoryClassName %>,
|
|
27
|
+
) { }
|
|
28
|
+
|
|
29
|
+
@get('/<%= sourceModelPath %>/{id}/<%= targetModelPath %>', {
|
|
30
|
+
responses: {
|
|
31
|
+
'200': {
|
|
32
|
+
description: '<%= sourceModelClassName %> has one <%= targetModelClassName %>',
|
|
33
|
+
content: {
|
|
34
|
+
'application/json': {
|
|
35
|
+
schema: getModelSchemaRef(<%= targetModelClassName %>),
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
async get(
|
|
42
|
+
@param.path.<%= sourceModelPrimaryKeyType %>('id') id: <%= sourceModelPrimaryKeyType %>,
|
|
43
|
+
@param.query.object('filter') filter?: Filter<<%= targetModelClassName %>>,
|
|
44
|
+
): Promise<<%= targetModelClassName %>> {
|
|
45
|
+
return this.<%= paramSourceRepository %>.<%= relationPropertyName %>(id).get(filter);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@post('/<%= sourceModelPath %>/{id}/<%= targetModelPath %>', {
|
|
49
|
+
responses: {
|
|
50
|
+
'200': {
|
|
51
|
+
description: '<%= sourceModelClassName %> model instance',
|
|
52
|
+
content: {'application/json': {schema: getModelSchemaRef(<%= targetModelClassName %>)}},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
async create(
|
|
57
|
+
@param.path.<%= sourceModelPrimaryKeyType %>('id') id: typeof <%= sourceModelClassName %>.prototype.<%= sourceModelPrimaryKey %>,
|
|
58
|
+
@requestBody({
|
|
59
|
+
content: {
|
|
60
|
+
'application/json': {
|
|
61
|
+
schema: getModelSchemaRef(<%= targetModelClassName %>, {
|
|
62
|
+
title: 'New<%= targetModelClassName %>In<%= sourceModelClassName %>',
|
|
63
|
+
exclude: ['<%= targetModelPrimaryKey %>'],
|
|
64
|
+
optional: ['<%= foreignKeyName %>']
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
}) <%= targetModelRequestBody %>: Omit<<%= targetModelClassName %>, '<%= targetModelPrimaryKey %>'>,
|
|
69
|
+
): Promise<<%= targetModelClassName %>> {
|
|
70
|
+
return this.<%= paramSourceRepository %>.<%= relationPropertyName %>(id).create(<%= targetModelRequestBody %>);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@patch('/<%= sourceModelPath %>/{id}/<%= targetModelPath %>', {
|
|
74
|
+
responses: {
|
|
75
|
+
'200': {
|
|
76
|
+
description: '<%= sourceModelClassName %>.<%= targetModelClassName %> PATCH success count',
|
|
77
|
+
content: {'application/json': {schema: CountSchema}},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
async patch(
|
|
82
|
+
@param.path.<%= sourceModelPrimaryKeyType %>('id') id: <%= sourceModelPrimaryKeyType %>,
|
|
83
|
+
@requestBody({
|
|
84
|
+
content: {
|
|
85
|
+
'application/json': {
|
|
86
|
+
schema: getModelSchemaRef(<%= targetModelClassName %>, {partial: true}),
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
})
|
|
90
|
+
<%= targetModelRequestBody %>: Partial<<%= targetModelClassName %>>,
|
|
91
|
+
@param.query.object('where', getWhereSchemaFor(<%= targetModelClassName %>)) where?: Where<<%= targetModelClassName %>>,
|
|
92
|
+
): Promise<Count> {
|
|
93
|
+
return this.<%= paramSourceRepository %>.<%= relationPropertyName %>(id).patch(<%= targetModelRequestBody %>, where);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@del('/<%= sourceModelPath %>/{id}/<%= targetModelPath %>', {
|
|
97
|
+
responses: {
|
|
98
|
+
'200': {
|
|
99
|
+
description: '<%= sourceModelClassName %>.<%= targetModelClassName %> DELETE success count',
|
|
100
|
+
content: {'application/json': {schema: CountSchema}},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
})
|
|
104
|
+
async delete(
|
|
105
|
+
@param.path.<%= sourceModelPrimaryKeyType %>('id') id: <%= sourceModelPrimaryKeyType %>,
|
|
106
|
+
@param.query.object('where', getWhereSchemaFor(<%= targetModelClassName %>)) where?: Where<<%= targetModelClassName %>>,
|
|
107
|
+
): Promise<Count> {
|
|
108
|
+
return this.<%= paramSourceRepository %>.<%= relationPropertyName %>(id).delete(where);
|
|
109
|
+
}
|
|
110
|
+
}
|