@loopback/sequelize 0.1.0
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/LICENSE +25 -0
- package/README.md +194 -0
- package/dist/.sandbox/6646miobBk/application.js +15 -0
- package/dist/.sandbox/6646miobBk/controllers/book-category.controller.js +41 -0
- package/dist/.sandbox/6646miobBk/controllers/book.controller.js +210 -0
- package/dist/.sandbox/6646miobBk/controllers/category.controller.js +198 -0
- package/dist/.sandbox/6646miobBk/controllers/developer.controller.js +177 -0
- package/dist/.sandbox/6646miobBk/controllers/doctor-patient.controller.js +112 -0
- package/dist/.sandbox/6646miobBk/controllers/doctor.controller.js +177 -0
- package/dist/.sandbox/6646miobBk/controllers/index.js +20 -0
- package/dist/.sandbox/6646miobBk/controllers/patient.controller.js +165 -0
- package/dist/.sandbox/6646miobBk/controllers/programming-languange.controller.js +204 -0
- package/dist/.sandbox/6646miobBk/controllers/test.controller.base.js +25 -0
- package/dist/.sandbox/6646miobBk/controllers/todo-list-todo.controller.js +113 -0
- package/dist/.sandbox/6646miobBk/controllers/todo-list.controller.js +177 -0
- package/dist/.sandbox/6646miobBk/controllers/todo-todo-list.controller.js +41 -0
- package/dist/.sandbox/6646miobBk/controllers/todo.controller.js +177 -0
- package/dist/.sandbox/6646miobBk/controllers/user-todo-list.controller.js +113 -0
- package/dist/.sandbox/6646miobBk/controllers/user.controller.js +210 -0
- package/dist/.sandbox/6646miobBk/datasources/db.datasource.js +28 -0
- package/dist/.sandbox/6646miobBk/models/appointment.model.js +37 -0
- package/dist/.sandbox/6646miobBk/models/book.model.js +48 -0
- package/dist/.sandbox/6646miobBk/models/category.model.js +32 -0
- package/dist/.sandbox/6646miobBk/models/developer.model.js +40 -0
- package/dist/.sandbox/6646miobBk/models/doctor.model.js +44 -0
- package/dist/.sandbox/6646miobBk/models/index.js +15 -0
- package/dist/.sandbox/6646miobBk/models/patient.model.js +32 -0
- package/dist/.sandbox/6646miobBk/models/programming-language.model.js +32 -0
- package/dist/.sandbox/6646miobBk/models/todo-list.model.js +45 -0
- package/dist/.sandbox/6646miobBk/models/todo.model.js +44 -0
- package/dist/.sandbox/6646miobBk/models/user.model.js +85 -0
- package/dist/.sandbox/6646miobBk/repositories/appointment.repository.js +20 -0
- package/dist/.sandbox/6646miobBk/repositories/book.repository.js +25 -0
- package/dist/.sandbox/6646miobBk/repositories/category.repository.js +20 -0
- package/dist/.sandbox/6646miobBk/repositories/developer.repository.js +25 -0
- package/dist/.sandbox/6646miobBk/repositories/doctor.repository.js +27 -0
- package/dist/.sandbox/6646miobBk/repositories/index.js +15 -0
- package/dist/.sandbox/6646miobBk/repositories/patient.repository.js +20 -0
- package/dist/.sandbox/6646miobBk/repositories/programming-language.repository.js +20 -0
- package/dist/.sandbox/6646miobBk/repositories/todo-list.repository.js +25 -0
- package/dist/.sandbox/6646miobBk/repositories/todo.repository.js +25 -0
- package/dist/.sandbox/6646miobBk/repositories/user.repository.js +29 -0
- package/dist/component.d.ts +7 -0
- package/dist/component.js +30 -0
- package/dist/component.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +8 -0
- package/dist/keys.js +16 -0
- package/dist/keys.js.map +1 -0
- package/dist/sequelize/connector-mapping.d.ts +9 -0
- package/dist/sequelize/connector-mapping.js +19 -0
- package/dist/sequelize/connector-mapping.js.map +1 -0
- package/dist/sequelize/index.d.ts +2 -0
- package/dist/sequelize/index.js +10 -0
- package/dist/sequelize/index.js.map +1 -0
- package/dist/sequelize/operator-translation.d.ts +8 -0
- package/dist/sequelize/operator-translation.js +31 -0
- package/dist/sequelize/operator-translation.js.map +1 -0
- package/dist/sequelize/sequelize.datasource.base.d.ts +23 -0
- package/dist/sequelize/sequelize.datasource.base.js +60 -0
- package/dist/sequelize/sequelize.datasource.base.js.map +1 -0
- package/dist/sequelize/sequelize.model.d.ts +7 -0
- package/dist/sequelize/sequelize.model.js +24 -0
- package/dist/sequelize/sequelize.model.js.map +1 -0
- package/dist/sequelize/sequelize.repository.base.d.ts +231 -0
- package/dist/sequelize/sequelize.repository.base.js +835 -0
- package/dist/sequelize/sequelize.repository.base.js.map +1 -0
- package/dist/sequelize/utils.d.ts +6 -0
- package/dist/sequelize/utils.js +17 -0
- package/dist/sequelize/utils.js.map +1 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/package.json +64 -0
- package/src/component.ts +34 -0
- package/src/index.ts +9 -0
- package/src/keys.ts +16 -0
- package/src/sequelize/connector-mapping.ts +26 -0
- package/src/sequelize/index.ts +7 -0
- package/src/sequelize/operator-translation.ts +32 -0
- package/src/sequelize/sequelize.datasource.base.ts +81 -0
- package/src/sequelize/sequelize.model.ts +22 -0
- package/src/sequelize/sequelize.repository.base.ts +1246 -0
- package/src/sequelize/utils.ts +13 -0
- package/src/types.ts +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Copyright (c) LoopBack contributors 2022.
|
|
2
|
+
Node module: @loopback/sequelize
|
|
3
|
+
This project is licensed under the MIT License, full text below.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
MIT license
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in
|
|
17
|
+
all copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# @loopback/sequelize
|
|
2
|
+
|
|
3
|
+
This is a loopback4 extension that provides Sequelize's query builder at
|
|
4
|
+
repository level in any loopback 4 application. It has zero learning curve as it
|
|
5
|
+
follows similar interface as `DefaultCrudRepository`. For relational databases,
|
|
6
|
+
Sequelize is a popular ORM of choice.
|
|
7
|
+
|
|
8
|
+
For pending features, refer to the [Limitations](#limitations) section below.
|
|
9
|
+
|
|
10
|
+
## Stability: ⚠️Experimental⚠️
|
|
11
|
+
|
|
12
|
+
> Experimental packages provide early access to advanced or experimental
|
|
13
|
+
> functionality to get community feedback. Such modules are published to npm
|
|
14
|
+
> using `0.x.y` versions. Their APIs and functionality may be subject to
|
|
15
|
+
> breaking changes in future releases.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
To install this extension in your Loopback 4 project, run the following command:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm install @loopback/sequelize
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
You'll also need to install the driver for your preferred database:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
# One of the following:
|
|
29
|
+
npm install --save pg pg-hstore # Postgres
|
|
30
|
+
npm install --save mysql2
|
|
31
|
+
npm install --save mariadb
|
|
32
|
+
npm install --save sqlite3
|
|
33
|
+
npm install --save tedious # Microsoft SQL Server
|
|
34
|
+
npm install --save oracledb # Oracle Database
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
> You can watch a video overview of this extension by
|
|
40
|
+
> [clicking here](https://youtu.be/ZrUxIk63oRc).
|
|
41
|
+
|
|
42
|
+
<!-- tutorial-start -->
|
|
43
|
+
|
|
44
|
+
Both newly developed and existing projects can benefit from the extension by
|
|
45
|
+
simply changing the parent classes in the target Data Source and Repositories.
|
|
46
|
+
|
|
47
|
+
### Step 1: Configure DataSource
|
|
48
|
+
|
|
49
|
+
Change the parent class from `juggler.DataSource` to `SequelizeDataSource` like
|
|
50
|
+
below.
|
|
51
|
+
|
|
52
|
+
```ts title="pg.datasource.ts"
|
|
53
|
+
// ...
|
|
54
|
+
import {SequelizeDataSource} from '@loopback/sequelize';
|
|
55
|
+
|
|
56
|
+
// ...
|
|
57
|
+
export class PgDataSource
|
|
58
|
+
extends SequelizeDataSource
|
|
59
|
+
implements LifeCycleObserver {
|
|
60
|
+
// ...
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Step 2: Configure Repository
|
|
65
|
+
|
|
66
|
+
Change the parent class from `DefaultCrudRepository` to
|
|
67
|
+
`SequelizeCrudRepository` like below.
|
|
68
|
+
|
|
69
|
+
```ts title="your.repository.ts"
|
|
70
|
+
// ...
|
|
71
|
+
import {SequelizeCrudRepository} from '@loopback/sequelize';
|
|
72
|
+
|
|
73
|
+
export class YourRepository extends SequelizeCrudRepository<
|
|
74
|
+
YourModel,
|
|
75
|
+
typeof YourModel.prototype.id,
|
|
76
|
+
YourModelRelations
|
|
77
|
+
> {
|
|
78
|
+
// ...
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Relations
|
|
83
|
+
|
|
84
|
+
### Supported Loopback Relations
|
|
85
|
+
|
|
86
|
+
With `SequelizeCrudRepository`, you can utilize following relations without any
|
|
87
|
+
additional configuration:
|
|
88
|
+
|
|
89
|
+
1. [HasMany Relation](https://loopback.io/doc/en/lb4/HasMany-relation.html)
|
|
90
|
+
2. [BelongsTo Relation](https://loopback.io/doc/en/lb4/BelongsTo-relation.html)
|
|
91
|
+
3. [HasOne Relation](https://loopback.io/doc/en/lb4/HasOne-relation.html)
|
|
92
|
+
4. [HasManyThrough Relation](https://loopback.io/doc/en/lb4/HasManyThrough-relation.html)
|
|
93
|
+
5. [ReferencesMany Relation](https://loopback.io/doc/en/lb4/ReferencesMany-relation.html)
|
|
94
|
+
|
|
95
|
+
The default relation configuration, generated using the
|
|
96
|
+
[lb4 relation](https://loopback.io/doc/en/lb4/Relation-generator.html) command
|
|
97
|
+
(i.e. inclusion resolvers in the repository and property decorators in the
|
|
98
|
+
model), remain unchanged.
|
|
99
|
+
|
|
100
|
+
### INNER JOIN
|
|
101
|
+
|
|
102
|
+
> Check the demo video of using inner joins here:
|
|
103
|
+
> https://youtu.be/ZrUxIk63oRc?t=76
|
|
104
|
+
|
|
105
|
+
When using `SequelizeCrudRepository`, the `find()`, `findOne()`, and
|
|
106
|
+
`findById()` methods accept a new option called `required` in the include
|
|
107
|
+
filter. Setting this option to `true` will result in an inner join query that
|
|
108
|
+
explicitly requires the specified condition for the child model. If the row does
|
|
109
|
+
not meet this condition, it will not be fetched and returned.
|
|
110
|
+
|
|
111
|
+
An example of the filter object might look like this to fetch the books who
|
|
112
|
+
contains "Art" in their title, which belongs to category "Programming":
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
"where": {"title": {"like": "%Art%"}},
|
|
117
|
+
"include": [
|
|
118
|
+
{
|
|
119
|
+
"relation": "category",
|
|
120
|
+
"scope": {
|
|
121
|
+
"where": {
|
|
122
|
+
"name": "Programming"
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"required": true // 👈
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
<!-- tutorial-end -->
|
|
132
|
+
|
|
133
|
+
## Debug strings reference
|
|
134
|
+
|
|
135
|
+
There are three built-in debug strings available in this extension to aid in
|
|
136
|
+
debugging. To learn more about how to use them, see
|
|
137
|
+
[this page](https://loopback.io/doc/en/lb4/Setting-debug-strings.html).
|
|
138
|
+
|
|
139
|
+
<table>
|
|
140
|
+
<tbody>
|
|
141
|
+
<tr>
|
|
142
|
+
<th>String</th>
|
|
143
|
+
<th>Description</th>
|
|
144
|
+
</tr>
|
|
145
|
+
<tr>
|
|
146
|
+
<th colspan="2">Datasource</th>
|
|
147
|
+
</tr>
|
|
148
|
+
<tr>
|
|
149
|
+
<td>loopback:sequelize:datasource</td>
|
|
150
|
+
<td>Database Connections logs</td>
|
|
151
|
+
</tr>
|
|
152
|
+
<tr>
|
|
153
|
+
<td>loopback:sequelize:queries</td>
|
|
154
|
+
<td>Logs Executed SQL Queries and Parameters</td>
|
|
155
|
+
</tr>
|
|
156
|
+
<tr>
|
|
157
|
+
<th colspan="2">Repository</th>
|
|
158
|
+
</tr>
|
|
159
|
+
<tr>
|
|
160
|
+
<td>loopback:sequelize:modelbuilder</td>
|
|
161
|
+
<td>Logs Translation of Loopback Models Into Sequelize Supported Definitions. Helpful When Debugging Datatype Issues</td>
|
|
162
|
+
</tr>
|
|
163
|
+
</tbody>
|
|
164
|
+
</table>
|
|
165
|
+
|
|
166
|
+
## Limitations
|
|
167
|
+
|
|
168
|
+
Please note, the current implementation does not support the following:
|
|
169
|
+
|
|
170
|
+
1. SQL Transactions.
|
|
171
|
+
2. Loopback Migrations (via default `migrate.ts`). Though you're good if using
|
|
172
|
+
external packages like
|
|
173
|
+
[`db-migrate`](https://www.npmjs.com/package/db-migrate).
|
|
174
|
+
3. Connection Pooling is not implemented yet.
|
|
175
|
+
|
|
176
|
+
Community contribution is welcome.
|
|
177
|
+
|
|
178
|
+
## Contributions
|
|
179
|
+
|
|
180
|
+
- [Guidelines](https://github.com/loopbackio/loopback-next/blob/master/docs/CONTRIBUTING.md)
|
|
181
|
+
- [Join the team](https://github.com/loopbackio/loopback-next/issues/110)
|
|
182
|
+
|
|
183
|
+
## Tests
|
|
184
|
+
|
|
185
|
+
Run `npm test` from the root folder.
|
|
186
|
+
|
|
187
|
+
## Contributors
|
|
188
|
+
|
|
189
|
+
See
|
|
190
|
+
[all contributors](https://github.com/loopbackio/loopback-next/graphs/contributors).
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
[MIT](https://github.com/loopbackio/loopback-next/blob/master/LICENSE)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SequelizeSandboxApplication = void 0;
|
|
4
|
+
const boot_1 = require("@loopback/boot");
|
|
5
|
+
const repository_1 = require("@loopback/repository");
|
|
6
|
+
const rest_1 = require("@loopback/rest");
|
|
7
|
+
class SequelizeSandboxApplication extends (0, boot_1.BootMixin)((0, repository_1.RepositoryMixin)(rest_1.RestApplication)) {
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
super(options);
|
|
10
|
+
this.projectRoot = __dirname;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.SequelizeSandboxApplication = SequelizeSandboxApplication;
|
|
14
|
+
//# sourceMappingURL=application.js.map
|
|
15
|
+
//# sourceMappingURL=/Users/dianalau/code/loopback/loopback-next/extensions/sequelize/dist/__tests__/fixtures/application.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BookCategoryController = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const repository_1 = require("@loopback/repository");
|
|
6
|
+
const rest_1 = require("@loopback/rest");
|
|
7
|
+
const models_1 = require("../models");
|
|
8
|
+
const repositories_1 = require("../repositories");
|
|
9
|
+
let BookCategoryController = class BookCategoryController {
|
|
10
|
+
constructor(bookRepository) {
|
|
11
|
+
this.bookRepository = bookRepository;
|
|
12
|
+
}
|
|
13
|
+
async getCategory(id) {
|
|
14
|
+
return this.bookRepository.category(id);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
tslib_1.__decorate([
|
|
18
|
+
(0, rest_1.get)('/books/{id}/category', {
|
|
19
|
+
responses: {
|
|
20
|
+
'200': {
|
|
21
|
+
description: 'Category belonging to Book',
|
|
22
|
+
content: {
|
|
23
|
+
'application/json': {
|
|
24
|
+
schema: { type: 'array', items: (0, rest_1.getModelSchemaRef)(models_1.Category) },
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
tslib_1.__param(0, rest_1.param.path.number('id')),
|
|
31
|
+
tslib_1.__metadata("design:type", Function),
|
|
32
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
33
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
34
|
+
], BookCategoryController.prototype, "getCategory", null);
|
|
35
|
+
BookCategoryController = tslib_1.__decorate([
|
|
36
|
+
tslib_1.__param(0, (0, repository_1.repository)(repositories_1.BookRepository)),
|
|
37
|
+
tslib_1.__metadata("design:paramtypes", [repositories_1.BookRepository])
|
|
38
|
+
], BookCategoryController);
|
|
39
|
+
exports.BookCategoryController = BookCategoryController;
|
|
40
|
+
//# sourceMappingURL=book-category.controller.js.map
|
|
41
|
+
//# sourceMappingURL=/Users/dianalau/code/loopback/loopback-next/extensions/sequelize/dist/__tests__/fixtures/controllers/book-category.controller.js.map
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BookController = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const repository_1 = require("@loopback/repository");
|
|
6
|
+
const rest_1 = require("@loopback/rest");
|
|
7
|
+
const models_1 = require("../models");
|
|
8
|
+
const repositories_1 = require("../repositories");
|
|
9
|
+
const test_controller_base_1 = require("./test.controller.base");
|
|
10
|
+
let BookController = class BookController extends test_controller_base_1.TestControllerBase {
|
|
11
|
+
constructor(bookRepository) {
|
|
12
|
+
super(bookRepository);
|
|
13
|
+
this.bookRepository = bookRepository;
|
|
14
|
+
}
|
|
15
|
+
async create(book) {
|
|
16
|
+
return this.bookRepository.create(book);
|
|
17
|
+
}
|
|
18
|
+
async createAll(books) {
|
|
19
|
+
return this.bookRepository.createAll(books);
|
|
20
|
+
}
|
|
21
|
+
async count(where) {
|
|
22
|
+
return this.bookRepository.count(where);
|
|
23
|
+
}
|
|
24
|
+
async find(filter) {
|
|
25
|
+
return this.bookRepository.find(filter);
|
|
26
|
+
}
|
|
27
|
+
async updateAll(book, where) {
|
|
28
|
+
return this.bookRepository.updateAll(book, where);
|
|
29
|
+
}
|
|
30
|
+
async findById(id, filter) {
|
|
31
|
+
return this.bookRepository.findById(id, filter);
|
|
32
|
+
}
|
|
33
|
+
async updateById(id, book) {
|
|
34
|
+
await this.bookRepository.updateById(id, book);
|
|
35
|
+
}
|
|
36
|
+
async replaceById(id, book) {
|
|
37
|
+
await this.bookRepository.replaceById(id, book);
|
|
38
|
+
}
|
|
39
|
+
async deleteById(id) {
|
|
40
|
+
await this.bookRepository.deleteById(id);
|
|
41
|
+
}
|
|
42
|
+
async syncSequelizeModel() {
|
|
43
|
+
await this.beforeEach({ syncAll: true });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
tslib_1.__decorate([
|
|
47
|
+
(0, rest_1.post)('/books'),
|
|
48
|
+
(0, rest_1.response)(200, {
|
|
49
|
+
description: 'Book model instance',
|
|
50
|
+
content: { 'application/json': { schema: (0, rest_1.getModelSchemaRef)(models_1.Book) } },
|
|
51
|
+
}),
|
|
52
|
+
tslib_1.__param(0, (0, rest_1.requestBody)({
|
|
53
|
+
content: {
|
|
54
|
+
'application/json': {
|
|
55
|
+
schema: (0, rest_1.getModelSchemaRef)(models_1.Book, {
|
|
56
|
+
title: 'NewBook',
|
|
57
|
+
exclude: ['id'],
|
|
58
|
+
}),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
})),
|
|
62
|
+
tslib_1.__metadata("design:type", Function),
|
|
63
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
64
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
65
|
+
], BookController.prototype, "create", null);
|
|
66
|
+
tslib_1.__decorate([
|
|
67
|
+
(0, rest_1.post)('/books-bulk'),
|
|
68
|
+
(0, rest_1.response)(200, {
|
|
69
|
+
description: 'Book model instances',
|
|
70
|
+
content: {
|
|
71
|
+
'application/json': {
|
|
72
|
+
schema: {
|
|
73
|
+
type: 'array',
|
|
74
|
+
items: (0, rest_1.getModelSchemaRef)(models_1.Book),
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
tslib_1.__param(0, (0, rest_1.requestBody)({
|
|
80
|
+
content: {
|
|
81
|
+
'application/json': {
|
|
82
|
+
schema: {
|
|
83
|
+
type: 'array',
|
|
84
|
+
items: (0, rest_1.getModelSchemaRef)(models_1.Book, {
|
|
85
|
+
title: 'NewBook',
|
|
86
|
+
exclude: ['id'],
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
})),
|
|
92
|
+
tslib_1.__metadata("design:type", Function),
|
|
93
|
+
tslib_1.__metadata("design:paramtypes", [Array]),
|
|
94
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
95
|
+
], BookController.prototype, "createAll", null);
|
|
96
|
+
tslib_1.__decorate([
|
|
97
|
+
(0, rest_1.get)('/books/count'),
|
|
98
|
+
(0, rest_1.response)(200, {
|
|
99
|
+
description: 'Book model count',
|
|
100
|
+
content: { 'application/json': { schema: repository_1.CountSchema } },
|
|
101
|
+
}),
|
|
102
|
+
tslib_1.__param(0, rest_1.param.where(models_1.Book)),
|
|
103
|
+
tslib_1.__metadata("design:type", Function),
|
|
104
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
105
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
106
|
+
], BookController.prototype, "count", null);
|
|
107
|
+
tslib_1.__decorate([
|
|
108
|
+
(0, rest_1.get)('/books'),
|
|
109
|
+
(0, rest_1.response)(200, {
|
|
110
|
+
description: 'Array of Book model instances',
|
|
111
|
+
content: {
|
|
112
|
+
'application/json': {
|
|
113
|
+
schema: {
|
|
114
|
+
type: 'array',
|
|
115
|
+
items: (0, rest_1.getModelSchemaRef)(models_1.Book, { includeRelations: true }),
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
tslib_1.__param(0, rest_1.param.filter(models_1.Book)),
|
|
121
|
+
tslib_1.__metadata("design:type", Function),
|
|
122
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
123
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
124
|
+
], BookController.prototype, "find", null);
|
|
125
|
+
tslib_1.__decorate([
|
|
126
|
+
(0, rest_1.patch)('/books'),
|
|
127
|
+
(0, rest_1.response)(200, {
|
|
128
|
+
description: 'Book PATCH success count',
|
|
129
|
+
content: { 'application/json': { schema: repository_1.CountSchema } },
|
|
130
|
+
}),
|
|
131
|
+
tslib_1.__param(0, (0, rest_1.requestBody)({
|
|
132
|
+
content: {
|
|
133
|
+
'application/json': {
|
|
134
|
+
schema: (0, rest_1.getModelSchemaRef)(models_1.Book, { partial: true }),
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
})),
|
|
138
|
+
tslib_1.__param(1, rest_1.param.where(models_1.Book)),
|
|
139
|
+
tslib_1.__metadata("design:type", Function),
|
|
140
|
+
tslib_1.__metadata("design:paramtypes", [models_1.Book, Object]),
|
|
141
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
142
|
+
], BookController.prototype, "updateAll", null);
|
|
143
|
+
tslib_1.__decorate([
|
|
144
|
+
(0, rest_1.get)('/books/{id}'),
|
|
145
|
+
(0, rest_1.response)(200, {
|
|
146
|
+
description: 'Book model instance',
|
|
147
|
+
content: {
|
|
148
|
+
'application/json': {
|
|
149
|
+
schema: (0, rest_1.getModelSchemaRef)(models_1.Book, { includeRelations: true }),
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
}),
|
|
153
|
+
tslib_1.__param(0, rest_1.param.path.number('id')),
|
|
154
|
+
tslib_1.__param(1, rest_1.param.filter(models_1.Book, { exclude: 'where' })),
|
|
155
|
+
tslib_1.__metadata("design:type", Function),
|
|
156
|
+
tslib_1.__metadata("design:paramtypes", [Number, Object]),
|
|
157
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
158
|
+
], BookController.prototype, "findById", null);
|
|
159
|
+
tslib_1.__decorate([
|
|
160
|
+
(0, rest_1.patch)('/books/{id}'),
|
|
161
|
+
(0, rest_1.response)(204, {
|
|
162
|
+
description: 'Book PATCH success',
|
|
163
|
+
}),
|
|
164
|
+
tslib_1.__param(0, rest_1.param.path.number('id')),
|
|
165
|
+
tslib_1.__param(1, (0, rest_1.requestBody)({
|
|
166
|
+
content: {
|
|
167
|
+
'application/json': {
|
|
168
|
+
schema: (0, rest_1.getModelSchemaRef)(models_1.Book, { partial: true }),
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
})),
|
|
172
|
+
tslib_1.__metadata("design:type", Function),
|
|
173
|
+
tslib_1.__metadata("design:paramtypes", [Number, models_1.Book]),
|
|
174
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
175
|
+
], BookController.prototype, "updateById", null);
|
|
176
|
+
tslib_1.__decorate([
|
|
177
|
+
(0, rest_1.put)('/books/{id}'),
|
|
178
|
+
(0, rest_1.response)(204, {
|
|
179
|
+
description: 'Book PUT success',
|
|
180
|
+
}),
|
|
181
|
+
tslib_1.__param(0, rest_1.param.path.number('id')),
|
|
182
|
+
tslib_1.__param(1, (0, rest_1.requestBody)()),
|
|
183
|
+
tslib_1.__metadata("design:type", Function),
|
|
184
|
+
tslib_1.__metadata("design:paramtypes", [Number, models_1.Book]),
|
|
185
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
186
|
+
], BookController.prototype, "replaceById", null);
|
|
187
|
+
tslib_1.__decorate([
|
|
188
|
+
(0, rest_1.del)('/books/{id}'),
|
|
189
|
+
(0, rest_1.response)(204, {
|
|
190
|
+
description: 'Book DELETE success',
|
|
191
|
+
}),
|
|
192
|
+
tslib_1.__param(0, rest_1.param.path.number('id')),
|
|
193
|
+
tslib_1.__metadata("design:type", Function),
|
|
194
|
+
tslib_1.__metadata("design:paramtypes", [Number]),
|
|
195
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
196
|
+
], BookController.prototype, "deleteById", null);
|
|
197
|
+
tslib_1.__decorate([
|
|
198
|
+
(0, rest_1.get)('/books/sync-sequelize-model'),
|
|
199
|
+
(0, rest_1.response)(200),
|
|
200
|
+
tslib_1.__metadata("design:type", Function),
|
|
201
|
+
tslib_1.__metadata("design:paramtypes", []),
|
|
202
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
203
|
+
], BookController.prototype, "syncSequelizeModel", null);
|
|
204
|
+
BookController = tslib_1.__decorate([
|
|
205
|
+
tslib_1.__param(0, (0, repository_1.repository)(repositories_1.BookRepository)),
|
|
206
|
+
tslib_1.__metadata("design:paramtypes", [repositories_1.BookRepository])
|
|
207
|
+
], BookController);
|
|
208
|
+
exports.BookController = BookController;
|
|
209
|
+
//# sourceMappingURL=book.controller.js.map
|
|
210
|
+
//# sourceMappingURL=/Users/dianalau/code/loopback/loopback-next/extensions/sequelize/dist/__tests__/fixtures/controllers/book.controller.js.map
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CategoryController = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const repository_1 = require("@loopback/repository");
|
|
6
|
+
const rest_1 = require("@loopback/rest");
|
|
7
|
+
const models_1 = require("../models");
|
|
8
|
+
const repositories_1 = require("../repositories");
|
|
9
|
+
let CategoryController = class CategoryController {
|
|
10
|
+
constructor(categoryRepository) {
|
|
11
|
+
this.categoryRepository = categoryRepository;
|
|
12
|
+
}
|
|
13
|
+
async create(category) {
|
|
14
|
+
return this.categoryRepository.create(category);
|
|
15
|
+
}
|
|
16
|
+
async createAll(categories) {
|
|
17
|
+
return this.categoryRepository.createAll(categories);
|
|
18
|
+
}
|
|
19
|
+
async count(where) {
|
|
20
|
+
return this.categoryRepository.count(where);
|
|
21
|
+
}
|
|
22
|
+
async find(filter) {
|
|
23
|
+
return this.categoryRepository.find(filter);
|
|
24
|
+
}
|
|
25
|
+
async updateAll(category, where) {
|
|
26
|
+
return this.categoryRepository.updateAll(category, where);
|
|
27
|
+
}
|
|
28
|
+
async findById(id, filter) {
|
|
29
|
+
return this.categoryRepository.findById(id, filter);
|
|
30
|
+
}
|
|
31
|
+
async updateById(id, category) {
|
|
32
|
+
await this.categoryRepository.updateById(id, category);
|
|
33
|
+
}
|
|
34
|
+
async replaceById(id, category) {
|
|
35
|
+
await this.categoryRepository.replaceById(id, category);
|
|
36
|
+
}
|
|
37
|
+
async deleteById(id) {
|
|
38
|
+
await this.categoryRepository.deleteById(id);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
tslib_1.__decorate([
|
|
42
|
+
(0, rest_1.post)('/categories'),
|
|
43
|
+
(0, rest_1.response)(200, {
|
|
44
|
+
description: 'Category model instance',
|
|
45
|
+
content: { 'application/json': { schema: (0, rest_1.getModelSchemaRef)(models_1.Category) } },
|
|
46
|
+
}),
|
|
47
|
+
tslib_1.__param(0, (0, rest_1.requestBody)({
|
|
48
|
+
content: {
|
|
49
|
+
'application/json': {
|
|
50
|
+
schema: (0, rest_1.getModelSchemaRef)(models_1.Category, {
|
|
51
|
+
title: 'NewCategory',
|
|
52
|
+
exclude: ['id'],
|
|
53
|
+
}),
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
})),
|
|
57
|
+
tslib_1.__metadata("design:type", Function),
|
|
58
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
59
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
60
|
+
], CategoryController.prototype, "create", null);
|
|
61
|
+
tslib_1.__decorate([
|
|
62
|
+
(0, rest_1.post)('/categories-bulk'),
|
|
63
|
+
(0, rest_1.response)(200, {
|
|
64
|
+
description: 'Category model instances',
|
|
65
|
+
content: {
|
|
66
|
+
'application/json': {
|
|
67
|
+
schema: {
|
|
68
|
+
type: 'array',
|
|
69
|
+
items: (0, rest_1.getModelSchemaRef)(models_1.Category),
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
tslib_1.__param(0, (0, rest_1.requestBody)({
|
|
75
|
+
content: {
|
|
76
|
+
'application/json': {
|
|
77
|
+
schema: {
|
|
78
|
+
type: 'array',
|
|
79
|
+
items: (0, rest_1.getModelSchemaRef)(models_1.Category, {
|
|
80
|
+
title: 'NewCategory',
|
|
81
|
+
exclude: ['id'],
|
|
82
|
+
}),
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
})),
|
|
87
|
+
tslib_1.__metadata("design:type", Function),
|
|
88
|
+
tslib_1.__metadata("design:paramtypes", [Array]),
|
|
89
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
90
|
+
], CategoryController.prototype, "createAll", null);
|
|
91
|
+
tslib_1.__decorate([
|
|
92
|
+
(0, rest_1.get)('/categories/count'),
|
|
93
|
+
(0, rest_1.response)(200, {
|
|
94
|
+
description: 'Category model count',
|
|
95
|
+
content: { 'application/json': { schema: repository_1.CountSchema } },
|
|
96
|
+
}),
|
|
97
|
+
tslib_1.__param(0, rest_1.param.where(models_1.Category)),
|
|
98
|
+
tslib_1.__metadata("design:type", Function),
|
|
99
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
100
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
101
|
+
], CategoryController.prototype, "count", null);
|
|
102
|
+
tslib_1.__decorate([
|
|
103
|
+
(0, rest_1.get)('/categories'),
|
|
104
|
+
(0, rest_1.response)(200, {
|
|
105
|
+
description: 'Array of Category model instances',
|
|
106
|
+
content: {
|
|
107
|
+
'application/json': {
|
|
108
|
+
schema: {
|
|
109
|
+
type: 'array',
|
|
110
|
+
items: (0, rest_1.getModelSchemaRef)(models_1.Category, { includeRelations: true }),
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
}),
|
|
115
|
+
tslib_1.__param(0, rest_1.param.filter(models_1.Category)),
|
|
116
|
+
tslib_1.__metadata("design:type", Function),
|
|
117
|
+
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
118
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
119
|
+
], CategoryController.prototype, "find", null);
|
|
120
|
+
tslib_1.__decorate([
|
|
121
|
+
(0, rest_1.patch)('/categories'),
|
|
122
|
+
(0, rest_1.response)(200, {
|
|
123
|
+
description: 'Category PATCH success count',
|
|
124
|
+
content: { 'application/json': { schema: repository_1.CountSchema } },
|
|
125
|
+
}),
|
|
126
|
+
tslib_1.__param(0, (0, rest_1.requestBody)({
|
|
127
|
+
content: {
|
|
128
|
+
'application/json': {
|
|
129
|
+
schema: (0, rest_1.getModelSchemaRef)(models_1.Category, { partial: true }),
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
})),
|
|
133
|
+
tslib_1.__param(1, rest_1.param.where(models_1.Category)),
|
|
134
|
+
tslib_1.__metadata("design:type", Function),
|
|
135
|
+
tslib_1.__metadata("design:paramtypes", [models_1.Category, Object]),
|
|
136
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
137
|
+
], CategoryController.prototype, "updateAll", null);
|
|
138
|
+
tslib_1.__decorate([
|
|
139
|
+
(0, rest_1.get)('/categories/{id}'),
|
|
140
|
+
(0, rest_1.response)(200, {
|
|
141
|
+
description: 'Category model instance',
|
|
142
|
+
content: {
|
|
143
|
+
'application/json': {
|
|
144
|
+
schema: (0, rest_1.getModelSchemaRef)(models_1.Category, { includeRelations: true }),
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
}),
|
|
148
|
+
tslib_1.__param(0, rest_1.param.path.number('id')),
|
|
149
|
+
tslib_1.__param(1, rest_1.param.filter(models_1.Category, { exclude: 'where' })),
|
|
150
|
+
tslib_1.__metadata("design:type", Function),
|
|
151
|
+
tslib_1.__metadata("design:paramtypes", [Number, Object]),
|
|
152
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
153
|
+
], CategoryController.prototype, "findById", null);
|
|
154
|
+
tslib_1.__decorate([
|
|
155
|
+
(0, rest_1.patch)('/categories/{id}'),
|
|
156
|
+
(0, rest_1.response)(204, {
|
|
157
|
+
description: 'Category PATCH success',
|
|
158
|
+
}),
|
|
159
|
+
tslib_1.__param(0, rest_1.param.path.number('id')),
|
|
160
|
+
tslib_1.__param(1, (0, rest_1.requestBody)({
|
|
161
|
+
content: {
|
|
162
|
+
'application/json': {
|
|
163
|
+
schema: (0, rest_1.getModelSchemaRef)(models_1.Category, { partial: true }),
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
})),
|
|
167
|
+
tslib_1.__metadata("design:type", Function),
|
|
168
|
+
tslib_1.__metadata("design:paramtypes", [Number, models_1.Category]),
|
|
169
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
170
|
+
], CategoryController.prototype, "updateById", null);
|
|
171
|
+
tslib_1.__decorate([
|
|
172
|
+
(0, rest_1.put)('/categories/{id}'),
|
|
173
|
+
(0, rest_1.response)(204, {
|
|
174
|
+
description: 'Category PUT success',
|
|
175
|
+
}),
|
|
176
|
+
tslib_1.__param(0, rest_1.param.path.number('id')),
|
|
177
|
+
tslib_1.__param(1, (0, rest_1.requestBody)()),
|
|
178
|
+
tslib_1.__metadata("design:type", Function),
|
|
179
|
+
tslib_1.__metadata("design:paramtypes", [Number, models_1.Category]),
|
|
180
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
181
|
+
], CategoryController.prototype, "replaceById", null);
|
|
182
|
+
tslib_1.__decorate([
|
|
183
|
+
(0, rest_1.del)('/categories/{id}'),
|
|
184
|
+
(0, rest_1.response)(204, {
|
|
185
|
+
description: 'Category DELETE success',
|
|
186
|
+
}),
|
|
187
|
+
tslib_1.__param(0, rest_1.param.path.number('id')),
|
|
188
|
+
tslib_1.__metadata("design:type", Function),
|
|
189
|
+
tslib_1.__metadata("design:paramtypes", [Number]),
|
|
190
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
191
|
+
], CategoryController.prototype, "deleteById", null);
|
|
192
|
+
CategoryController = tslib_1.__decorate([
|
|
193
|
+
tslib_1.__param(0, (0, repository_1.repository)(repositories_1.CategoryRepository)),
|
|
194
|
+
tslib_1.__metadata("design:paramtypes", [repositories_1.CategoryRepository])
|
|
195
|
+
], CategoryController);
|
|
196
|
+
exports.CategoryController = CategoryController;
|
|
197
|
+
//# sourceMappingURL=category.controller.js.map
|
|
198
|
+
//# sourceMappingURL=/Users/dianalau/code/loopback/loopback-next/extensions/sequelize/dist/__tests__/fixtures/controllers/category.controller.js.map
|