@loopback/sequelize 0.4.0 → 0.5.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.
Files changed (54) hide show
  1. package/dist/.sandbox/40627f10KYa/application.js +15 -0
  2. package/dist/.sandbox/40627f10KYa/controllers/book-category.controller.js +40 -0
  3. package/dist/.sandbox/40627f10KYa/controllers/book.controller.js +209 -0
  4. package/dist/.sandbox/40627f10KYa/controllers/category.controller.js +197 -0
  5. package/dist/.sandbox/40627f10KYa/controllers/developer.controller.js +176 -0
  6. package/dist/.sandbox/40627f10KYa/controllers/doctor-patient.controller.js +111 -0
  7. package/dist/.sandbox/40627f10KYa/controllers/doctor.controller.js +176 -0
  8. package/dist/.sandbox/40627f10KYa/controllers/index.js +23 -0
  9. package/dist/.sandbox/40627f10KYa/controllers/patient.controller.js +164 -0
  10. package/dist/.sandbox/40627f10KYa/controllers/product.controller.js +176 -0
  11. package/dist/.sandbox/40627f10KYa/controllers/programming-languange.controller.js +203 -0
  12. package/dist/.sandbox/40627f10KYa/controllers/task.controller.js +209 -0
  13. package/dist/.sandbox/40627f10KYa/controllers/test.controller.base.js +27 -0
  14. package/dist/.sandbox/40627f10KYa/controllers/todo-list-todo.controller.js +112 -0
  15. package/dist/.sandbox/40627f10KYa/controllers/todo-list.controller.js +176 -0
  16. package/dist/.sandbox/40627f10KYa/controllers/todo-todo-list.controller.js +40 -0
  17. package/dist/.sandbox/40627f10KYa/controllers/todo.controller.js +176 -0
  18. package/dist/.sandbox/40627f10KYa/controllers/transaction.controller.js +156 -0
  19. package/dist/.sandbox/40627f10KYa/controllers/user-todo-list.controller.js +112 -0
  20. package/dist/.sandbox/40627f10KYa/controllers/user.controller.js +209 -0
  21. package/dist/.sandbox/40627f10KYa/datasources/config.js +65 -0
  22. package/dist/.sandbox/40627f10KYa/datasources/primary.datasource.js +27 -0
  23. package/dist/.sandbox/40627f10KYa/datasources/secondary.datasource.js +27 -0
  24. package/dist/.sandbox/40627f10KYa/models/appointment.model.js +36 -0
  25. package/dist/.sandbox/40627f10KYa/models/book.model.js +47 -0
  26. package/dist/.sandbox/40627f10KYa/models/category.model.js +31 -0
  27. package/dist/.sandbox/40627f10KYa/models/developer.model.js +46 -0
  28. package/dist/.sandbox/40627f10KYa/models/doctor.model.js +43 -0
  29. package/dist/.sandbox/40627f10KYa/models/index.js +17 -0
  30. package/dist/.sandbox/40627f10KYa/models/patient.model.js +31 -0
  31. package/dist/.sandbox/40627f10KYa/models/product.model.js +40 -0
  32. package/dist/.sandbox/40627f10KYa/models/programming-language.model.js +38 -0
  33. package/dist/.sandbox/40627f10KYa/models/task.model.js +73 -0
  34. package/dist/.sandbox/40627f10KYa/models/todo-list.model.js +44 -0
  35. package/dist/.sandbox/40627f10KYa/models/todo.model.js +43 -0
  36. package/dist/.sandbox/40627f10KYa/models/user.model.js +90 -0
  37. package/dist/.sandbox/40627f10KYa/repositories/appointment.repository.js +19 -0
  38. package/dist/.sandbox/40627f10KYa/repositories/book.repository.js +24 -0
  39. package/dist/.sandbox/40627f10KYa/repositories/category.repository.js +19 -0
  40. package/dist/.sandbox/40627f10KYa/repositories/developer.repository.js +24 -0
  41. package/dist/.sandbox/40627f10KYa/repositories/doctor.repository.js +26 -0
  42. package/dist/.sandbox/40627f10KYa/repositories/index.js +17 -0
  43. package/dist/.sandbox/40627f10KYa/repositories/patient.repository.js +19 -0
  44. package/dist/.sandbox/40627f10KYa/repositories/product.repository.js +19 -0
  45. package/dist/.sandbox/40627f10KYa/repositories/programming-language.repository.js +19 -0
  46. package/dist/.sandbox/40627f10KYa/repositories/task.repository.js +25 -0
  47. package/dist/.sandbox/40627f10KYa/repositories/todo-list.repository.js +24 -0
  48. package/dist/.sandbox/40627f10KYa/repositories/todo.repository.js +24 -0
  49. package/dist/.sandbox/40627f10KYa/repositories/user.repository.js +24 -0
  50. package/dist/sequelize/sequelize.repository.base.d.ts +11 -0
  51. package/dist/sequelize/sequelize.repository.base.js +30 -3
  52. package/dist/sequelize/sequelize.repository.base.js.map +1 -1
  53. package/package.json +10 -10
  54. package/src/sequelize/sequelize.repository.base.ts +34 -3
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TodoListController = 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 TodoListController = exports.TodoListController = class TodoListController extends test_controller_base_1.TestControllerBase {
11
+ constructor(todoListRepository) {
12
+ super(todoListRepository);
13
+ this.todoListRepository = todoListRepository;
14
+ }
15
+ async create(todoList) {
16
+ return this.todoListRepository.create(todoList);
17
+ }
18
+ async count(where) {
19
+ return this.todoListRepository.count(where);
20
+ }
21
+ async find(filter) {
22
+ return this.todoListRepository.find(filter);
23
+ }
24
+ async updateAll(todoList, where) {
25
+ return this.todoListRepository.updateAll(todoList, where);
26
+ }
27
+ async findById(id, filter) {
28
+ return this.todoListRepository.findById(id, filter);
29
+ }
30
+ async updateById(id, todoList) {
31
+ await this.todoListRepository.updateById(id, todoList);
32
+ }
33
+ async replaceById(id, todoList) {
34
+ await this.todoListRepository.replaceById(id, todoList);
35
+ }
36
+ async deleteById(id) {
37
+ await this.todoListRepository.deleteById(id);
38
+ }
39
+ async syncSequelizeModel() {
40
+ await this.beforeEach({ syncAll: true });
41
+ }
42
+ };
43
+ tslib_1.__decorate([
44
+ (0, rest_1.post)('/todo-lists'),
45
+ (0, rest_1.response)(200, {
46
+ description: 'TodoList model instance',
47
+ content: { 'application/json': { schema: (0, rest_1.getModelSchemaRef)(models_1.TodoList) } },
48
+ }),
49
+ tslib_1.__param(0, (0, rest_1.requestBody)({
50
+ content: {
51
+ 'application/json': {
52
+ schema: (0, rest_1.getModelSchemaRef)(models_1.TodoList, {
53
+ title: 'NewTodoList',
54
+ exclude: ['id'],
55
+ }),
56
+ },
57
+ },
58
+ })),
59
+ tslib_1.__metadata("design:type", Function),
60
+ tslib_1.__metadata("design:paramtypes", [Object]),
61
+ tslib_1.__metadata("design:returntype", Promise)
62
+ ], TodoListController.prototype, "create", null);
63
+ tslib_1.__decorate([
64
+ (0, rest_1.get)('/todo-lists/count'),
65
+ (0, rest_1.response)(200, {
66
+ description: 'TodoList model count',
67
+ content: { 'application/json': { schema: repository_1.CountSchema } },
68
+ }),
69
+ tslib_1.__param(0, rest_1.param.where(models_1.TodoList)),
70
+ tslib_1.__metadata("design:type", Function),
71
+ tslib_1.__metadata("design:paramtypes", [Object]),
72
+ tslib_1.__metadata("design:returntype", Promise)
73
+ ], TodoListController.prototype, "count", null);
74
+ tslib_1.__decorate([
75
+ (0, rest_1.get)('/todo-lists'),
76
+ (0, rest_1.response)(200, {
77
+ description: 'Array of TodoList model instances',
78
+ content: {
79
+ 'application/json': {
80
+ schema: {
81
+ type: 'array',
82
+ items: (0, rest_1.getModelSchemaRef)(models_1.TodoList, { includeRelations: true }),
83
+ },
84
+ },
85
+ },
86
+ }),
87
+ tslib_1.__param(0, rest_1.param.filter(models_1.TodoList)),
88
+ tslib_1.__metadata("design:type", Function),
89
+ tslib_1.__metadata("design:paramtypes", [Object]),
90
+ tslib_1.__metadata("design:returntype", Promise)
91
+ ], TodoListController.prototype, "find", null);
92
+ tslib_1.__decorate([
93
+ (0, rest_1.patch)('/todo-lists'),
94
+ (0, rest_1.response)(200, {
95
+ description: 'TodoList PATCH success count',
96
+ content: { 'application/json': { schema: repository_1.CountSchema } },
97
+ }),
98
+ tslib_1.__param(0, (0, rest_1.requestBody)({
99
+ content: {
100
+ 'application/json': {
101
+ schema: (0, rest_1.getModelSchemaRef)(models_1.TodoList, { partial: true }),
102
+ },
103
+ },
104
+ })),
105
+ tslib_1.__param(1, rest_1.param.where(models_1.TodoList)),
106
+ tslib_1.__metadata("design:type", Function),
107
+ tslib_1.__metadata("design:paramtypes", [models_1.TodoList, Object]),
108
+ tslib_1.__metadata("design:returntype", Promise)
109
+ ], TodoListController.prototype, "updateAll", null);
110
+ tslib_1.__decorate([
111
+ (0, rest_1.get)('/todo-lists/{id}'),
112
+ (0, rest_1.response)(200, {
113
+ description: 'TodoList model instance',
114
+ content: {
115
+ 'application/json': {
116
+ schema: (0, rest_1.getModelSchemaRef)(models_1.TodoList, { includeRelations: true }),
117
+ },
118
+ },
119
+ }),
120
+ tslib_1.__param(0, rest_1.param.path.number('id')),
121
+ tslib_1.__param(1, rest_1.param.filter(models_1.TodoList, { exclude: 'where' })),
122
+ tslib_1.__metadata("design:type", Function),
123
+ tslib_1.__metadata("design:paramtypes", [Number, Object]),
124
+ tslib_1.__metadata("design:returntype", Promise)
125
+ ], TodoListController.prototype, "findById", null);
126
+ tslib_1.__decorate([
127
+ (0, rest_1.patch)('/todo-lists/{id}'),
128
+ (0, rest_1.response)(204, {
129
+ description: 'TodoList PATCH success',
130
+ }),
131
+ tslib_1.__param(0, rest_1.param.path.number('id')),
132
+ tslib_1.__param(1, (0, rest_1.requestBody)({
133
+ content: {
134
+ 'application/json': {
135
+ schema: (0, rest_1.getModelSchemaRef)(models_1.TodoList, { partial: true }),
136
+ },
137
+ },
138
+ })),
139
+ tslib_1.__metadata("design:type", Function),
140
+ tslib_1.__metadata("design:paramtypes", [Number, models_1.TodoList]),
141
+ tslib_1.__metadata("design:returntype", Promise)
142
+ ], TodoListController.prototype, "updateById", null);
143
+ tslib_1.__decorate([
144
+ (0, rest_1.put)('/todo-lists/{id}'),
145
+ (0, rest_1.response)(204, {
146
+ description: 'TodoList PUT success',
147
+ }),
148
+ tslib_1.__param(0, rest_1.param.path.number('id')),
149
+ tslib_1.__param(1, (0, rest_1.requestBody)()),
150
+ tslib_1.__metadata("design:type", Function),
151
+ tslib_1.__metadata("design:paramtypes", [Number, models_1.TodoList]),
152
+ tslib_1.__metadata("design:returntype", Promise)
153
+ ], TodoListController.prototype, "replaceById", null);
154
+ tslib_1.__decorate([
155
+ (0, rest_1.del)('/todo-lists/{id}'),
156
+ (0, rest_1.response)(204, {
157
+ description: 'TodoList DELETE success',
158
+ }),
159
+ tslib_1.__param(0, rest_1.param.path.number('id')),
160
+ tslib_1.__metadata("design:type", Function),
161
+ tslib_1.__metadata("design:paramtypes", [Number]),
162
+ tslib_1.__metadata("design:returntype", Promise)
163
+ ], TodoListController.prototype, "deleteById", null);
164
+ tslib_1.__decorate([
165
+ (0, rest_1.get)('/todo-lists/sync-sequelize-model'),
166
+ (0, rest_1.response)(200),
167
+ tslib_1.__metadata("design:type", Function),
168
+ tslib_1.__metadata("design:paramtypes", []),
169
+ tslib_1.__metadata("design:returntype", Promise)
170
+ ], TodoListController.prototype, "syncSequelizeModel", null);
171
+ exports.TodoListController = TodoListController = tslib_1.__decorate([
172
+ tslib_1.__param(0, (0, repository_1.repository)(repositories_1.TodoListRepository)),
173
+ tslib_1.__metadata("design:paramtypes", [repositories_1.TodoListRepository])
174
+ ], TodoListController);
175
+ //# sourceMappingURL=todo-list.controller.js.map
176
+ //# sourceMappingURL=/Users/dianalau/code/loopback/loopback-next/extensions/sequelize/dist/__tests__/fixtures/controllers/todo-list.controller.js.map
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TodoTodoListController = 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 TodoTodoListController = exports.TodoTodoListController = class TodoTodoListController {
10
+ constructor(todoRepository) {
11
+ this.todoRepository = todoRepository;
12
+ }
13
+ async getTodoList(id) {
14
+ return this.todoRepository.todoList(id);
15
+ }
16
+ };
17
+ tslib_1.__decorate([
18
+ (0, rest_1.get)('/todos/{id}/todo-list', {
19
+ responses: {
20
+ '200': {
21
+ description: 'TodoList belonging to Todo',
22
+ content: {
23
+ 'application/json': {
24
+ schema: { type: 'array', items: (0, rest_1.getModelSchemaRef)(models_1.TodoList) },
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
+ ], TodoTodoListController.prototype, "getTodoList", null);
35
+ exports.TodoTodoListController = TodoTodoListController = tslib_1.__decorate([
36
+ tslib_1.__param(0, (0, repository_1.repository)(repositories_1.TodoRepository)),
37
+ tslib_1.__metadata("design:paramtypes", [repositories_1.TodoRepository])
38
+ ], TodoTodoListController);
39
+ //# sourceMappingURL=todo-todo-list.controller.js.map
40
+ //# sourceMappingURL=/Users/dianalau/code/loopback/loopback-next/extensions/sequelize/dist/__tests__/fixtures/controllers/todo-todo-list.controller.js.map
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TodoController = 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 TodoController = exports.TodoController = class TodoController extends test_controller_base_1.TestControllerBase {
11
+ constructor(todoRepository) {
12
+ super(todoRepository);
13
+ this.todoRepository = todoRepository;
14
+ }
15
+ async create(todo) {
16
+ return this.todoRepository.create(todo);
17
+ }
18
+ async count(where) {
19
+ return this.todoRepository.count(where);
20
+ }
21
+ async find(filter) {
22
+ return this.todoRepository.find(filter);
23
+ }
24
+ async updateAll(todo, where) {
25
+ return this.todoRepository.updateAll(todo, where);
26
+ }
27
+ async findById(id, filter) {
28
+ return this.todoRepository.findById(id, filter);
29
+ }
30
+ async updateById(id, todo) {
31
+ await this.todoRepository.updateById(id, todo);
32
+ }
33
+ async replaceById(id, todo) {
34
+ await this.todoRepository.replaceById(id, todo);
35
+ }
36
+ async deleteById(id) {
37
+ await this.todoRepository.deleteById(id);
38
+ }
39
+ async syncSequelizeModel() {
40
+ await this.beforeEach();
41
+ }
42
+ };
43
+ tslib_1.__decorate([
44
+ (0, rest_1.post)('/todos'),
45
+ (0, rest_1.response)(200, {
46
+ description: 'Todo model instance',
47
+ content: { 'application/json': { schema: (0, rest_1.getModelSchemaRef)(models_1.Todo) } },
48
+ }),
49
+ tslib_1.__param(0, (0, rest_1.requestBody)({
50
+ content: {
51
+ 'application/json': {
52
+ schema: (0, rest_1.getModelSchemaRef)(models_1.Todo, {
53
+ title: 'NewTodo',
54
+ exclude: ['id'],
55
+ }),
56
+ },
57
+ },
58
+ })),
59
+ tslib_1.__metadata("design:type", Function),
60
+ tslib_1.__metadata("design:paramtypes", [Object]),
61
+ tslib_1.__metadata("design:returntype", Promise)
62
+ ], TodoController.prototype, "create", null);
63
+ tslib_1.__decorate([
64
+ (0, rest_1.get)('/todos/count'),
65
+ (0, rest_1.response)(200, {
66
+ description: 'Todo model count',
67
+ content: { 'application/json': { schema: repository_1.CountSchema } },
68
+ }),
69
+ tslib_1.__param(0, rest_1.param.where(models_1.Todo)),
70
+ tslib_1.__metadata("design:type", Function),
71
+ tslib_1.__metadata("design:paramtypes", [Object]),
72
+ tslib_1.__metadata("design:returntype", Promise)
73
+ ], TodoController.prototype, "count", null);
74
+ tslib_1.__decorate([
75
+ (0, rest_1.get)('/todos'),
76
+ (0, rest_1.response)(200, {
77
+ description: 'Array of Todo model instances',
78
+ content: {
79
+ 'application/json': {
80
+ schema: {
81
+ type: 'array',
82
+ items: (0, rest_1.getModelSchemaRef)(models_1.Todo, { includeRelations: true }),
83
+ },
84
+ },
85
+ },
86
+ }),
87
+ tslib_1.__param(0, rest_1.param.filter(models_1.Todo)),
88
+ tslib_1.__metadata("design:type", Function),
89
+ tslib_1.__metadata("design:paramtypes", [Object]),
90
+ tslib_1.__metadata("design:returntype", Promise)
91
+ ], TodoController.prototype, "find", null);
92
+ tslib_1.__decorate([
93
+ (0, rest_1.patch)('/todos'),
94
+ (0, rest_1.response)(200, {
95
+ description: 'Todo PATCH success count',
96
+ content: { 'application/json': { schema: repository_1.CountSchema } },
97
+ }),
98
+ tslib_1.__param(0, (0, rest_1.requestBody)({
99
+ content: {
100
+ 'application/json': {
101
+ schema: (0, rest_1.getModelSchemaRef)(models_1.Todo, { partial: true }),
102
+ },
103
+ },
104
+ })),
105
+ tslib_1.__param(1, rest_1.param.where(models_1.Todo)),
106
+ tslib_1.__metadata("design:type", Function),
107
+ tslib_1.__metadata("design:paramtypes", [models_1.Todo, Object]),
108
+ tslib_1.__metadata("design:returntype", Promise)
109
+ ], TodoController.prototype, "updateAll", null);
110
+ tslib_1.__decorate([
111
+ (0, rest_1.get)('/todos/{id}'),
112
+ (0, rest_1.response)(200, {
113
+ description: 'Todo model instance',
114
+ content: {
115
+ 'application/json': {
116
+ schema: (0, rest_1.getModelSchemaRef)(models_1.Todo, { includeRelations: true }),
117
+ },
118
+ },
119
+ }),
120
+ tslib_1.__param(0, rest_1.param.path.number('id')),
121
+ tslib_1.__param(1, rest_1.param.filter(models_1.Todo, { exclude: 'where' })),
122
+ tslib_1.__metadata("design:type", Function),
123
+ tslib_1.__metadata("design:paramtypes", [Number, Object]),
124
+ tslib_1.__metadata("design:returntype", Promise)
125
+ ], TodoController.prototype, "findById", null);
126
+ tslib_1.__decorate([
127
+ (0, rest_1.patch)('/todos/{id}'),
128
+ (0, rest_1.response)(204, {
129
+ description: 'Todo PATCH success',
130
+ }),
131
+ tslib_1.__param(0, rest_1.param.path.number('id')),
132
+ tslib_1.__param(1, (0, rest_1.requestBody)({
133
+ content: {
134
+ 'application/json': {
135
+ schema: (0, rest_1.getModelSchemaRef)(models_1.Todo, { partial: true }),
136
+ },
137
+ },
138
+ })),
139
+ tslib_1.__metadata("design:type", Function),
140
+ tslib_1.__metadata("design:paramtypes", [Number, models_1.Todo]),
141
+ tslib_1.__metadata("design:returntype", Promise)
142
+ ], TodoController.prototype, "updateById", null);
143
+ tslib_1.__decorate([
144
+ (0, rest_1.put)('/todos/{id}'),
145
+ (0, rest_1.response)(204, {
146
+ description: 'Todo PUT success',
147
+ }),
148
+ tslib_1.__param(0, rest_1.param.path.number('id')),
149
+ tslib_1.__param(1, (0, rest_1.requestBody)()),
150
+ tslib_1.__metadata("design:type", Function),
151
+ tslib_1.__metadata("design:paramtypes", [Number, models_1.Todo]),
152
+ tslib_1.__metadata("design:returntype", Promise)
153
+ ], TodoController.prototype, "replaceById", null);
154
+ tslib_1.__decorate([
155
+ (0, rest_1.del)('/todos/{id}'),
156
+ (0, rest_1.response)(204, {
157
+ description: 'Todo DELETE success',
158
+ }),
159
+ tslib_1.__param(0, rest_1.param.path.number('id')),
160
+ tslib_1.__metadata("design:type", Function),
161
+ tslib_1.__metadata("design:paramtypes", [Number]),
162
+ tslib_1.__metadata("design:returntype", Promise)
163
+ ], TodoController.prototype, "deleteById", null);
164
+ tslib_1.__decorate([
165
+ (0, rest_1.get)('/todos/sync-sequelize-model'),
166
+ (0, rest_1.response)(200),
167
+ tslib_1.__metadata("design:type", Function),
168
+ tslib_1.__metadata("design:paramtypes", []),
169
+ tslib_1.__metadata("design:returntype", Promise)
170
+ ], TodoController.prototype, "syncSequelizeModel", null);
171
+ exports.TodoController = TodoController = tslib_1.__decorate([
172
+ tslib_1.__param(0, (0, repository_1.repository)(repositories_1.TodoRepository)),
173
+ tslib_1.__metadata("design:paramtypes", [repositories_1.TodoRepository])
174
+ ], TodoController);
175
+ //# sourceMappingURL=todo.controller.js.map
176
+ //# sourceMappingURL=/Users/dianalau/code/loopback/loopback-next/extensions/sequelize/dist/__tests__/fixtures/controllers/todo.controller.js.map
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionController = 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 types_1 = require("./../../../types");
10
+ const test_controller_base_1 = require("./test.controller.base");
11
+ let TransactionController = exports.TransactionController = class TransactionController extends test_controller_base_1.TestControllerBase {
12
+ constructor(todoListRepository, productRepository) {
13
+ super(todoListRepository, productRepository);
14
+ this.todoListRepository = todoListRepository;
15
+ this.productRepository = productRepository;
16
+ }
17
+ // create todo-list entry using transaction
18
+ async ensureTransactionCommit(todoList) {
19
+ const tx = await this.todoListRepository.beginTransaction({
20
+ isolationLevel: types_1.Transaction.ISOLATION_LEVELS.SERIALIZABLE,
21
+ });
22
+ try {
23
+ const created = await this.todoListRepository.create(todoList, {
24
+ transaction: tx,
25
+ });
26
+ await tx.commit();
27
+ return created;
28
+ }
29
+ catch (err) {
30
+ await tx.rollback();
31
+ throw err;
32
+ }
33
+ }
34
+ // create todo-list entry using transaction but rollback
35
+ async ensureRollback(todoList) {
36
+ const tx = await this.todoListRepository.beginTransaction({
37
+ isolationLevel: types_1.Transaction.ISOLATION_LEVELS.READ_COMMITTED,
38
+ });
39
+ const created = await this.todoListRepository.create(todoList, {
40
+ transaction: tx,
41
+ });
42
+ await tx.rollback();
43
+ // In real applications if you're rolling back. Don't return created entities to user
44
+ // For test cases it's required here. (to get the id)
45
+ return created;
46
+ }
47
+ // create todo-list entry using transaction but don't commit or rollback
48
+ async ensureIsolatedTransaction(todoList) {
49
+ const tx = await this.todoListRepository.beginTransaction({
50
+ isolationLevel: types_1.Transaction.ISOLATION_LEVELS.READ_COMMITTED,
51
+ });
52
+ const created = await this.todoListRepository.create(todoList, {
53
+ transaction: tx,
54
+ });
55
+ let err = {};
56
+ // reading before commit in READ_COMMITED level should not find the entity
57
+ const findBeforeCommit = await this.todoListRepository
58
+ .findById(created.id)
59
+ .catch(e => (err = e));
60
+ await tx.commit();
61
+ // throwing it after commit to avoid deadlocks
62
+ if (err) {
63
+ throw err;
64
+ }
65
+ return findBeforeCommit;
66
+ }
67
+ async ensureLocalTransactions() {
68
+ // "Todo List" model is from Primary Datasource
69
+ // and "AnyObject" model is from Secondary Datasource
70
+ // this test case is to ensure transaction created on
71
+ // one datasource can't be used in another
72
+ const tx = await this.todoListRepository.beginTransaction({
73
+ isolationLevel: types_1.Transaction.ISOLATION_LEVELS.SERIALIZABLE,
74
+ });
75
+ let err = null;
76
+ try {
77
+ await this.productRepository.create({
78
+ name: 'phone',
79
+ price: 5000,
80
+ }, {
81
+ transaction: tx,
82
+ });
83
+ }
84
+ catch (e) {
85
+ err = e;
86
+ }
87
+ await tx.commit();
88
+ if (err) {
89
+ throw new rest_1.HttpErrors[406](err.message);
90
+ }
91
+ // Won't reach till here if test passes
92
+ throw new rest_1.HttpErrors[406]('Product created with non-local transaction.');
93
+ }
94
+ };
95
+ tslib_1.__decorate([
96
+ (0, rest_1.post)('/transactions/todo-lists/commit'),
97
+ tslib_1.__param(0, (0, rest_1.requestBody)({
98
+ content: {
99
+ 'application/json': {
100
+ schema: (0, rest_1.getModelSchemaRef)(models_1.TodoList, {
101
+ title: 'NewTodoList',
102
+ exclude: ['id'],
103
+ }),
104
+ },
105
+ },
106
+ })),
107
+ tslib_1.__metadata("design:type", Function),
108
+ tslib_1.__metadata("design:paramtypes", [Object]),
109
+ tslib_1.__metadata("design:returntype", Promise)
110
+ ], TransactionController.prototype, "ensureTransactionCommit", null);
111
+ tslib_1.__decorate([
112
+ (0, rest_1.post)('/transactions/todo-lists/rollback'),
113
+ tslib_1.__param(0, (0, rest_1.requestBody)({
114
+ content: {
115
+ 'application/json': {
116
+ schema: (0, rest_1.getModelSchemaRef)(models_1.TodoList, {
117
+ title: 'NewTodoList',
118
+ exclude: ['id'],
119
+ }),
120
+ },
121
+ },
122
+ })),
123
+ tslib_1.__metadata("design:type", Function),
124
+ tslib_1.__metadata("design:paramtypes", [Object]),
125
+ tslib_1.__metadata("design:returntype", Promise)
126
+ ], TransactionController.prototype, "ensureRollback", null);
127
+ tslib_1.__decorate([
128
+ (0, rest_1.post)('/transactions/todo-lists/isolation/read_commited'),
129
+ tslib_1.__param(0, (0, rest_1.requestBody)({
130
+ content: {
131
+ 'application/json': {
132
+ schema: (0, rest_1.getModelSchemaRef)(models_1.TodoList, {
133
+ title: 'NewTodoList',
134
+ exclude: ['id'],
135
+ }),
136
+ },
137
+ },
138
+ })),
139
+ tslib_1.__metadata("design:type", Function),
140
+ tslib_1.__metadata("design:paramtypes", [Object]),
141
+ tslib_1.__metadata("design:returntype", Promise)
142
+ ], TransactionController.prototype, "ensureIsolatedTransaction", null);
143
+ tslib_1.__decorate([
144
+ (0, rest_1.get)('/transactions/ensure-local'),
145
+ tslib_1.__metadata("design:type", Function),
146
+ tslib_1.__metadata("design:paramtypes", []),
147
+ tslib_1.__metadata("design:returntype", Promise)
148
+ ], TransactionController.prototype, "ensureLocalTransactions", null);
149
+ exports.TransactionController = TransactionController = tslib_1.__decorate([
150
+ tslib_1.__param(0, (0, repository_1.repository)(repositories_1.TodoListRepository)),
151
+ tslib_1.__param(1, (0, repository_1.repository)(repositories_1.ProductRepository)),
152
+ tslib_1.__metadata("design:paramtypes", [repositories_1.TodoListRepository,
153
+ repositories_1.ProductRepository])
154
+ ], TransactionController);
155
+ //# sourceMappingURL=transaction.controller.js.map
156
+ //# sourceMappingURL=/Users/dianalau/code/loopback/loopback-next/extensions/sequelize/dist/__tests__/fixtures/controllers/transaction.controller.js.map
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserTodoListController = 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 UserTodoListController = exports.UserTodoListController = class UserTodoListController {
10
+ constructor(userRepository) {
11
+ this.userRepository = userRepository;
12
+ }
13
+ async get(id, filter) {
14
+ return this.userRepository.todoList(id).get(filter);
15
+ }
16
+ async create(id, todoList) {
17
+ return this.userRepository.todoList(id).create(todoList);
18
+ }
19
+ async patch(id, todoList, where) {
20
+ return this.userRepository.todoList(id).patch(todoList, where);
21
+ }
22
+ async delete(id, where) {
23
+ return this.userRepository.todoList(id).delete(where);
24
+ }
25
+ };
26
+ tslib_1.__decorate([
27
+ (0, rest_1.get)('/users/{id}/todo-list', {
28
+ responses: {
29
+ '200': {
30
+ description: 'User has one TodoList',
31
+ content: {
32
+ 'application/json': {
33
+ schema: (0, rest_1.getModelSchemaRef)(models_1.TodoList),
34
+ },
35
+ },
36
+ },
37
+ },
38
+ }),
39
+ tslib_1.__param(0, rest_1.param.path.number('id')),
40
+ tslib_1.__param(1, rest_1.param.query.object('filter')),
41
+ tslib_1.__metadata("design:type", Function),
42
+ tslib_1.__metadata("design:paramtypes", [Number, Object]),
43
+ tslib_1.__metadata("design:returntype", Promise)
44
+ ], UserTodoListController.prototype, "get", null);
45
+ tslib_1.__decorate([
46
+ (0, rest_1.post)('/users/{id}/todo-list', {
47
+ responses: {
48
+ '200': {
49
+ description: 'User model instance',
50
+ content: { 'application/json': { schema: (0, rest_1.getModelSchemaRef)(models_1.TodoList) } },
51
+ },
52
+ },
53
+ }),
54
+ tslib_1.__param(0, rest_1.param.path.number('id')),
55
+ tslib_1.__param(1, (0, rest_1.requestBody)({
56
+ content: {
57
+ 'application/json': {
58
+ schema: (0, rest_1.getModelSchemaRef)(models_1.TodoList, {
59
+ title: 'NewTodoListInUser',
60
+ exclude: ['id'],
61
+ optional: ['user'],
62
+ }),
63
+ },
64
+ },
65
+ })),
66
+ tslib_1.__metadata("design:type", Function),
67
+ tslib_1.__metadata("design:paramtypes", [Object, Object]),
68
+ tslib_1.__metadata("design:returntype", Promise)
69
+ ], UserTodoListController.prototype, "create", null);
70
+ tslib_1.__decorate([
71
+ (0, rest_1.patch)('/users/{id}/todo-list', {
72
+ responses: {
73
+ '200': {
74
+ description: 'User.TodoList PATCH success count',
75
+ content: { 'application/json': { schema: repository_1.CountSchema } },
76
+ },
77
+ },
78
+ }),
79
+ tslib_1.__param(0, rest_1.param.path.number('id')),
80
+ tslib_1.__param(1, (0, rest_1.requestBody)({
81
+ content: {
82
+ 'application/json': {
83
+ schema: (0, rest_1.getModelSchemaRef)(models_1.TodoList, { partial: true }),
84
+ },
85
+ },
86
+ })),
87
+ tslib_1.__param(2, rest_1.param.query.object('where', (0, rest_1.getWhereSchemaFor)(models_1.TodoList))),
88
+ tslib_1.__metadata("design:type", Function),
89
+ tslib_1.__metadata("design:paramtypes", [Number, Object, Object]),
90
+ tslib_1.__metadata("design:returntype", Promise)
91
+ ], UserTodoListController.prototype, "patch", null);
92
+ tslib_1.__decorate([
93
+ (0, rest_1.del)('/users/{id}/todo-list', {
94
+ responses: {
95
+ '200': {
96
+ description: 'User.TodoList DELETE success count',
97
+ content: { 'application/json': { schema: repository_1.CountSchema } },
98
+ },
99
+ },
100
+ }),
101
+ tslib_1.__param(0, rest_1.param.path.number('id')),
102
+ tslib_1.__param(1, rest_1.param.query.object('where', (0, rest_1.getWhereSchemaFor)(models_1.TodoList))),
103
+ tslib_1.__metadata("design:type", Function),
104
+ tslib_1.__metadata("design:paramtypes", [Number, Object]),
105
+ tslib_1.__metadata("design:returntype", Promise)
106
+ ], UserTodoListController.prototype, "delete", null);
107
+ exports.UserTodoListController = UserTodoListController = tslib_1.__decorate([
108
+ tslib_1.__param(0, (0, repository_1.repository)(repositories_1.UserRepository)),
109
+ tslib_1.__metadata("design:paramtypes", [repositories_1.UserRepository])
110
+ ], UserTodoListController);
111
+ //# sourceMappingURL=user-todo-list.controller.js.map
112
+ //# sourceMappingURL=/Users/dianalau/code/loopback/loopback-next/extensions/sequelize/dist/__tests__/fixtures/controllers/user-todo-list.controller.js.map