@spinajs/orm-api 2.0.180 → 2.0.182
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/lib/cjs/PlainJsonCollectionTransformer.d.ts +8 -8
- package/lib/cjs/PlainJsonCollectionTransformer.js +29 -29
- package/lib/cjs/PlainJsonCollectionTransformer.js.map +1 -1
- package/lib/cjs/config/orm-api.d.ts +16 -16
- package/lib/cjs/config/orm-api.js +24 -24
- package/lib/cjs/controllers/JsonApi.js +244 -244
- package/lib/cjs/controllers/crud/Create.d.ts +15 -15
- package/lib/cjs/controllers/crud/Create.js +144 -144
- package/lib/cjs/controllers/crud/Create.js.map +1 -1
- package/lib/cjs/controllers/crud/Delete.d.ts +15 -15
- package/lib/cjs/controllers/crud/Delete.js +157 -157
- package/lib/cjs/controllers/crud/Delete.js.map +1 -1
- package/lib/cjs/controllers/crud/Read.d.ts +39 -39
- package/lib/cjs/controllers/crud/Read.js +226 -226
- package/lib/cjs/controllers/crud/Read.js.map +1 -1
- package/lib/cjs/controllers/crud/Update.d.ts +12 -12
- package/lib/cjs/controllers/crud/Update.js +98 -98
- package/lib/cjs/controllers/crud/Update.js.map +1 -1
- package/lib/cjs/dto/QueryArgs.d.ts +8 -8
- package/lib/cjs/dto/QueryArgs.js +27 -27
- package/lib/cjs/dto/QueryArgs.js.map +1 -1
- package/lib/cjs/dto/QueryFilter.d.ts +5 -5
- package/lib/cjs/dto/QueryFilter.js +30 -30
- package/lib/cjs/dto/QueryFilter.js.map +1 -1
- package/lib/cjs/dto/QueryIncludes.d.ts +4 -4
- package/lib/cjs/dto/QueryIncludes.js +30 -30
- package/lib/cjs/dto/QueryIncludes.js.map +1 -1
- package/lib/cjs/hydrators/QueryFilterHydrator.d.ts +4 -4
- package/lib/cjs/hydrators/QueryFilterHydrator.js +14 -14
- package/lib/cjs/hydrators/QueryIncludesHydrator.d.ts +4 -4
- package/lib/cjs/hydrators/QueryIncludesHydrator.js +20 -20
- package/lib/cjs/index.d.ts +28 -28
- package/lib/cjs/index.js +100 -100
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces.d.ts +41 -41
- package/lib/cjs/interfaces.js +49 -49
- package/lib/cjs/interfaces.js.map +1 -1
- package/lib/cjs/middleware.d.ts +21 -21
- package/lib/cjs/middleware.js +30 -30
- package/lib/cjs/policies/FindModelType.d.ts +7 -7
- package/lib/cjs/policies/FindModelType.js +42 -42
- package/lib/cjs/policies/FindModelType.js.map +1 -1
- package/lib/cjs/route-args/ModelType.d.ts +12 -12
- package/lib/cjs/route-args/ModelType.js +38 -38
- package/lib/cjs/route-args/ModelType.js.map +1 -1
- package/lib/cjs/schemas/QueryArgs.schema.d.ts +19 -19
- package/lib/cjs/schemas/QueryArgs.schema.js +12 -12
- package/lib/cjs/schemas/QueryFilter.schema.d.ts +20 -20
- package/lib/cjs/schemas/QueryFilter.schema.js +15 -15
- package/lib/cjs/schemas/QueryIncludes.schema.d.ts +7 -7
- package/lib/cjs/schemas/QueryIncludes.schema.js +9 -9
- package/lib/mjs/PlainJsonCollectionTransformer.d.ts +8 -8
- package/lib/mjs/PlainJsonCollectionTransformer.js +26 -26
- package/lib/mjs/PlainJsonCollectionTransformer.js.map +1 -1
- package/lib/mjs/config/orm-api.d.ts +16 -16
- package/lib/mjs/config/orm-api.js +22 -22
- package/lib/mjs/controllers/JsonApi.d.ts +1 -1
- package/lib/mjs/controllers/JsonApi.js +245 -245
- package/lib/mjs/controllers/crud/Create.d.ts +15 -15
- package/lib/mjs/controllers/crud/Create.js +138 -138
- package/lib/mjs/controllers/crud/Create.js.map +1 -1
- package/lib/mjs/controllers/crud/Crud.d.ts +1 -1
- package/lib/mjs/controllers/crud/Crud.js +1 -1
- package/lib/mjs/controllers/crud/Delete.d.ts +15 -15
- package/lib/mjs/controllers/crud/Delete.js +154 -154
- package/lib/mjs/controllers/crud/Delete.js.map +1 -1
- package/lib/mjs/controllers/crud/Read.d.ts +39 -39
- package/lib/mjs/controllers/crud/Read.js +223 -223
- package/lib/mjs/controllers/crud/Read.js.map +1 -1
- package/lib/mjs/controllers/crud/Update.d.ts +12 -12
- package/lib/mjs/controllers/crud/Update.js +95 -95
- package/lib/mjs/controllers/crud/Update.js.map +1 -1
- package/lib/mjs/dto/QueryArgs.d.ts +8 -8
- package/lib/mjs/dto/QueryArgs.js +21 -21
- package/lib/mjs/dto/QueryArgs.js.map +1 -1
- package/lib/mjs/dto/QueryFilter.d.ts +5 -5
- package/lib/mjs/dto/QueryFilter.js +24 -24
- package/lib/mjs/dto/QueryFilter.js.map +1 -1
- package/lib/mjs/dto/QueryIncludes.d.ts +4 -4
- package/lib/mjs/dto/QueryIncludes.js +24 -24
- package/lib/mjs/dto/QueryIncludes.js.map +1 -1
- package/lib/mjs/hydrators/QueryFilterHydrator.d.ts +4 -4
- package/lib/mjs/hydrators/QueryFilterHydrator.js +10 -10
- package/lib/mjs/hydrators/QueryIncludesHydrator.d.ts +4 -4
- package/lib/mjs/hydrators/QueryIncludesHydrator.js +13 -13
- package/lib/mjs/index.d.ts +28 -28
- package/lib/mjs/index.js +94 -94
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/interfaces.d.ts +41 -41
- package/lib/mjs/interfaces.js +44 -44
- package/lib/mjs/interfaces.js.map +1 -1
- package/lib/mjs/middleware.d.ts +21 -21
- package/lib/mjs/middleware.js +26 -26
- package/lib/mjs/policies/FindModelType.d.ts +7 -7
- package/lib/mjs/policies/FindModelType.js +39 -39
- package/lib/mjs/policies/FindModelType.js.map +1 -1
- package/lib/mjs/route-args/ModelType.d.ts +12 -12
- package/lib/mjs/route-args/ModelType.js +34 -34
- package/lib/mjs/route-args/ModelType.js.map +1 -1
- package/lib/mjs/schemas/QueryArgs.schema.d.ts +19 -19
- package/lib/mjs/schemas/QueryArgs.schema.js +10 -10
- package/lib/mjs/schemas/QueryFilter.schema.d.ts +20 -20
- package/lib/mjs/schemas/QueryFilter.schema.js +13 -13
- package/lib/mjs/schemas/QueryIncludes.schema.d.ts +7 -7
- package/lib/mjs/schemas/QueryIncludes.schema.js +7 -7
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +12 -12
|
@@ -1,227 +1,227 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.CrudRead = void 0;
|
|
16
|
-
const orm_1 = require("@spinajs/orm");
|
|
17
|
-
const http_1 = require("@spinajs/http");
|
|
18
|
-
const rbac_http_1 = require("@spinajs/rbac-http");
|
|
19
|
-
const rbac_1 = require("@spinajs/rbac");
|
|
20
|
-
const di_1 = require("@spinajs/di");
|
|
21
|
-
const exceptions_1 = require("@spinajs/exceptions");
|
|
22
|
-
const log_1 = require("@spinajs/log");
|
|
23
|
-
require("@spinajs/rbac");
|
|
24
|
-
const ModelType_js_1 = require("../../route-args/ModelType.js");
|
|
25
|
-
const QueryArgs_js_1 = require("../../dto/QueryArgs.js");
|
|
26
|
-
const QueryFilter_js_1 = require("../../dto/QueryFilter.js");
|
|
27
|
-
const QueryIncludes_js_1 = require("../../dto/QueryIncludes.js");
|
|
28
|
-
const FindModelType_js_1 = require("../../policies/FindModelType.js");
|
|
29
|
-
const interfaces_js_1 = require("./../../interfaces.js");
|
|
30
|
-
let CrudRead = class CrudRead extends interfaces_js_1.Crud {
|
|
31
|
-
/**
|
|
32
|
-
* retrieve resource name, if model does not have @OrmResource decorator set
|
|
33
|
-
* model name is default resource name
|
|
34
|
-
* @param model
|
|
35
|
-
* @returns
|
|
36
|
-
*/
|
|
37
|
-
getResourceName(model) {
|
|
38
|
-
const descriptor = model.getModelDescriptor();
|
|
39
|
-
return descriptor.RbacResource ? descriptor.RbacResource : descriptor.Name;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
* Creates query on model and ansures that user have proper permission to access it
|
|
44
|
-
*
|
|
45
|
-
* @param model model to query against
|
|
46
|
-
* @param user user for permission check
|
|
47
|
-
* @returns
|
|
48
|
-
*/
|
|
49
|
-
getSafeQuery(model, user) {
|
|
50
|
-
const query = model.query();
|
|
51
|
-
const resource = this.getResourceName(model);
|
|
52
|
-
let permission = user.canReadAny(resource);
|
|
53
|
-
if (!permission.granted) {
|
|
54
|
-
// permission for readAny not granted, check for own
|
|
55
|
-
permission = user.canReadOwn(resource);
|
|
56
|
-
if (permission.granted) {
|
|
57
|
-
if (model.ensureOwnership) {
|
|
58
|
-
model.ensureOwnership(query, user);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
throw new exceptions_1.UnexpectedServerError(`Resource ${resource} can be only read by owner and does not have ensureOwnership method implemented`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
throw new exceptions_1.Forbidden(`You do not access to ${resource}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return { query, permission };
|
|
69
|
-
}
|
|
70
|
-
async getAll(model, getParams, filters, includes, user) {
|
|
71
|
-
const { query, permission } = this.getSafeQuery(model, user);
|
|
72
|
-
query
|
|
73
|
-
.select('*')
|
|
74
|
-
.populate(includes)
|
|
75
|
-
.order(getParams.order, getParams.orderDirection ?? orm_1.SortOrder.ASC)
|
|
76
|
-
.skip(getParams.page * getParams.perPage ?? 0)
|
|
77
|
-
.take(getParams.perPage ?? 10);
|
|
78
|
-
// apply basic filters
|
|
79
|
-
for (const filter in filters) {
|
|
80
|
-
const f = filters[filter];
|
|
81
|
-
// if filter have no operator, by default we assume qeuality
|
|
82
|
-
query.where(filter, f.op ? f.op : '=', f.val);
|
|
83
|
-
}
|
|
84
|
-
const count = await query.clone().clearColumns().count('*', 'count').takeFirst().asRaw();
|
|
85
|
-
const result = await query;
|
|
86
|
-
return new http_1.Ok({
|
|
87
|
-
Data: result.map((x) => x.dehydrateWithRelations()).map((x) => permission.filter(x)),
|
|
88
|
-
Total: count.count,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
async get(user, model, id, includes) {
|
|
92
|
-
const descriptor = model.getModelDescriptor();
|
|
93
|
-
const { query, permission } = this.getSafeQuery(model, user);
|
|
94
|
-
const result = await query
|
|
95
|
-
.select('*')
|
|
96
|
-
.where(descriptor.PrimaryKey, id)
|
|
97
|
-
.populate(includes)
|
|
98
|
-
.firstOrThrow(new exceptions_1.ResourceNotFound(`Record with id ${id} not found`, {
|
|
99
|
-
Resource: model.name,
|
|
100
|
-
[descriptor.PrimaryKey]: id,
|
|
101
|
-
}));
|
|
102
|
-
return new http_1.Ok(permission.filter(result.dehydrateWithRelations()));
|
|
103
|
-
}
|
|
104
|
-
async getRelation(model, id, relation, relationId, includes, user) {
|
|
105
|
-
const mDescriptor = model.getModelDescriptor();
|
|
106
|
-
const rDescriptor = model.getRelationDescriptor(relation);
|
|
107
|
-
const rmDescriptor = rDescriptor.TargetModel.getModelDescriptor();
|
|
108
|
-
const { query, permission } = this.getSafeQuery(rDescriptor.TargetModel, user);
|
|
109
|
-
if (!mDescriptor.Relations.has(relation)) {
|
|
110
|
-
return new exceptions_1.BadRequest(`Resource ${mDescriptor.Name} does not have relation ${relation} defined`);
|
|
111
|
-
}
|
|
112
|
-
const pExists = await model.exists(id);
|
|
113
|
-
if (!pExists) {
|
|
114
|
-
throw new exceptions_1.ResourceNotFound(`Record with id ${id} not found`, {
|
|
115
|
-
Resource: model.name,
|
|
116
|
-
[mDescriptor.PrimaryKey]: id,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
const result = await query
|
|
120
|
-
.select('*')
|
|
121
|
-
.populate(includes)
|
|
122
|
-
.where(rmDescriptor.PrimaryKey, relationId)
|
|
123
|
-
.firstOrThrow(new exceptions_1.ResourceNotFound(`Record with id ${relationId} not found`, {
|
|
124
|
-
Resource: rDescriptor.TargetModel.name,
|
|
125
|
-
[rmDescriptor.PrimaryKey]: relationId,
|
|
126
|
-
}));
|
|
127
|
-
return new http_1.Ok(permission.filter(result.dehydrateWithRelations()));
|
|
128
|
-
}
|
|
129
|
-
async getRelations(model, id, relation, params, filters, includes, user) {
|
|
130
|
-
const mDescriptor = model.getModelDescriptor();
|
|
131
|
-
const rDescriptor = model.getRelationDescriptor(relation);
|
|
132
|
-
const { query, permission } = this.getSafeQuery(rDescriptor.TargetModel, user);
|
|
133
|
-
if (!mDescriptor.Relations.has(relation)) {
|
|
134
|
-
return new exceptions_1.BadRequest(`Resource ${mDescriptor.Name} does not have relation ${relation} defined`);
|
|
135
|
-
}
|
|
136
|
-
const pExists = await model.exists(id);
|
|
137
|
-
if (!pExists) {
|
|
138
|
-
throw new exceptions_1.ResourceNotFound(`Record with id ${id} not found`, {
|
|
139
|
-
Resource: model.name,
|
|
140
|
-
[mDescriptor.PrimaryKey]: id,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
query
|
|
144
|
-
.where(rDescriptor.ForeignKey, id)
|
|
145
|
-
.select('*')
|
|
146
|
-
.populate(includes)
|
|
147
|
-
.order(params.order, params.orderDirection ?? orm_1.SortOrder.ASC)
|
|
148
|
-
.skip(params.page * params.perPage ?? 0)
|
|
149
|
-
.take(params.perPage ?? 10);
|
|
150
|
-
// apply basic filters
|
|
151
|
-
for (const filter in filters) {
|
|
152
|
-
const f = filters[filter];
|
|
153
|
-
// if filter have no operator, by default we assume qeuality
|
|
154
|
-
query.where(filter, f.op ? f.op : '=', f.val);
|
|
155
|
-
}
|
|
156
|
-
const count = await query.clone().clearColumns().count('*', 'count').takeFirst().asRaw();
|
|
157
|
-
const result = await query;
|
|
158
|
-
return new http_1.Ok({
|
|
159
|
-
Data: result.map((x) => x.dehydrateWithRelations()).map((x) => permission.filter(x)),
|
|
160
|
-
Total: count,
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
__param(
|
|
180
|
-
__param(
|
|
181
|
-
__param(
|
|
182
|
-
__param(
|
|
183
|
-
|
|
184
|
-
__metadata("design:
|
|
185
|
-
__metadata("design:
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
__param(
|
|
191
|
-
__param(
|
|
192
|
-
__param(
|
|
193
|
-
|
|
194
|
-
__metadata("design:
|
|
195
|
-
__metadata("design:
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
__param(
|
|
201
|
-
__param(
|
|
202
|
-
__param(
|
|
203
|
-
__param(
|
|
204
|
-
__param(
|
|
205
|
-
|
|
206
|
-
__metadata("design:
|
|
207
|
-
__metadata("design:
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
__param(
|
|
213
|
-
__param(
|
|
214
|
-
__param(
|
|
215
|
-
__param(
|
|
216
|
-
__param(
|
|
217
|
-
__param(
|
|
218
|
-
|
|
219
|
-
__metadata("design:
|
|
220
|
-
__metadata("design:
|
|
221
|
-
|
|
222
|
-
CrudRead
|
|
223
|
-
|
|
224
|
-
(0, http_1.
|
|
225
|
-
|
|
226
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CrudRead = void 0;
|
|
16
|
+
const orm_1 = require("@spinajs/orm");
|
|
17
|
+
const http_1 = require("@spinajs/http");
|
|
18
|
+
const rbac_http_1 = require("@spinajs/rbac-http");
|
|
19
|
+
const rbac_1 = require("@spinajs/rbac");
|
|
20
|
+
const di_1 = require("@spinajs/di");
|
|
21
|
+
const exceptions_1 = require("@spinajs/exceptions");
|
|
22
|
+
const log_1 = require("@spinajs/log");
|
|
23
|
+
require("@spinajs/rbac");
|
|
24
|
+
const ModelType_js_1 = require("../../route-args/ModelType.js");
|
|
25
|
+
const QueryArgs_js_1 = require("../../dto/QueryArgs.js");
|
|
26
|
+
const QueryFilter_js_1 = require("../../dto/QueryFilter.js");
|
|
27
|
+
const QueryIncludes_js_1 = require("../../dto/QueryIncludes.js");
|
|
28
|
+
const FindModelType_js_1 = require("../../policies/FindModelType.js");
|
|
29
|
+
const interfaces_js_1 = require("./../../interfaces.js");
|
|
30
|
+
let CrudRead = class CrudRead extends interfaces_js_1.Crud {
|
|
31
|
+
/**
|
|
32
|
+
* retrieve resource name, if model does not have @OrmResource decorator set
|
|
33
|
+
* model name is default resource name
|
|
34
|
+
* @param model
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
getResourceName(model) {
|
|
38
|
+
const descriptor = model.getModelDescriptor();
|
|
39
|
+
return descriptor.RbacResource ? descriptor.RbacResource : descriptor.Name;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* Creates query on model and ansures that user have proper permission to access it
|
|
44
|
+
*
|
|
45
|
+
* @param model model to query against
|
|
46
|
+
* @param user user for permission check
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
getSafeQuery(model, user) {
|
|
50
|
+
const query = model.query();
|
|
51
|
+
const resource = this.getResourceName(model);
|
|
52
|
+
let permission = user.canReadAny(resource);
|
|
53
|
+
if (!permission.granted) {
|
|
54
|
+
// permission for readAny not granted, check for own
|
|
55
|
+
permission = user.canReadOwn(resource);
|
|
56
|
+
if (permission.granted) {
|
|
57
|
+
if (model.ensureOwnership) {
|
|
58
|
+
model.ensureOwnership(query, user);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
throw new exceptions_1.UnexpectedServerError(`Resource ${resource} can be only read by owner and does not have ensureOwnership method implemented`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
throw new exceptions_1.Forbidden(`You do not access to ${resource}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return { query, permission };
|
|
69
|
+
}
|
|
70
|
+
async getAll(model, getParams, filters, includes, user) {
|
|
71
|
+
const { query, permission } = this.getSafeQuery(model, user);
|
|
72
|
+
query
|
|
73
|
+
.select('*')
|
|
74
|
+
.populate(includes)
|
|
75
|
+
.order(getParams.order, getParams.orderDirection ?? orm_1.SortOrder.ASC)
|
|
76
|
+
.skip(getParams.page * getParams.perPage ?? 0)
|
|
77
|
+
.take(getParams.perPage ?? 10);
|
|
78
|
+
// apply basic filters
|
|
79
|
+
for (const filter in filters) {
|
|
80
|
+
const f = filters[filter];
|
|
81
|
+
// if filter have no operator, by default we assume qeuality
|
|
82
|
+
query.where(filter, f.op ? f.op : '=', f.val);
|
|
83
|
+
}
|
|
84
|
+
const count = await query.clone().clearColumns().count('*', 'count').takeFirst().asRaw();
|
|
85
|
+
const result = await query;
|
|
86
|
+
return new http_1.Ok({
|
|
87
|
+
Data: result.map((x) => x.dehydrateWithRelations()).map((x) => permission.filter(x)),
|
|
88
|
+
Total: count.count,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async get(user, model, id, includes) {
|
|
92
|
+
const descriptor = model.getModelDescriptor();
|
|
93
|
+
const { query, permission } = this.getSafeQuery(model, user);
|
|
94
|
+
const result = await query
|
|
95
|
+
.select('*')
|
|
96
|
+
.where(descriptor.PrimaryKey, id)
|
|
97
|
+
.populate(includes)
|
|
98
|
+
.firstOrThrow(new exceptions_1.ResourceNotFound(`Record with id ${id} not found`, {
|
|
99
|
+
Resource: model.name,
|
|
100
|
+
[descriptor.PrimaryKey]: id,
|
|
101
|
+
}));
|
|
102
|
+
return new http_1.Ok(permission.filter(result.dehydrateWithRelations()));
|
|
103
|
+
}
|
|
104
|
+
async getRelation(model, id, relation, relationId, includes, user) {
|
|
105
|
+
const mDescriptor = model.getModelDescriptor();
|
|
106
|
+
const rDescriptor = model.getRelationDescriptor(relation);
|
|
107
|
+
const rmDescriptor = rDescriptor.TargetModel.getModelDescriptor();
|
|
108
|
+
const { query, permission } = this.getSafeQuery(rDescriptor.TargetModel, user);
|
|
109
|
+
if (!mDescriptor.Relations.has(relation)) {
|
|
110
|
+
return new exceptions_1.BadRequest(`Resource ${mDescriptor.Name} does not have relation ${relation} defined`);
|
|
111
|
+
}
|
|
112
|
+
const pExists = await model.exists(id);
|
|
113
|
+
if (!pExists) {
|
|
114
|
+
throw new exceptions_1.ResourceNotFound(`Record with id ${id} not found`, {
|
|
115
|
+
Resource: model.name,
|
|
116
|
+
[mDescriptor.PrimaryKey]: id,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
const result = await query
|
|
120
|
+
.select('*')
|
|
121
|
+
.populate(includes)
|
|
122
|
+
.where(rmDescriptor.PrimaryKey, relationId)
|
|
123
|
+
.firstOrThrow(new exceptions_1.ResourceNotFound(`Record with id ${relationId} not found`, {
|
|
124
|
+
Resource: rDescriptor.TargetModel.name,
|
|
125
|
+
[rmDescriptor.PrimaryKey]: relationId,
|
|
126
|
+
}));
|
|
127
|
+
return new http_1.Ok(permission.filter(result.dehydrateWithRelations()));
|
|
128
|
+
}
|
|
129
|
+
async getRelations(model, id, relation, params, filters, includes, user) {
|
|
130
|
+
const mDescriptor = model.getModelDescriptor();
|
|
131
|
+
const rDescriptor = model.getRelationDescriptor(relation);
|
|
132
|
+
const { query, permission } = this.getSafeQuery(rDescriptor.TargetModel, user);
|
|
133
|
+
if (!mDescriptor.Relations.has(relation)) {
|
|
134
|
+
return new exceptions_1.BadRequest(`Resource ${mDescriptor.Name} does not have relation ${relation} defined`);
|
|
135
|
+
}
|
|
136
|
+
const pExists = await model.exists(id);
|
|
137
|
+
if (!pExists) {
|
|
138
|
+
throw new exceptions_1.ResourceNotFound(`Record with id ${id} not found`, {
|
|
139
|
+
Resource: model.name,
|
|
140
|
+
[mDescriptor.PrimaryKey]: id,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
query
|
|
144
|
+
.where(rDescriptor.ForeignKey, id)
|
|
145
|
+
.select('*')
|
|
146
|
+
.populate(includes)
|
|
147
|
+
.order(params.order, params.orderDirection ?? orm_1.SortOrder.ASC)
|
|
148
|
+
.skip(params.page * params.perPage ?? 0)
|
|
149
|
+
.take(params.perPage ?? 10);
|
|
150
|
+
// apply basic filters
|
|
151
|
+
for (const filter in filters) {
|
|
152
|
+
const f = filters[filter];
|
|
153
|
+
// if filter have no operator, by default we assume qeuality
|
|
154
|
+
query.where(filter, f.op ? f.op : '=', f.val);
|
|
155
|
+
}
|
|
156
|
+
const count = await query.clone().clearColumns().count('*', 'count').takeFirst().asRaw();
|
|
157
|
+
const result = await query;
|
|
158
|
+
return new http_1.Ok({
|
|
159
|
+
Data: result.map((x) => x.dehydrateWithRelations()).map((x) => permission.filter(x)),
|
|
160
|
+
Total: count,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
exports.CrudRead = CrudRead;
|
|
165
|
+
__decorate([
|
|
166
|
+
(0, log_1.Logger)('orm-http:api'),
|
|
167
|
+
__metadata("design:type", log_1.Log)
|
|
168
|
+
], CrudRead.prototype, "Log", void 0);
|
|
169
|
+
__decorate([
|
|
170
|
+
(0, di_1.Autoinject)(),
|
|
171
|
+
__metadata("design:type", orm_1.Orm)
|
|
172
|
+
], CrudRead.prototype, "Orm", void 0);
|
|
173
|
+
__decorate([
|
|
174
|
+
(0, di_1.Autoinject)(),
|
|
175
|
+
__metadata("design:type", rbac_1.AccessControl)
|
|
176
|
+
], CrudRead.prototype, "Ac", void 0);
|
|
177
|
+
__decorate([
|
|
178
|
+
(0, http_1.Get)(':model'),
|
|
179
|
+
__param(0, (0, ModelType_js_1.ModelType)()),
|
|
180
|
+
__param(1, (0, http_1.Query)()),
|
|
181
|
+
__param(2, (0, http_1.Query)()),
|
|
182
|
+
__param(3, (0, http_1.Query)()),
|
|
183
|
+
__param(4, (0, rbac_http_1.User)()),
|
|
184
|
+
__metadata("design:type", Function),
|
|
185
|
+
__metadata("design:paramtypes", [Object, QueryArgs_js_1.QueryArgs, QueryFilter_js_1.QueryFilter, QueryIncludes_js_1.QueryIncludes, rbac_1.User]),
|
|
186
|
+
__metadata("design:returntype", Promise)
|
|
187
|
+
], CrudRead.prototype, "getAll", null);
|
|
188
|
+
__decorate([
|
|
189
|
+
(0, http_1.Get)(':model/:id'),
|
|
190
|
+
__param(0, (0, rbac_http_1.User)()),
|
|
191
|
+
__param(1, (0, ModelType_js_1.ModelType)()),
|
|
192
|
+
__param(2, (0, http_1.Param)()),
|
|
193
|
+
__param(3, (0, http_1.Query)()),
|
|
194
|
+
__metadata("design:type", Function),
|
|
195
|
+
__metadata("design:paramtypes", [rbac_1.User, Object, Number, QueryIncludes_js_1.QueryIncludes]),
|
|
196
|
+
__metadata("design:returntype", Promise)
|
|
197
|
+
], CrudRead.prototype, "get", null);
|
|
198
|
+
__decorate([
|
|
199
|
+
(0, http_1.Get)(':model/:id/:relation/:relationId'),
|
|
200
|
+
__param(0, (0, ModelType_js_1.ModelType)()),
|
|
201
|
+
__param(1, (0, http_1.Param)()),
|
|
202
|
+
__param(2, (0, http_1.Param)()),
|
|
203
|
+
__param(3, (0, http_1.Param)()),
|
|
204
|
+
__param(4, (0, http_1.Query)()),
|
|
205
|
+
__param(5, (0, rbac_http_1.User)()),
|
|
206
|
+
__metadata("design:type", Function),
|
|
207
|
+
__metadata("design:paramtypes", [Object, Object, String, Object, QueryIncludes_js_1.QueryIncludes, rbac_1.User]),
|
|
208
|
+
__metadata("design:returntype", Promise)
|
|
209
|
+
], CrudRead.prototype, "getRelation", null);
|
|
210
|
+
__decorate([
|
|
211
|
+
(0, http_1.Get)(':model/:id/:relation'),
|
|
212
|
+
__param(0, (0, ModelType_js_1.ModelType)()),
|
|
213
|
+
__param(1, (0, http_1.Param)()),
|
|
214
|
+
__param(2, (0, http_1.Param)()),
|
|
215
|
+
__param(3, (0, http_1.Query)()),
|
|
216
|
+
__param(4, (0, http_1.Query)()),
|
|
217
|
+
__param(5, (0, http_1.Query)()),
|
|
218
|
+
__param(6, (0, rbac_http_1.User)()),
|
|
219
|
+
__metadata("design:type", Function),
|
|
220
|
+
__metadata("design:paramtypes", [Object, Object, String, QueryArgs_js_1.QueryArgs, QueryFilter_js_1.QueryFilter, QueryIncludes_js_1.QueryIncludes, rbac_1.User]),
|
|
221
|
+
__metadata("design:returntype", Promise)
|
|
222
|
+
], CrudRead.prototype, "getRelations", null);
|
|
223
|
+
exports.CrudRead = CrudRead = __decorate([
|
|
224
|
+
(0, http_1.BasePath)('crud'),
|
|
225
|
+
(0, http_1.Policy)(FindModelType_js_1.FindModelType)
|
|
226
|
+
], CrudRead);
|
|
227
227
|
//# sourceMappingURL=Read.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Read.js","sourceRoot":"","sources":["../../../../src/controllers/crud/Read.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,sCAA4D;AAC5D,wCAAwE;AACxE,kDAA0C;AAC1C,wCAAuF;AACvF,oCAAyC;AACzC,oDAAqG;AACrG,sCAA2C;AAC3C,yBAAuB;AAGvB,gEAA0D;AAC1D,yDAAmD;AACnD,6DAAuD;AACvD,iEAA2D;AAC3D,sEAAgE;AAChE,yDAA6C;AAItC,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,oBAAI;IAUhC;;;;;OAKG;IACO,eAAe,CAAC,KAAmB;QAC3C,MAAM,UAAU,GAAG,KAAK,CAAC,kBAAkB,EAA0B,CAAC;QACtE,OAAO,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;IAC7E,CAAC;IAED;;;;;;;OAOG;IACO,YAAY,CAAC,KAAmB,EAAE,IAAe;QACzD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;QAE5B,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC7C,IAAI,UAAU,GAAe,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAEvD,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE;YACvB,qDAAqD;YAC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,gCAAa,EAAiB,WAAS;;4CAwC7N;mBA3KU,QAAQ;IAFpB,IAAA,eAAQ,EAAC,MAAM,CAAC;IAChB,IAAA,aAAM,EAAC,gCAAa,CAAC;GACT,QAAQ,CA4KpB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { IModelStatic, Orm } from '@spinajs/orm';
|
|
2
|
-
import { Ok } from '@spinajs/http';
|
|
3
|
-
import { Log } from '@spinajs/log';
|
|
4
|
-
import { AccessControl } from '@spinajs/rbac';
|
|
5
|
-
import { Crud } from './../../interfaces.js';
|
|
6
|
-
export declare class CrudUpdate extends Crud {
|
|
7
|
-
protected Log: Log;
|
|
8
|
-
protected Orm: Orm;
|
|
9
|
-
protected Ac: AccessControl;
|
|
10
|
-
update(model: IModelStatic, id: number, data: unknown): Promise<Ok>;
|
|
11
|
-
updateRelation(model: IModelStatic, id: number, relation: string, relationId: any, data: unknown): Promise<Ok>;
|
|
12
|
-
}
|
|
1
|
+
import { IModelStatic, Orm } from '@spinajs/orm';
|
|
2
|
+
import { Ok } from '@spinajs/http';
|
|
3
|
+
import { Log } from '@spinajs/log';
|
|
4
|
+
import { AccessControl } from '@spinajs/rbac';
|
|
5
|
+
import { Crud } from './../../interfaces.js';
|
|
6
|
+
export declare class CrudUpdate extends Crud {
|
|
7
|
+
protected Log: Log;
|
|
8
|
+
protected Orm: Orm;
|
|
9
|
+
protected Ac: AccessControl;
|
|
10
|
+
update(model: IModelStatic, id: number, data: unknown): Promise<Ok>;
|
|
11
|
+
updateRelation(model: IModelStatic, id: number, relation: string, relationId: any, data: unknown): Promise<Ok>;
|
|
12
|
+
}
|
|
13
13
|
//# sourceMappingURL=Update.d.ts.map
|