@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,224 +1,224 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
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;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
-
};
|
|
13
|
-
import { Orm, SortOrder } from '@spinajs/orm';
|
|
14
|
-
import { Get, Ok, Query, Param, Policy, BasePath } from '@spinajs/http';
|
|
15
|
-
import { User } from '@spinajs/rbac-http';
|
|
16
|
-
import { User as UserModel, AccessControl } from '@spinajs/rbac';
|
|
17
|
-
import { Autoinject } from '@spinajs/di';
|
|
18
|
-
import { BadRequest, Forbidden, ResourceNotFound, UnexpectedServerError } from '@spinajs/exceptions';
|
|
19
|
-
import { Log, Logger } from '@spinajs/log';
|
|
20
|
-
import '@spinajs/rbac';
|
|
21
|
-
import { ModelType } from '../../route-args/ModelType.js';
|
|
22
|
-
import { QueryArgs } from '../../dto/QueryArgs.js';
|
|
23
|
-
import { QueryFilter } from '../../dto/QueryFilter.js';
|
|
24
|
-
import { QueryIncludes } from '../../dto/QueryIncludes.js';
|
|
25
|
-
import { FindModelType } from '../../policies/FindModelType.js';
|
|
26
|
-
import { Crud } from './../../interfaces.js';
|
|
27
|
-
let CrudRead = class CrudRead extends Crud {
|
|
28
|
-
/**
|
|
29
|
-
* retrieve resource name, if model does not have @OrmResource decorator set
|
|
30
|
-
* model name is default resource name
|
|
31
|
-
* @param model
|
|
32
|
-
* @returns
|
|
33
|
-
*/
|
|
34
|
-
getResourceName(model) {
|
|
35
|
-
const descriptor = model.getModelDescriptor();
|
|
36
|
-
return descriptor.RbacResource ? descriptor.RbacResource : descriptor.Name;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
* Creates query on model and ansures that user have proper permission to access it
|
|
41
|
-
*
|
|
42
|
-
* @param model model to query against
|
|
43
|
-
* @param user user for permission check
|
|
44
|
-
* @returns
|
|
45
|
-
*/
|
|
46
|
-
getSafeQuery(model, user) {
|
|
47
|
-
const query = model.query();
|
|
48
|
-
const resource = this.getResourceName(model);
|
|
49
|
-
let permission = user.canReadAny(resource);
|
|
50
|
-
if (!permission.granted) {
|
|
51
|
-
// permission for readAny not granted, check for own
|
|
52
|
-
permission = user.canReadOwn(resource);
|
|
53
|
-
if (permission.granted) {
|
|
54
|
-
if (model.ensureOwnership) {
|
|
55
|
-
model.ensureOwnership(query, user);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
throw new UnexpectedServerError(`Resource ${resource} can be only read by owner and does not have ensureOwnership method implemented`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
throw new Forbidden(`You do not access to ${resource}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return { query, permission };
|
|
66
|
-
}
|
|
67
|
-
async getAll(model, getParams, filters, includes, user) {
|
|
68
|
-
const { query, permission } = this.getSafeQuery(model, user);
|
|
69
|
-
query
|
|
70
|
-
.select('*')
|
|
71
|
-
.populate(includes)
|
|
72
|
-
.order(getParams.order, getParams.orderDirection ?? SortOrder.ASC)
|
|
73
|
-
.skip(getParams.page * getParams.perPage ?? 0)
|
|
74
|
-
.take(getParams.perPage ?? 10);
|
|
75
|
-
// apply basic filters
|
|
76
|
-
for (const filter in filters) {
|
|
77
|
-
const f = filters[filter];
|
|
78
|
-
// if filter have no operator, by default we assume qeuality
|
|
79
|
-
query.where(filter, f.op ? f.op : '=', f.val);
|
|
80
|
-
}
|
|
81
|
-
const count = await query.clone().clearColumns().count('*', 'count').takeFirst().asRaw();
|
|
82
|
-
const result = await query;
|
|
83
|
-
return new Ok({
|
|
84
|
-
Data: result.map((x) => x.dehydrateWithRelations()).map((x) => permission.filter(x)),
|
|
85
|
-
Total: count.count,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
async get(user, model, id, includes) {
|
|
89
|
-
const descriptor = model.getModelDescriptor();
|
|
90
|
-
const { query, permission } = this.getSafeQuery(model, user);
|
|
91
|
-
const result = await query
|
|
92
|
-
.select('*')
|
|
93
|
-
.where(descriptor.PrimaryKey, id)
|
|
94
|
-
.populate(includes)
|
|
95
|
-
.firstOrThrow(new ResourceNotFound(`Record with id ${id} not found`, {
|
|
96
|
-
Resource: model.name,
|
|
97
|
-
[descriptor.PrimaryKey]: id,
|
|
98
|
-
}));
|
|
99
|
-
return new Ok(permission.filter(result.dehydrateWithRelations()));
|
|
100
|
-
}
|
|
101
|
-
async getRelation(model, id, relation, relationId, includes, user) {
|
|
102
|
-
const mDescriptor = model.getModelDescriptor();
|
|
103
|
-
const rDescriptor = model.getRelationDescriptor(relation);
|
|
104
|
-
const rmDescriptor = rDescriptor.TargetModel.getModelDescriptor();
|
|
105
|
-
const { query, permission } = this.getSafeQuery(rDescriptor.TargetModel, user);
|
|
106
|
-
if (!mDescriptor.Relations.has(relation)) {
|
|
107
|
-
return new BadRequest(`Resource ${mDescriptor.Name} does not have relation ${relation} defined`);
|
|
108
|
-
}
|
|
109
|
-
const pExists = await model.exists(id);
|
|
110
|
-
if (!pExists) {
|
|
111
|
-
throw new ResourceNotFound(`Record with id ${id} not found`, {
|
|
112
|
-
Resource: model.name,
|
|
113
|
-
[mDescriptor.PrimaryKey]: id,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
const result = await query
|
|
117
|
-
.select('*')
|
|
118
|
-
.populate(includes)
|
|
119
|
-
.where(rmDescriptor.PrimaryKey, relationId)
|
|
120
|
-
.firstOrThrow(new ResourceNotFound(`Record with id ${relationId} not found`, {
|
|
121
|
-
Resource: rDescriptor.TargetModel.name,
|
|
122
|
-
[rmDescriptor.PrimaryKey]: relationId,
|
|
123
|
-
}));
|
|
124
|
-
return new Ok(permission.filter(result.dehydrateWithRelations()));
|
|
125
|
-
}
|
|
126
|
-
async getRelations(model, id, relation, params, filters, includes, user) {
|
|
127
|
-
const mDescriptor = model.getModelDescriptor();
|
|
128
|
-
const rDescriptor = model.getRelationDescriptor(relation);
|
|
129
|
-
const { query, permission } = this.getSafeQuery(rDescriptor.TargetModel, user);
|
|
130
|
-
if (!mDescriptor.Relations.has(relation)) {
|
|
131
|
-
return new BadRequest(`Resource ${mDescriptor.Name} does not have relation ${relation} defined`);
|
|
132
|
-
}
|
|
133
|
-
const pExists = await model.exists(id);
|
|
134
|
-
if (!pExists) {
|
|
135
|
-
throw new ResourceNotFound(`Record with id ${id} not found`, {
|
|
136
|
-
Resource: model.name,
|
|
137
|
-
[mDescriptor.PrimaryKey]: id,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
query
|
|
141
|
-
.where(rDescriptor.ForeignKey, id)
|
|
142
|
-
.select('*')
|
|
143
|
-
.populate(includes)
|
|
144
|
-
.order(params.order, params.orderDirection ?? SortOrder.ASC)
|
|
145
|
-
.skip(params.page * params.perPage ?? 0)
|
|
146
|
-
.take(params.perPage ?? 10);
|
|
147
|
-
// apply basic filters
|
|
148
|
-
for (const filter in filters) {
|
|
149
|
-
const f = filters[filter];
|
|
150
|
-
// if filter have no operator, by default we assume qeuality
|
|
151
|
-
query.where(filter, f.op ? f.op : '=', f.val);
|
|
152
|
-
}
|
|
153
|
-
const count = await query.clone().clearColumns().count('*', 'count').takeFirst().asRaw();
|
|
154
|
-
const result = await query;
|
|
155
|
-
return new Ok({
|
|
156
|
-
Data: result.map((x) => x.dehydrateWithRelations()).map((x) => permission.filter(x)),
|
|
157
|
-
Total: count,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
__decorate([
|
|
162
|
-
Logger('orm-http:api'),
|
|
163
|
-
__metadata("design:type", Log)
|
|
164
|
-
], CrudRead.prototype, "Log", void 0);
|
|
165
|
-
__decorate([
|
|
166
|
-
Autoinject(),
|
|
167
|
-
__metadata("design:type", Orm)
|
|
168
|
-
], CrudRead.prototype, "Orm", void 0);
|
|
169
|
-
__decorate([
|
|
170
|
-
Autoinject(),
|
|
171
|
-
__metadata("design:type", AccessControl)
|
|
172
|
-
], CrudRead.prototype, "Ac", void 0);
|
|
173
|
-
__decorate([
|
|
174
|
-
Get(':model'),
|
|
175
|
-
__param(0, ModelType()),
|
|
176
|
-
__param(1, Query()),
|
|
177
|
-
__param(2, Query()),
|
|
178
|
-
__param(3, Query()),
|
|
179
|
-
__param(4, User()),
|
|
180
|
-
__metadata("design:type", Function),
|
|
181
|
-
__metadata("design:paramtypes", [Object, QueryArgs, QueryFilter, QueryIncludes, UserModel]),
|
|
182
|
-
__metadata("design:returntype", Promise)
|
|
183
|
-
], CrudRead.prototype, "getAll", null);
|
|
184
|
-
__decorate([
|
|
185
|
-
Get(':model/:id'),
|
|
186
|
-
__param(0, User()),
|
|
187
|
-
__param(1, ModelType()),
|
|
188
|
-
__param(2, Param()),
|
|
189
|
-
__param(3, Query()),
|
|
190
|
-
__metadata("design:type", Function),
|
|
191
|
-
__metadata("design:paramtypes", [UserModel, Object, Number, QueryIncludes]),
|
|
192
|
-
__metadata("design:returntype", Promise)
|
|
193
|
-
], CrudRead.prototype, "get", null);
|
|
194
|
-
__decorate([
|
|
195
|
-
Get(':model/:id/:relation/:relationId'),
|
|
196
|
-
__param(0, ModelType()),
|
|
197
|
-
__param(1, Param()),
|
|
198
|
-
__param(2, Param()),
|
|
199
|
-
__param(3, Param()),
|
|
200
|
-
__param(4, Query()),
|
|
201
|
-
__param(5, User()),
|
|
202
|
-
__metadata("design:type", Function),
|
|
203
|
-
__metadata("design:paramtypes", [Object, Object, String, Object, QueryIncludes, UserModel]),
|
|
204
|
-
__metadata("design:returntype", Promise)
|
|
205
|
-
], CrudRead.prototype, "getRelation", null);
|
|
206
|
-
__decorate([
|
|
207
|
-
Get(':model/:id/:relation'),
|
|
208
|
-
__param(0, ModelType()),
|
|
209
|
-
__param(1, Param()),
|
|
210
|
-
__param(2, Param()),
|
|
211
|
-
__param(3, Query()),
|
|
212
|
-
__param(4, Query()),
|
|
213
|
-
__param(5, Query()),
|
|
214
|
-
__param(6, User()),
|
|
215
|
-
__metadata("design:type", Function),
|
|
216
|
-
__metadata("design:paramtypes", [Object, Object, String, QueryArgs, QueryFilter, QueryIncludes, UserModel]),
|
|
217
|
-
__metadata("design:returntype", Promise)
|
|
218
|
-
], CrudRead.prototype, "getRelations", null);
|
|
219
|
-
CrudRead = __decorate([
|
|
220
|
-
BasePath('crud'),
|
|
221
|
-
Policy(FindModelType)
|
|
222
|
-
], CrudRead);
|
|
223
|
-
export { CrudRead };
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { Orm, SortOrder } from '@spinajs/orm';
|
|
14
|
+
import { Get, Ok, Query, Param, Policy, BasePath } from '@spinajs/http';
|
|
15
|
+
import { User } from '@spinajs/rbac-http';
|
|
16
|
+
import { User as UserModel, AccessControl } from '@spinajs/rbac';
|
|
17
|
+
import { Autoinject } from '@spinajs/di';
|
|
18
|
+
import { BadRequest, Forbidden, ResourceNotFound, UnexpectedServerError } from '@spinajs/exceptions';
|
|
19
|
+
import { Log, Logger } from '@spinajs/log';
|
|
20
|
+
import '@spinajs/rbac';
|
|
21
|
+
import { ModelType } from '../../route-args/ModelType.js';
|
|
22
|
+
import { QueryArgs } from '../../dto/QueryArgs.js';
|
|
23
|
+
import { QueryFilter } from '../../dto/QueryFilter.js';
|
|
24
|
+
import { QueryIncludes } from '../../dto/QueryIncludes.js';
|
|
25
|
+
import { FindModelType } from '../../policies/FindModelType.js';
|
|
26
|
+
import { Crud } from './../../interfaces.js';
|
|
27
|
+
let CrudRead = class CrudRead extends Crud {
|
|
28
|
+
/**
|
|
29
|
+
* retrieve resource name, if model does not have @OrmResource decorator set
|
|
30
|
+
* model name is default resource name
|
|
31
|
+
* @param model
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
getResourceName(model) {
|
|
35
|
+
const descriptor = model.getModelDescriptor();
|
|
36
|
+
return descriptor.RbacResource ? descriptor.RbacResource : descriptor.Name;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* Creates query on model and ansures that user have proper permission to access it
|
|
41
|
+
*
|
|
42
|
+
* @param model model to query against
|
|
43
|
+
* @param user user for permission check
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
getSafeQuery(model, user) {
|
|
47
|
+
const query = model.query();
|
|
48
|
+
const resource = this.getResourceName(model);
|
|
49
|
+
let permission = user.canReadAny(resource);
|
|
50
|
+
if (!permission.granted) {
|
|
51
|
+
// permission for readAny not granted, check for own
|
|
52
|
+
permission = user.canReadOwn(resource);
|
|
53
|
+
if (permission.granted) {
|
|
54
|
+
if (model.ensureOwnership) {
|
|
55
|
+
model.ensureOwnership(query, user);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
throw new UnexpectedServerError(`Resource ${resource} can be only read by owner and does not have ensureOwnership method implemented`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw new Forbidden(`You do not access to ${resource}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { query, permission };
|
|
66
|
+
}
|
|
67
|
+
async getAll(model, getParams, filters, includes, user) {
|
|
68
|
+
const { query, permission } = this.getSafeQuery(model, user);
|
|
69
|
+
query
|
|
70
|
+
.select('*')
|
|
71
|
+
.populate(includes)
|
|
72
|
+
.order(getParams.order, getParams.orderDirection ?? SortOrder.ASC)
|
|
73
|
+
.skip(getParams.page * getParams.perPage ?? 0)
|
|
74
|
+
.take(getParams.perPage ?? 10);
|
|
75
|
+
// apply basic filters
|
|
76
|
+
for (const filter in filters) {
|
|
77
|
+
const f = filters[filter];
|
|
78
|
+
// if filter have no operator, by default we assume qeuality
|
|
79
|
+
query.where(filter, f.op ? f.op : '=', f.val);
|
|
80
|
+
}
|
|
81
|
+
const count = await query.clone().clearColumns().count('*', 'count').takeFirst().asRaw();
|
|
82
|
+
const result = await query;
|
|
83
|
+
return new Ok({
|
|
84
|
+
Data: result.map((x) => x.dehydrateWithRelations()).map((x) => permission.filter(x)),
|
|
85
|
+
Total: count.count,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
async get(user, model, id, includes) {
|
|
89
|
+
const descriptor = model.getModelDescriptor();
|
|
90
|
+
const { query, permission } = this.getSafeQuery(model, user);
|
|
91
|
+
const result = await query
|
|
92
|
+
.select('*')
|
|
93
|
+
.where(descriptor.PrimaryKey, id)
|
|
94
|
+
.populate(includes)
|
|
95
|
+
.firstOrThrow(new ResourceNotFound(`Record with id ${id} not found`, {
|
|
96
|
+
Resource: model.name,
|
|
97
|
+
[descriptor.PrimaryKey]: id,
|
|
98
|
+
}));
|
|
99
|
+
return new Ok(permission.filter(result.dehydrateWithRelations()));
|
|
100
|
+
}
|
|
101
|
+
async getRelation(model, id, relation, relationId, includes, user) {
|
|
102
|
+
const mDescriptor = model.getModelDescriptor();
|
|
103
|
+
const rDescriptor = model.getRelationDescriptor(relation);
|
|
104
|
+
const rmDescriptor = rDescriptor.TargetModel.getModelDescriptor();
|
|
105
|
+
const { query, permission } = this.getSafeQuery(rDescriptor.TargetModel, user);
|
|
106
|
+
if (!mDescriptor.Relations.has(relation)) {
|
|
107
|
+
return new BadRequest(`Resource ${mDescriptor.Name} does not have relation ${relation} defined`);
|
|
108
|
+
}
|
|
109
|
+
const pExists = await model.exists(id);
|
|
110
|
+
if (!pExists) {
|
|
111
|
+
throw new ResourceNotFound(`Record with id ${id} not found`, {
|
|
112
|
+
Resource: model.name,
|
|
113
|
+
[mDescriptor.PrimaryKey]: id,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const result = await query
|
|
117
|
+
.select('*')
|
|
118
|
+
.populate(includes)
|
|
119
|
+
.where(rmDescriptor.PrimaryKey, relationId)
|
|
120
|
+
.firstOrThrow(new ResourceNotFound(`Record with id ${relationId} not found`, {
|
|
121
|
+
Resource: rDescriptor.TargetModel.name,
|
|
122
|
+
[rmDescriptor.PrimaryKey]: relationId,
|
|
123
|
+
}));
|
|
124
|
+
return new Ok(permission.filter(result.dehydrateWithRelations()));
|
|
125
|
+
}
|
|
126
|
+
async getRelations(model, id, relation, params, filters, includes, user) {
|
|
127
|
+
const mDescriptor = model.getModelDescriptor();
|
|
128
|
+
const rDescriptor = model.getRelationDescriptor(relation);
|
|
129
|
+
const { query, permission } = this.getSafeQuery(rDescriptor.TargetModel, user);
|
|
130
|
+
if (!mDescriptor.Relations.has(relation)) {
|
|
131
|
+
return new BadRequest(`Resource ${mDescriptor.Name} does not have relation ${relation} defined`);
|
|
132
|
+
}
|
|
133
|
+
const pExists = await model.exists(id);
|
|
134
|
+
if (!pExists) {
|
|
135
|
+
throw new ResourceNotFound(`Record with id ${id} not found`, {
|
|
136
|
+
Resource: model.name,
|
|
137
|
+
[mDescriptor.PrimaryKey]: id,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
query
|
|
141
|
+
.where(rDescriptor.ForeignKey, id)
|
|
142
|
+
.select('*')
|
|
143
|
+
.populate(includes)
|
|
144
|
+
.order(params.order, params.orderDirection ?? SortOrder.ASC)
|
|
145
|
+
.skip(params.page * params.perPage ?? 0)
|
|
146
|
+
.take(params.perPage ?? 10);
|
|
147
|
+
// apply basic filters
|
|
148
|
+
for (const filter in filters) {
|
|
149
|
+
const f = filters[filter];
|
|
150
|
+
// if filter have no operator, by default we assume qeuality
|
|
151
|
+
query.where(filter, f.op ? f.op : '=', f.val);
|
|
152
|
+
}
|
|
153
|
+
const count = await query.clone().clearColumns().count('*', 'count').takeFirst().asRaw();
|
|
154
|
+
const result = await query;
|
|
155
|
+
return new Ok({
|
|
156
|
+
Data: result.map((x) => x.dehydrateWithRelations()).map((x) => permission.filter(x)),
|
|
157
|
+
Total: count,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
__decorate([
|
|
162
|
+
Logger('orm-http:api'),
|
|
163
|
+
__metadata("design:type", Log)
|
|
164
|
+
], CrudRead.prototype, "Log", void 0);
|
|
165
|
+
__decorate([
|
|
166
|
+
Autoinject(),
|
|
167
|
+
__metadata("design:type", Orm)
|
|
168
|
+
], CrudRead.prototype, "Orm", void 0);
|
|
169
|
+
__decorate([
|
|
170
|
+
Autoinject(),
|
|
171
|
+
__metadata("design:type", AccessControl)
|
|
172
|
+
], CrudRead.prototype, "Ac", void 0);
|
|
173
|
+
__decorate([
|
|
174
|
+
Get(':model'),
|
|
175
|
+
__param(0, ModelType()),
|
|
176
|
+
__param(1, Query()),
|
|
177
|
+
__param(2, Query()),
|
|
178
|
+
__param(3, Query()),
|
|
179
|
+
__param(4, User()),
|
|
180
|
+
__metadata("design:type", Function),
|
|
181
|
+
__metadata("design:paramtypes", [Object, QueryArgs, QueryFilter, QueryIncludes, UserModel]),
|
|
182
|
+
__metadata("design:returntype", Promise)
|
|
183
|
+
], CrudRead.prototype, "getAll", null);
|
|
184
|
+
__decorate([
|
|
185
|
+
Get(':model/:id'),
|
|
186
|
+
__param(0, User()),
|
|
187
|
+
__param(1, ModelType()),
|
|
188
|
+
__param(2, Param()),
|
|
189
|
+
__param(3, Query()),
|
|
190
|
+
__metadata("design:type", Function),
|
|
191
|
+
__metadata("design:paramtypes", [UserModel, Object, Number, QueryIncludes]),
|
|
192
|
+
__metadata("design:returntype", Promise)
|
|
193
|
+
], CrudRead.prototype, "get", null);
|
|
194
|
+
__decorate([
|
|
195
|
+
Get(':model/:id/:relation/:relationId'),
|
|
196
|
+
__param(0, ModelType()),
|
|
197
|
+
__param(1, Param()),
|
|
198
|
+
__param(2, Param()),
|
|
199
|
+
__param(3, Param()),
|
|
200
|
+
__param(4, Query()),
|
|
201
|
+
__param(5, User()),
|
|
202
|
+
__metadata("design:type", Function),
|
|
203
|
+
__metadata("design:paramtypes", [Object, Object, String, Object, QueryIncludes, UserModel]),
|
|
204
|
+
__metadata("design:returntype", Promise)
|
|
205
|
+
], CrudRead.prototype, "getRelation", null);
|
|
206
|
+
__decorate([
|
|
207
|
+
Get(':model/:id/:relation'),
|
|
208
|
+
__param(0, ModelType()),
|
|
209
|
+
__param(1, Param()),
|
|
210
|
+
__param(2, Param()),
|
|
211
|
+
__param(3, Query()),
|
|
212
|
+
__param(4, Query()),
|
|
213
|
+
__param(5, Query()),
|
|
214
|
+
__param(6, User()),
|
|
215
|
+
__metadata("design:type", Function),
|
|
216
|
+
__metadata("design:paramtypes", [Object, Object, String, QueryArgs, QueryFilter, QueryIncludes, UserModel]),
|
|
217
|
+
__metadata("design:returntype", Promise)
|
|
218
|
+
], CrudRead.prototype, "getRelations", null);
|
|
219
|
+
CrudRead = __decorate([
|
|
220
|
+
BasePath('crud'),
|
|
221
|
+
Policy(FindModelType)
|
|
222
|
+
], CrudRead);
|
|
223
|
+
export { CrudRead };
|
|
224
224
|
//# sourceMappingURL=Read.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Read.js","sourceRoot":"","sources":["../../../../src/controllers/crud/Read.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAgB,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,IAAI,IAAI,SAAS,EAAwB,aAAa,EAAE,MAAM,eAAe,CAAC;AACvF,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACrG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,eAAe,CAAC;AAGvB,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC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
|
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
|