Skip to content

Commit 8394c74

Browse files
ludoheninraymondfeng
authored andcommitted
fix(cli): add missing PUT method in rest controller template
1 parent 1016a09 commit 8394c74

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

packages/cli/generators/controller/templates/src/controllers/controller-rest-template.ts.ejs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
getFilterSchemaFor,
1313
getWhereSchemaFor,
1414
patch,
15+
put,
1516
del,
1617
requestBody,
1718
} from '@loopback/rest';
@@ -109,6 +110,20 @@ export class <%= className %>Controller {
109110
await this.<%= repositoryNameCamel %>.updateById(id, <%= modelVariableName %>);
110111
}
111112

113+
@put('<%= httpPathName %>/{id}', {
114+
responses: {
115+
'204': {
116+
description: '<%= modelName %> PUT success',
117+
},
118+
},
119+
})
120+
async replaceById(
121+
@param.path.<%= idType %>('id') id: <%= idType %>,
122+
@requestBody() <%= modelVariableName %>: <%= modelName %>,
123+
): Promise<void> {
124+
await this.<%= repositoryNameCamel %>.replaceById(id, <%= modelVariableName %>);
125+
}
126+
112127
@del('<%= httpPathName %>/{id}', {
113128
responses: {
114129
'204': {

packages/cli/test/integration/generators/controller.integration.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,18 @@ function checkRestCrudContents() {
318318
assert.fileContent(expectedFile, regex);
319319
});
320320

321+
// @put - replaceById
322+
const putReplaceByIdRegEx = [
323+
/\@put\('\/product-reviews\/{id}'/,
324+
/responses: {/,
325+
/'204': {/,
326+
/description: 'ProductReview PUT success'/,
327+
/async replaceById\(\s{1,}\@param.path.number\('id'\) id: number,\s{1,}\@requestBody\(\) productReview: ProductReview,\s+\)/,
328+
];
329+
putReplaceByIdRegEx.forEach(regex => {
330+
assert.fileContent(expectedFile, regex);
331+
});
332+
321333
// @del - deleteById
322334
const deleteByIdRegEx = [
323335
/\@del\('\/product-reviews\/{id}', {/,

0 commit comments

Comments
 (0)