@bearei/server-common 0.0.3 → 0.0.4
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/dist/action-log/action-log.service.js +1 -1
- package/dist/action-log/action-log.service.js.map +1 -1
- package/dist/app.dto.d.ts +1 -2
- package/dist/app.dto.js +4 -9
- package/dist/app.dto.js.map +1 -1
- package/dist/app.entity.js +2 -10
- package/dist/app.entity.js.map +1 -1
- package/dist/app.interface.d.ts +0 -5
- package/dist/app.interface.js.map +1 -1
- package/dist/authentication/access/access.guard.js +3 -3
- package/dist/authentication/access/access.guard.js.map +1 -1
- package/dist/authentication/auth/auth.interface.d.ts +1 -2
- package/dist/authentication/auth/auth.service.d.ts +4 -3
- package/dist/authentication/auth/auth.service.js +4 -4
- package/dist/authentication/auth/auth.service.js.map +1 -1
- package/dist/authentication/permission/permission.guard.js +1 -1
- package/dist/authentication/permission/permission.guard.js.map +1 -1
- package/dist/base/base.interface.d.ts +5 -7
- package/dist/base/base.service.d.ts +4 -4
- package/dist/base/base.service.js +107 -79
- package/dist/base/base.service.js.map +1 -1
- package/dist/base/index.d.ts +1 -0
- package/dist/base/index.js +1 -0
- package/dist/base/index.js.map +1 -1
- package/dist/common.d.ts +1 -0
- package/dist/common.js +36 -1
- package/dist/common.js.map +1 -1
- package/dist/external/external.interface.d.ts +11 -15
- package/dist/external/external.service.d.ts +6 -5
- package/dist/external/external.service.js +35 -37
- package/dist/external/external.service.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/util/error.util.d.ts +2 -2
- package/dist/util/error.util.js +5 -5
- package/dist/util/error.util.js.map +1 -1
- package/dist/util/format.util.d.ts +1 -1
- package/dist/util/format.util.js +1 -1
- package/dist/util/format.util.js.map +1 -1
- package/dist/util/util.interface.d.ts +1 -1
- package/package.json +2 -2
|
@@ -24,7 +24,7 @@ let ActionLogService = class ActionLogService {
|
|
|
24
24
|
return async (data) => this.create({ ...options, result: app_interface_1.ActionResult.FAILURE })(data);
|
|
25
25
|
}
|
|
26
26
|
create({ headers, enableLogging = true, ...args }) {
|
|
27
|
-
return async (data) => enableLogging && (await this.externalService.createActionLog({
|
|
27
|
+
return async (data) => enableLogging && (await this.externalService.createActionLog(headers)({ ...args, data }));
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
exports.ActionLogService = ActionLogService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-log.service.js","sourceRoot":"","sources":["../../src/action-log/action-log.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyC;AACzC,oDAA6C;AAC7C,0CAA2C;AAIpC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACzB,YAA6B,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAAG,CAAC;IAEjE,OAAO,CAAC,OAAyB;QAC7B,OAAO,KAAK,EAAE,IAA6B,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,MAAM,EAAE,4BAAY,CAAC,OAAO,EAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IACjH,CAAC;IAED,OAAO,CAAC,OAAyB;QAC7B,OAAO,KAAK,EAAE,IAA6B,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,MAAM,EAAE,4BAAY,CAAC,OAAO,EAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IACjH,CAAC;IAED,MAAM,CAAC,EAAC,OAAO,EAAE,aAAa,GAAG,IAAI,EAAE,GAAG,IAAI,EAAyB;QACnE,OAAO,KAAK,EAAE,IAA6B,EAAE,EAAE,CAC3C,aAAa,IAAI,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"action-log.service.js","sourceRoot":"","sources":["../../src/action-log/action-log.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyC;AACzC,oDAA6C;AAC7C,0CAA2C;AAIpC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACzB,YAA6B,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAAG,CAAC;IAEjE,OAAO,CAAC,OAAyB;QAC7B,OAAO,KAAK,EAAE,IAA6B,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,MAAM,EAAE,4BAAY,CAAC,OAAO,EAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IACjH,CAAC;IAED,OAAO,CAAC,OAAyB;QAC7B,OAAO,KAAK,EAAE,IAA6B,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAC,GAAG,OAAO,EAAE,MAAM,EAAE,4BAAY,CAAC,OAAO,EAAC,CAAC,CAAC,IAAI,CAAC,CAAA;IACjH,CAAC;IAED,MAAM,CAAC,EAAC,OAAO,EAAE,aAAa,GAAG,IAAI,EAAE,GAAG,IAAI,EAAyB;QACnE,OAAO,KAAK,EAAE,IAA6B,EAAE,EAAE,CAC3C,aAAa,IAAI,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,EAAC,GAAG,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC,CAAA;IAC/F,CAAC;CACJ,CAAA;AAfY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;qCAEqC,0BAAe;GADpD,gBAAgB,CAe5B"}
|
package/dist/app.dto.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ValidationOptions } from 'class-validator';
|
|
2
|
-
import {
|
|
2
|
+
import { Order } from './app.interface';
|
|
3
3
|
export declare const IsNanoid: (validationOptions?: ValidationOptions) => (object: Record<string, any>, propertyName: string) => void;
|
|
4
4
|
export declare class IndexDTO {
|
|
5
5
|
projectId?: string;
|
|
@@ -9,7 +9,6 @@ export declare class IndexDTO {
|
|
|
9
9
|
size?: number;
|
|
10
10
|
count?: boolean;
|
|
11
11
|
order?: keyof typeof Order;
|
|
12
|
-
language?: keyof typeof Language;
|
|
13
12
|
ids?: string[];
|
|
14
13
|
createdAtRange?: string[];
|
|
15
14
|
}
|
package/dist/app.dto.js
CHANGED
|
@@ -48,7 +48,6 @@ __decorate([
|
|
|
48
48
|
], IndexDTO.prototype, "id", void 0);
|
|
49
49
|
__decorate([
|
|
50
50
|
(0, class_validator_1.IsNumber)({ allowNaN: false }),
|
|
51
|
-
(0, class_validator_1.Max)(1024),
|
|
52
51
|
(0, class_validator_1.Min)(1),
|
|
53
52
|
(0, class_transformer_1.Transform)(({ value }) => parseInt(value)),
|
|
54
53
|
__metadata("design:type", Number)
|
|
@@ -61,28 +60,24 @@ __decorate([
|
|
|
61
60
|
__metadata("design:type", Number)
|
|
62
61
|
], IndexDTO.prototype, "size", void 0);
|
|
63
62
|
__decorate([
|
|
64
|
-
(0, class_transformer_1.Transform)(({ value }) => value === 'true'),
|
|
65
63
|
(0, class_validator_1.IsBoolean)(),
|
|
64
|
+
(0, class_transformer_1.Transform)(({ value }) => (typeof value === 'string' ? value === 'true' : value)),
|
|
66
65
|
__metadata("design:type", Boolean)
|
|
67
66
|
], IndexDTO.prototype, "count", void 0);
|
|
68
67
|
__decorate([
|
|
69
68
|
(0, class_validator_1.IsEnum)(common_1.ORDER),
|
|
70
69
|
__metadata("design:type", Object)
|
|
71
70
|
], IndexDTO.prototype, "order", void 0);
|
|
72
|
-
__decorate([
|
|
73
|
-
(0, class_validator_1.IsEnum)(common_1.LANGUAGE),
|
|
74
|
-
__metadata("design:type", Object)
|
|
75
|
-
], IndexDTO.prototype, "language", void 0);
|
|
76
71
|
__decorate([
|
|
77
72
|
(0, class_validator_1.ArrayMaxSize)(1024),
|
|
78
|
-
(0, class_validator_1.ArrayMinSize)(
|
|
73
|
+
(0, class_validator_1.ArrayMinSize)(0),
|
|
79
74
|
(0, exports.IsNanoid)({ each: true }),
|
|
80
75
|
(0, class_transformer_1.Transform)(({ value }) => (typeof value === 'string' ? value.split(',') : value)),
|
|
81
76
|
__metadata("design:type", Array)
|
|
82
77
|
], IndexDTO.prototype, "ids", void 0);
|
|
83
78
|
__decorate([
|
|
84
79
|
(0, class_validator_1.ArrayMaxSize)(2),
|
|
85
|
-
(0, class_validator_1.ArrayMinSize)(
|
|
80
|
+
(0, class_validator_1.ArrayMinSize)(0),
|
|
86
81
|
(0, exports.IsNanoid)({ each: true }),
|
|
87
82
|
(0, class_transformer_1.Transform)(({ value }) => (typeof value === 'string' ? value.split(',') : value)),
|
|
88
83
|
__metadata("design:type", Array)
|
|
@@ -99,7 +94,7 @@ class ByIdsDTO {
|
|
|
99
94
|
exports.ByIdsDTO = ByIdsDTO;
|
|
100
95
|
__decorate([
|
|
101
96
|
(0, class_validator_1.ArrayMaxSize)(1024),
|
|
102
|
-
(0, class_validator_1.ArrayMinSize)(
|
|
97
|
+
(0, class_validator_1.ArrayMinSize)(0),
|
|
103
98
|
(0, exports.IsNanoid)({ each: true }),
|
|
104
99
|
(0, class_transformer_1.Transform)(({ value }) => (typeof value === 'string' ? value.split(',') : value)),
|
|
105
100
|
__metadata("design:type", String)
|
package/dist/app.dto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.dto.js","sourceRoot":"","sources":["../src/app.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAA2C;AAC3C,qDAUwB;AAExB,
|
|
1
|
+
{"version":3,"file":"app.dto.js","sourceRoot":"","sources":["../src/app.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAA2C;AAC3C,qDAUwB;AAExB,qCAA8B;AAEvB,MAAM,QAAQ,GACjB,CAAC,iBAAqC,EAAE,EAAE,CAAC,CAAC,MAA2B,EAAE,YAAoB,EAAE,EAAE;IAC7F,IAAA,mCAAiB,EAAC;QACd,IAAI,EAAE,UAAU;Q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AAA,gBAAQ,GAAE;;uCACG"}
|
package/dist/app.entity.js
CHANGED
|
@@ -21,7 +21,6 @@ exports.AppEntity = AppEntity;
|
|
|
21
21
|
__decorate([
|
|
22
22
|
(0, typeorm_1.PrimaryColumn)({
|
|
23
23
|
length: 32,
|
|
24
|
-
name: 'id',
|
|
25
24
|
nullable: false,
|
|
26
25
|
type: 'varchar'
|
|
27
26
|
}),
|
|
@@ -30,7 +29,6 @@ __decorate([
|
|
|
30
29
|
__decorate([
|
|
31
30
|
(0, typeorm_1.Column)({
|
|
32
31
|
length: 32,
|
|
33
|
-
name: 'project_id',
|
|
34
32
|
nullable: false,
|
|
35
33
|
type: 'varchar'
|
|
36
34
|
}),
|
|
@@ -38,9 +36,8 @@ __decorate([
|
|
|
38
36
|
], AppEntity.prototype, "projectId", void 0);
|
|
39
37
|
__decorate([
|
|
40
38
|
(0, typeorm_1.Column)({
|
|
41
|
-
default: '',
|
|
39
|
+
default: 'ei',
|
|
42
40
|
length: 32,
|
|
43
|
-
name: 'scope_id',
|
|
44
41
|
nullable: false,
|
|
45
42
|
type: 'varchar'
|
|
46
43
|
}),
|
|
@@ -48,7 +45,6 @@ __decorate([
|
|
|
48
45
|
], AppEntity.prototype, "scopeId", void 0);
|
|
49
46
|
__decorate([
|
|
50
47
|
(0, typeorm_1.Column)({
|
|
51
|
-
name: 'created_at',
|
|
52
48
|
nullable: false,
|
|
53
49
|
type: 'date'
|
|
54
50
|
}),
|
|
@@ -56,7 +52,6 @@ __decorate([
|
|
|
56
52
|
], AppEntity.prototype, "createdAt", void 0);
|
|
57
53
|
__decorate([
|
|
58
54
|
(0, typeorm_1.Column)({
|
|
59
|
-
name: 'updated_at',
|
|
60
55
|
nullable: false,
|
|
61
56
|
type: 'date'
|
|
62
57
|
}),
|
|
@@ -64,16 +59,13 @@ __decorate([
|
|
|
64
59
|
], AppEntity.prototype, "updatedAt", void 0);
|
|
65
60
|
__decorate([
|
|
66
61
|
(0, typeorm_1.Column)({
|
|
67
|
-
name: 'deleted_at',
|
|
68
62
|
type: 'date'
|
|
69
63
|
}),
|
|
70
64
|
__metadata("design:type", Date)
|
|
71
65
|
], AppEntity.prototype, "deletedAt", void 0);
|
|
72
66
|
__decorate([
|
|
73
67
|
(0, typeorm_1.VersionColumn)({
|
|
74
|
-
|
|
75
|
-
nullable: false,
|
|
76
|
-
type: 'bigint'
|
|
68
|
+
nullable: false
|
|
77
69
|
}),
|
|
78
70
|
__metadata("design:type", String)
|
|
79
71
|
], AppEntity.prototype, "version", void 0);
|
package/dist/app.entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.entity.js","sourceRoot":"","sources":["../src/app.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAA6B;AAC7B,qCAA6F;AAGtF,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,oBAAU;
|
|
1
|
+
{"version":3,"file":"app.entity.js","sourceRoot":"","sources":["../src/app.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAA6B;AAC7B,qCAA6F;AAGtF,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,oBAAU;IA8CrC,YAAY;QACR,IAAI,CAAC,EAAE,GAAG,IAAA,eAAM,GAAE,CAAA;IACtB,CAAC;CACJ,CAAA;AAjDY,8BAAS;AAMlB;IALC,IAAA,uBAAa,EAAC;QACX,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,KAAK;QACf,IAAI,EAAE,SAAS;KAClB,CAAC;;qCACQ;AAOV;IALC,IAAA,gBAAM,EAAC;QACJ,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,KAAK;QACf,IAAI,EAAE,SAAS;KAClB,CAAC;;4CACe;AAQjB;IANC,IAAA,gBAAM,EAAC;QACJ,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,KAAK;QACf,IAAI,EAAE,SAAS;KAClB,CAAC;;0CACa;AAMf;IAJC,IAAA,gBAAM,EAAC;QACJ,QAAQ,EAAE,KAAK;QACf,IAAI,EAAE,MAAM;KACf,CAAC;8BACS,IAAI;4CAAA;AAMf;IAJC,IAAA,gBAAM,EAAC;QACJ,QAAQ,EAAE,KAAK;QACf,IAAI,EAAE,MAAM;KACf,CAAC;8BACS,IAAI;4CAAA;AAKf;IAHC,IAAA,gBAAM,EAAC;QACJ,IAAI,EAAE,MAAM;KACf,CAAC;8BACS,IAAI;4CAAA;AAKf;IAHC,IAAA,uBAAa,EAAC;QACX,QAAQ,EAAE,KAAK;KAClB,CAAC;;0CACa;AAGf;IADC,IAAA,sBAAY,GAAE;;;;6CAGd;oBAhDQ,SAAS;IADrB,IAAA,eAAK,EAAC,CAAC,WAAW,CAAC,CAAC;GACR,SAAS,CAiDrB"}
|
package/dist/app.interface.d.ts
CHANGED
|
@@ -3,15 +3,12 @@ export declare enum Language {
|
|
|
3
3
|
EN_US = "enUS",
|
|
4
4
|
ZH_CN = "zhCN"
|
|
5
5
|
}
|
|
6
|
-
export type LanguageType = 'EN_US' | 'ZH_CN';
|
|
7
6
|
export declare enum Order {
|
|
8
7
|
ASC = "asc",
|
|
9
8
|
DESC = "desc"
|
|
10
9
|
}
|
|
11
|
-
export type OrderType = 'ASC' | 'DESC';
|
|
12
10
|
export type CustomHeaders = Record<'x-project-id' | 'x-scope-id' | 'x-authorization' | 'x-ip' | 'x-client' | 'x-request-id' | 'x-internal', string>;
|
|
13
11
|
export type APIHeaders = Record<string, string> | CustomHeaders | AxiosRequestConfig['headers'];
|
|
14
|
-
export type APIErrorType = 'FORBIDDEN' | 'HTTP_EXCEPTION' | 'INTERNAL_SERVER_ERROR' | 'NOT_FOUND' | 'UNAUTHORIZED' | 'UNPROCESSABLE_ENTITY';
|
|
15
12
|
export declare enum APIError {
|
|
16
13
|
FORBIDDEN = "forbidden",
|
|
17
14
|
HTTP_EXCEPTION = "HttpException",
|
|
@@ -20,12 +17,10 @@ export declare enum APIError {
|
|
|
20
17
|
UNAUTHORIZED = "unauthorized",
|
|
21
18
|
UNPROCESSABLE_ENTITY = "unprocessableEntity"
|
|
22
19
|
}
|
|
23
|
-
export type ActionResultType = 'FAILURE' | 'SUCCESS';
|
|
24
20
|
export declare enum ActionResult {
|
|
25
21
|
FAILURE = "failure",
|
|
26
22
|
SUCCESS = "success"
|
|
27
23
|
}
|
|
28
|
-
export type ActionType = 'CREATE' | 'DELETE' | 'EXPORT' | 'IMPORT' | 'SIGN_IN' | 'SIGN_OUT' | 'SIGN_UP' | 'UPDATE';
|
|
29
24
|
export declare enum Action {
|
|
30
25
|
CREATE = "create",
|
|
31
26
|
DELETE = "delete",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.interface.js","sourceRoot":"","sources":["../src/app.interface.ts"],"names":[],"mappings":";;;AAEA,IAAY,QAGX;AAHD,WAAY,QAAQ;IAChB,0BAAc,CAAA;IACd,0BAAc,CAAA;AAClB,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB;
|
|
1
|
+
{"version":3,"file":"app.interface.js","sourceRoot":"","sources":["../src/app.interface.ts"],"names":[],"mappings":";;;AAEA,IAAY,QAGX;AAHD,WAAY,QAAQ;IAChB,0BAAc,CAAA;IACd,0BAAc,CAAA;AAClB,CAAC,EAHW,QAAQ,wBAAR,QAAQ,QAGnB;AAED,IAAY,KAGX;AAHD,WAAY,KAAK;IACb,oBAAW,CAAA;IACX,sBAAa,CAAA;AACjB,CAAC,EAHW,KAAK,qBAAL,KAAK,QAGhB;AAQD,IAAY,QAOX;AAPD,WAAY,QAAQ;IAChB,mCAAuB,CAAA;IACvB,4CAAgC,CAAA;IAChC,2DAA+C,CAAA;IAC/C,kCAAsB,CAAA;IACtB,yCAA6B,CAAA;IAC7B,wDAA4C,CAAA;AAChD,CAAC,EAPW,QAAQ,wBAAR,QAAQ,QAOnB;AAED,IAAY,YAGX;AAHD,WAAY,YAAY;IACpB,mCAAmB,CAAA;IACnB,mCAAmB,CAAA;AACvB,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAED,IAAY,MASX;AATD,WAAY,MAAM;IACd,2BAAiB,CAAA;IACjB,2BAAiB,CAAA;IACjB,2BAAiB,CAAA;IACjB,2BAAiB,CAAA;IACjB,4BAAkB,CAAA;IAClB,8BAAoB,CAAA;IACpB,4BAAkB,CAAA;IAClB,2BAAiB,CAAA;AACrB,CAAC,EATW,MAAM,sBAAN,MAAM,QASjB"}
|
|
@@ -36,15 +36,15 @@ let AuthGuard = class AuthGuard {
|
|
|
36
36
|
}
|
|
37
37
|
const token = (0, util_1.formatToken)(headers);
|
|
38
38
|
!token &&
|
|
39
|
-
(0, util_1.
|
|
39
|
+
(0, util_1.throwAPIError)({
|
|
40
40
|
code: 401004,
|
|
41
41
|
message: 'No required authentication token found; a token is essential for access authentication'
|
|
42
42
|
})(app_interface_1.APIError.UNAUTHORIZED);
|
|
43
|
-
return this.authService.authAccess(
|
|
43
|
+
return this.authService.authAccess(headers).then(payload => {
|
|
44
44
|
payload.sub === 'guest' &&
|
|
45
45
|
requiredAccesses &&
|
|
46
46
|
!requiredAccesses.includes(access_interface_1.Access.GUEST) &&
|
|
47
|
-
(0, util_1.
|
|
47
|
+
(0, util_1.throwAPIError)({
|
|
48
48
|
code: 401005,
|
|
49
49
|
message: 'The current resource is not accessible to guest users'
|
|
50
50
|
})(app_interface_1.APIError.UNAUTHORIZED);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"access.guard.js","sourceRoot":"","sources":["../../../src/authentication/access/access.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAwE;AACxE,uCAAsC;AACtC,uDAAiD;AACjD,uDAA4C;AAE5C,
|
|
1
|
+
{"version":3,"file":"access.guard.js","sourceRoot":"","sources":["../../../src/authentication/access/access.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAwE;AACxE,uCAAsC;AACtC,uDAAiD;AACjD,uDAA4C;AAE5C,qCAAqD;AACrD,kCAAmC;AACnC,yD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E,MAAM;oBACZ,OAAO,EAAE,uDAAuD;iBACnE,CAAC,CAAC,wBAAQ,CAAC,YAAY,CAAC,CAAA;YAE7B,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAA;YAEzB,OAAO,IAAI,CAAA;QACf,CAAC,CAAC,CAAA;IACN,CAAC;CACJ,CAAA;AA3CY,8BAAS;oBAAT,SAAS;IADrB,IAAA,mBAAU,GAAE;qCAGyB,kBAAW;QACb,gBAAS;GAHhC,SAAS,CA2CrB"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type AuthAccessOptions = AuthExternalAccessOptions;
|
|
1
|
+
import { AuthExternalPermissionOptions } from '../../external';
|
|
3
2
|
export type AuthPermissionOptions = AuthExternalPermissionOptions;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { APIHeaders } from '../../app.interface';
|
|
1
2
|
import { ExternalService } from '../../external';
|
|
2
|
-
import {
|
|
3
|
+
import { AuthPermissionOptions } from './auth.interface';
|
|
3
4
|
export declare class AuthService {
|
|
4
5
|
private readonly externalService;
|
|
5
6
|
constructor(externalService: ExternalService);
|
|
6
|
-
authAccess(
|
|
7
|
-
authPermission(options: AuthPermissionOptions)
|
|
7
|
+
authAccess(headers: APIHeaders): Promise<import("../../external").AuthenticatedToken>;
|
|
8
|
+
authPermission(headers: APIHeaders): (options: AuthPermissionOptions) => Promise<import("../../external").AuthenticatedPermission>;
|
|
8
9
|
}
|
|
@@ -16,11 +16,11 @@ let AuthService = class AuthService {
|
|
|
16
16
|
constructor(externalService) {
|
|
17
17
|
this.externalService = externalService;
|
|
18
18
|
}
|
|
19
|
-
async authAccess(
|
|
20
|
-
return this.externalService.authAccess(
|
|
19
|
+
async authAccess(headers) {
|
|
20
|
+
return this.externalService.authAccess(headers);
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
return this.externalService.authPermission(options);
|
|
22
|
+
authPermission(headers) {
|
|
23
|
+
return async (options) => this.externalService.authPermission(headers)(options);
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
exports.AuthService = AuthService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../../src/authentication/auth/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyC;
|
|
1
|
+
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../../src/authentication/auth/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyC;AAEzC,6CAA8C;AAIvC,IAAM,WAAW,GAAjB,MAAM,WAAW;IACpB,YAA6B,eAAgC;QAAhC,oBAAe,GAAf,eAAe,CAAiB;IAAG,CAAC;IAEjE,KAAK,CAAC,UAAU,CAAC,OAAmB;QAChC,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;IACnD,CAAC;IAED,cAAc,CAAC,OAAmB;QAC9B,OAAO,KAAK,EAAE,OAA8B,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAA;IAC1G,CAAC;CACJ,CAAA;AAVY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;qCAEqC,0BAAe;GADpD,WAAW,CAUvB"}
|
|
@@ -33,7 +33,7 @@ let PermissionGuard = class PermissionGuard {
|
|
|
33
33
|
return true;
|
|
34
34
|
}
|
|
35
35
|
return this.authService
|
|
36
|
-
.authPermission({
|
|
36
|
+
.authPermission(headers)({ keys: requiredPermissions, userId: user.sub })
|
|
37
37
|
.then(({ result }) => result === 'successes');
|
|
38
38
|
}
|
|
39
39
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permission.guard.js","sourceRoot":"","sources":["../../../src/authentication/permission/permission.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAwE;AACxE,uCAAsC;AACtC,uDAAwD;AAExD,kCAAmC;AAI5B,IAAM,eAAe,GAArB,MAAM,eAAe;IACxB,YACqB,WAAwB,EACxB,SAAoB;QADpB,gBAAW,GAAX,WAAW,CAAa;QACxB,cAAS,GAAT,SAAS,CAAW;IACtC,CAAC;IAEJ,WAAW,CAAC,OAAyB;QACjC,MAAM,mBAAmB,GAAiB,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,oCAAoB,EAAE;YAC7F,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SACrB,CAAC,CAAA;QAEF,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACvB,OAAO,IAAI,CAAA;QACf,CAAC;QAED,MAAM,EAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAC,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAc,CAAA;QAC/E,MAAM,MAAM,GAAG,IAAI,EAAE,GAAG,KAAK,MAAM,CAAC,EAAE,CAAA;QAEtC,IAAI,OAAO,CAAC,YAAY,CAAC,IAAI,MAAM,EAAE,CAAC;YAClC,OAAO,IAAI,CAAA;QACf,CAAC;QAED,OAAO,IAAI,CAAC,WAAW;aAClB,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"permission.guard.js","sourceRoot":"","sources":["../../../src/authentication/permission/permission.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAwE;AACxE,uCAAsC;AACtC,uDAAwD;AAExD,kCAAmC;AAI5B,IAAM,eAAe,GAArB,MAAM,eAAe;IACxB,YACqB,WAAwB,EACxB,SAAoB;QADpB,gBAAW,GAAX,WAAW,CAAa;QACxB,cAAS,GAAT,SAAS,CAAW;IACtC,CAAC;IAEJ,WAAW,CAAC,OAAyB;QACjC,MAAM,mBAAmB,GAAiB,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,oCAAoB,EAAE;YAC7F,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SACrB,CAAC,CAAA;QAEF,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACvB,OAAO,IAAI,CAAA;QACf,CAAC;QAED,MAAM,EAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAC,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAc,CAAA;QAC/E,MAAM,MAAM,GAAG,IAAI,EAAE,GAAG,KAAK,MAAM,CAAC,EAAE,CAAA;QAEtC,IAAI,OAAO,CAAC,YAAY,CAAC,IAAI,MAAM,EAAE,CAAC;YAClC,OAAO,IAAI,CAAA;QACf,CAAC;QAED,OAAO,IAAI,CAAC,WAAW;aAClB,cAAc,CAAC,OAAO,CAAC,CAAC,EAAC,IAAI,EAAE,mBAAmB,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,EAAC,CAAC;aACtE,IAAI,CAAC,CAAC,EAAC,MAAM,EAAC,EAAE,EAAE,CAAC,MAAM,KAAK,WAAW,CAAC,CAAA;IACnD,CAAC;CACJ,CAAA;AA3BY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;qCAGyB,kBAAW;QACb,gBAAS;GAHhC,eAAe,CA2B3B"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EntityManager, FindManyOptions, FindOptionsWhere } from 'typeorm';
|
|
2
2
|
import { ActionLogOptions } from '../action-log';
|
|
3
3
|
import { IndexDTO, NotIdDTO } from '../app.dto';
|
|
4
4
|
import { APIError, APIHeaders } from '../app.interface';
|
|
5
|
+
import { ThrowAPIErrorOptions } from '../util';
|
|
5
6
|
export interface BaseServiceOptions<T> extends Pick<ActionLogOptions, 'enableLogging'> {
|
|
6
7
|
entityManager?: EntityManager;
|
|
7
|
-
entityOptions:
|
|
8
|
+
entityOptions: T;
|
|
8
9
|
findOptions: FindOptionsWhere<T>;
|
|
9
10
|
headers: APIHeaders;
|
|
10
11
|
preValidateOptions?: Omit<PreValidateOptions<T>, 'serviceName' | 'actionLogOptions'>;
|
|
@@ -17,9 +18,8 @@ export interface UpdateOptions<T> extends Omit<BaseServiceOptions<T>, 'preValida
|
|
|
17
18
|
validateKeys?: (keyof FindOptionsWhere<T>)[];
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
|
-
export interface
|
|
21
|
+
export interface UpdateAssociationOptions<T> extends Omit<BaseServiceOptions<T>, 'entityOptions'> {
|
|
21
22
|
entityIds: string[];
|
|
22
|
-
linkKey: string;
|
|
23
23
|
}
|
|
24
24
|
export interface FindOptions<T> {
|
|
25
25
|
findManyOptions?: FindManyOptions<T>;
|
|
@@ -35,8 +35,6 @@ export interface PreValidateOptions<T> {
|
|
|
35
35
|
validateKeys?: (keyof FindOptionsWhere<T>)[][] | (keyof FindOptionsWhere<T>)[];
|
|
36
36
|
validateMethod?: 'and' | 'or';
|
|
37
37
|
}
|
|
38
|
-
export interface ThrowErrorOptions {
|
|
39
|
-
code?: number;
|
|
38
|
+
export interface ThrowErrorOptions extends ThrowAPIErrorOptions {
|
|
40
39
|
errorType: APIError;
|
|
41
|
-
message: string;
|
|
42
40
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Repository } from 'typeorm';
|
|
2
2
|
import { ActionLogOptions, ActionLogService } from '../action-log';
|
|
3
3
|
import { AppEntity } from '../app.entity';
|
|
4
|
-
import { CreateOptions, DelOptions, FindOneOptions, FindOptions, PreValidateOptions, ThrowErrorOptions,
|
|
4
|
+
import { CreateOptions, DelOptions, FindOneOptions, FindOptions, PreValidateOptions, ThrowErrorOptions, UpdateAssociationOptions, UpdateOptions } from './base.interface';
|
|
5
5
|
export declare class BaseService {
|
|
6
6
|
private readonly actionLogService;
|
|
7
7
|
constructor(actionLogService: ActionLogService);
|
|
8
8
|
create<T extends AppEntity>({ enableLogging, entityManager, entityOptions, headers, preValidateOptions, serviceName }: CreateOptions<T>): (repository: Repository<T>) => Promise<T>;
|
|
9
9
|
del<T extends AppEntity>({ entityManager, findOptions, serviceName, headers, enableLogging }: DelOptions<T>): (repository: Repository<T>) => Promise<void>;
|
|
10
|
-
update<T extends AppEntity>({ enableLogging, entityManager, entityOptions, findOptions, headers, preValidateOptions, serviceName }: UpdateOptions<T>):
|
|
10
|
+
update<T extends AppEntity>({ enableLogging, entityManager, entityOptions, findOptions, headers, preValidateOptions, serviceName }: UpdateOptions<T>): (repository: Repository<T>) => Promise<T>;
|
|
11
11
|
find<T extends AppEntity>({ findOptions, findManyOptions }: FindOptions<T>): (repository: Repository<T>) => Promise<{
|
|
12
12
|
results: T[];
|
|
13
13
|
limit: number;
|
|
@@ -15,8 +15,8 @@ export declare class BaseService {
|
|
|
15
15
|
total: number;
|
|
16
16
|
}>;
|
|
17
17
|
findOne<T extends AppEntity>({ serviceName, findOptions, actionLogOptions }: FindOneOptions<T>): (repository: Repository<T>) => Promise<T>;
|
|
18
|
-
|
|
19
|
-
preValidate<T extends AppEntity>({ actionLogOptions, findOptions, serviceName, validateKeys, validateMethod }: PreValidateOptions<T>): (repository: Repository<T>) => Promise<void
|
|
18
|
+
updateAssociation<T extends AppEntity>({ enableLogging, entityIds: rawEntityIds, entityManager, findOptions, headers, serviceName }: UpdateAssociationOptions<T>): (associationKey: string) => (repository: Repository<T>) => Promise<T[]>;
|
|
19
|
+
preValidate<T extends AppEntity>({ actionLogOptions, findOptions, serviceName, validateKeys, validateMethod }: PreValidateOptions<T>): Promise<(repository: Repository<T>) => Promise<void>>;
|
|
20
20
|
checkProhibited<T extends AppEntity>(actionLogOptions?: ActionLogOptions): (entity: T & {
|
|
21
21
|
protected?: boolean;
|
|
22
22
|
}) => Promise<void>;
|
|
@@ -20,10 +20,17 @@ let BaseService = class BaseService {
|
|
|
20
20
|
this.actionLogService = actionLogService;
|
|
21
21
|
}
|
|
22
22
|
create({ enableLogging, entityManager, entityOptions, headers, preValidateOptions, serviceName }) {
|
|
23
|
+
const actionLogOptions = {
|
|
24
|
+
action: app_interface_1.Action.CREATE,
|
|
25
|
+
enableLogging,
|
|
26
|
+
headers,
|
|
27
|
+
message: `Create a ${serviceName}`,
|
|
28
|
+
raw: { entityOptions },
|
|
29
|
+
serviceName
|
|
30
|
+
};
|
|
23
31
|
return async (repository) => {
|
|
24
|
-
const actionLogOptions = { action: app_interface_1.Action.CREATE, enableLogging, headers, data: { entityOptions }, serviceName };
|
|
25
32
|
preValidateOptions &&
|
|
26
|
-
(await this.preValidate({ ...preValidateOptions, serviceName, actionLogOptions })(repository));
|
|
33
|
+
(await (await this.preValidate({ ...preValidateOptions, serviceName, actionLogOptions }))(repository));
|
|
27
34
|
const createdEntity = repository.create(entityOptions);
|
|
28
35
|
const entity = await (entityManager ? entityManager.save(createdEntity) : createdEntity.save());
|
|
29
36
|
await this.actionLogSuccess(actionLogOptions)(entity);
|
|
@@ -31,69 +38,71 @@ let BaseService = class BaseService {
|
|
|
31
38
|
};
|
|
32
39
|
}
|
|
33
40
|
del({ entityManager, findOptions, serviceName, headers, enableLogging }) {
|
|
41
|
+
const actionLogOptions = {
|
|
42
|
+
action: app_interface_1.Action.DELETE,
|
|
43
|
+
enableLogging,
|
|
44
|
+
headers,
|
|
45
|
+
message: `Delete a ${serviceName}`,
|
|
46
|
+
serviceName
|
|
47
|
+
};
|
|
34
48
|
return async (repository) => {
|
|
35
|
-
const actionLogOptions = { action: app_interface_1.Action.DELETE, enableLogging, headers, data: { findOptions }, serviceName };
|
|
36
49
|
const entity = await this.findOne({ serviceName, findOptions, actionLogOptions })(repository);
|
|
50
|
+
const raw = enableLogging ? { findOptions, entity: { ...entity } } : undefined;
|
|
37
51
|
await this.checkProhibited(actionLogOptions)(entity);
|
|
38
|
-
const nextActionLogOptions = {
|
|
39
|
-
...actionLogOptions,
|
|
40
|
-
data: { ...actionLogOptions.data, entity: { ...entity } }
|
|
41
|
-
};
|
|
42
52
|
await entity.softRemove();
|
|
43
53
|
await (entityManager ? entityManager.save(entity) : entity.save());
|
|
44
|
-
await this.actionLogSuccess(
|
|
54
|
+
await this.actionLogSuccess({ ...actionLogOptions, raw })(entity);
|
|
45
55
|
};
|
|
46
56
|
}
|
|
47
|
-
|
|
57
|
+
update({ enableLogging, entityManager, entityOptions, findOptions, headers, preValidateOptions, serviceName }) {
|
|
58
|
+
const actionLogOptions = {
|
|
59
|
+
action: app_interface_1.Action.UPDATE,
|
|
60
|
+
enableLogging,
|
|
61
|
+
headers,
|
|
62
|
+
message: `Update a ${serviceName}`,
|
|
63
|
+
serviceName
|
|
64
|
+
};
|
|
48
65
|
return async (repository) => {
|
|
49
|
-
const actionLogOptions = {
|
|
50
|
-
action: app_interface_1.Action.UPDATE,
|
|
51
|
-
enableLogging,
|
|
52
|
-
headers,
|
|
53
|
-
raw: { findOptions, entityOptions },
|
|
54
|
-
serviceName
|
|
55
|
-
};
|
|
56
66
|
const entity = await this.findOne({ actionLogOptions, findOptions, serviceName })(repository);
|
|
57
|
-
|
|
67
|
+
const raw = enableLogging ? { findOptions, entity: { ...entity }, entityOptions } : undefined;
|
|
68
|
+
const nextActionLogOptions = { ...actionLogOptions, raw };
|
|
69
|
+
await this.checkProhibited(nextActionLogOptions)(entity);
|
|
58
70
|
if (preValidateOptions) {
|
|
59
71
|
const { validateKeys = [], ...args } = preValidateOptions;
|
|
60
72
|
const preValidateKeys = [
|
|
61
73
|
...new Set([...Object.keys(preValidateOptions.findOptions), ...validateKeys])
|
|
62
74
|
];
|
|
63
75
|
const findOptions = preValidateKeys
|
|
76
|
+
.filter(key => key === 'id')
|
|
64
77
|
.map(key => ({ [key]: entityOptions[key] ?? entity[key] }))
|
|
65
78
|
.reduce((acc, cur) => ({ ...acc, ...cur }), {});
|
|
66
|
-
await this.preValidate({
|
|
79
|
+
await (await this.preValidate({
|
|
67
80
|
...args,
|
|
68
|
-
actionLogOptions,
|
|
81
|
+
actionLogOptions: nextActionLogOptions,
|
|
69
82
|
findOptions: { ...findOptions, notId: entity.id },
|
|
70
83
|
serviceName
|
|
71
|
-
})(repository);
|
|
84
|
+
}))(repository);
|
|
72
85
|
}
|
|
73
|
-
const nextActionLogOptions = {
|
|
74
|
-
...actionLogOptions,
|
|
75
|
-
data: { ...actionLogOptions.raw, entity: { ...entity } }
|
|
76
|
-
};
|
|
77
86
|
repository.merge(entity, entityOptions);
|
|
78
87
|
await (entityManager ? entityManager.save(entity) : entity.save());
|
|
79
|
-
await this.actionLogSuccess(
|
|
88
|
+
await this.actionLogSuccess({ ...actionLogOptions, raw })(entity);
|
|
80
89
|
return entity;
|
|
81
90
|
};
|
|
82
91
|
}
|
|
83
92
|
find({ findOptions, findManyOptions }) {
|
|
93
|
+
const { page = 1, size = 10, order = 'ASC', count = false, createdAtRange, ids, ...args } = findOptions;
|
|
94
|
+
const isCount = count && page === 1;
|
|
95
|
+
const limit = size;
|
|
96
|
+
const offset = (page - 1) * size;
|
|
97
|
+
const where = {
|
|
98
|
+
...args,
|
|
99
|
+
...(ids && { id: (0, typeorm_1.In)(ids) }),
|
|
100
|
+
...(createdAtRange && {
|
|
101
|
+
createdAt: (0, typeorm_1.Between)(createdAtRange[0], createdAtRange[1])
|
|
102
|
+
})
|
|
103
|
+
};
|
|
104
|
+
const orderOptions = { createdAt: order };
|
|
84
105
|
return async (repository) => {
|
|
85
|
-
const { page = 1, size = 10, order = 'ASC', count = false, createdAtRange, ids, ...args } = findOptions;
|
|
86
|
-
const isCount = count && page === 1;
|
|
87
|
-
const limit = size;
|
|
88
|
-
const offset = (page - 1) * size;
|
|
89
|
-
const where = {
|
|
90
|
-
...args,
|
|
91
|
-
...(ids && { id: (0, typeorm_1.In)(ids) }),
|
|
92
|
-
...(createdAtRange && {
|
|
93
|
-
createdAt: (0, typeorm_1.Between)(createdAtRange[0], createdAtRange[1])
|
|
94
|
-
})
|
|
95
|
-
};
|
|
96
|
-
const orderOptions = { createdAt: order };
|
|
97
106
|
const [entities, total] = await Promise.all([
|
|
98
107
|
repository.find({ ...findManyOptions, order: orderOptions, skip: offset, take: limit, where }),
|
|
99
108
|
isCount ? repository.count({ where }) : undefined
|
|
@@ -114,61 +123,80 @@ let BaseService = class BaseService {
|
|
|
114
123
|
return entity;
|
|
115
124
|
};
|
|
116
125
|
}
|
|
117
|
-
|
|
118
|
-
return
|
|
126
|
+
updateAssociation({ enableLogging, entityIds: rawEntityIds, entityManager, findOptions, headers, serviceName }) {
|
|
127
|
+
return (associationKey) => {
|
|
119
128
|
const size = 1024;
|
|
120
|
-
const
|
|
129
|
+
const entityIds = [...new Set(rawEntityIds)];
|
|
121
130
|
const actionLogOptions = {
|
|
122
131
|
action: app_interface_1.Action.UPDATE,
|
|
123
132
|
enableLogging,
|
|
124
133
|
headers,
|
|
125
|
-
|
|
126
|
-
serviceName
|
|
134
|
+
serviceName,
|
|
135
|
+
message: `Update ${serviceName} and ${associationKey} associations.`
|
|
136
|
+
};
|
|
137
|
+
return async (repository) => {
|
|
138
|
+
const entities = await this.find({
|
|
139
|
+
findOptions: { ...findOptions, size },
|
|
140
|
+
findManyOptions: { withDeleted: true }
|
|
141
|
+
})(repository).then(({ results }) => results);
|
|
142
|
+
const raw = enableLogging ?
|
|
143
|
+
{ findOptions, entities: entities.map(entity => ({ ...entity })), entityIds, associationKey }
|
|
144
|
+
: undefined;
|
|
145
|
+
const existingIds = entities.map(entity => entity[associationKey]);
|
|
146
|
+
const entitiesToAdd = entityIds
|
|
147
|
+
.filter(id => !existingIds.includes(id))
|
|
148
|
+
.map(id => repository.create({ ...findOptions, [associationKey]: id }));
|
|
149
|
+
const entitiesToRemove = await Promise.all(entities
|
|
150
|
+
.filter(entity => !entityIds.includes(entity[associationKey]))
|
|
151
|
+
.map(entity => entity.softRemove()));
|
|
152
|
+
const entitiesToRecover = await Promise.all(entities
|
|
153
|
+
.filter(entity => entityIds.includes(entity[associationKey]) && entity.deletedAt)
|
|
154
|
+
.map(entity => entity.recover()));
|
|
155
|
+
const entityActions = [...entitiesToAdd, ...entitiesToRecover, ...entitiesToRemove];
|
|
156
|
+
const savedEntities = await (entityManager ?
|
|
157
|
+
entityManager.save(entityActions)
|
|
158
|
+
: repository.save(entityActions));
|
|
159
|
+
await this.actionLogSuccess({ ...actionLogOptions, raw })(savedEntities);
|
|
160
|
+
return savedEntities.filter(entity => entity.deletedAt);
|
|
127
161
|
};
|
|
128
|
-
const entities = await this.find({
|
|
129
|
-
findOptions: { ...findOptions, size },
|
|
130
|
-
findManyOptions: { withDeleted: true }
|
|
131
|
-
})(repository).then(({ results }) => results);
|
|
132
|
-
const existingIds = entities.map(entity => entity[linkKey]);
|
|
133
|
-
const entitiesToAdd = entityOptions
|
|
134
|
-
.filter(id => !existingIds.includes(id))
|
|
135
|
-
.map(id => repository.create({ ...findOptions, [linkKey]: id }));
|
|
136
|
-
const entitiesToRemove = await Promise.all(entities.filter(entity => !entityOptions.includes(entity[linkKey])).map(entity => entity.softRemove()));
|
|
137
|
-
const entitiesToRecover = await Promise.all(entities
|
|
138
|
-
.filter(entity => entityOptions.includes(entity[linkKey]) && entity.deletedAt)
|
|
139
|
-
.map(entity => entity.recover()));
|
|
140
|
-
const entityActions = [...entitiesToAdd, ...entitiesToRecover, ...entitiesToRemove];
|
|
141
|
-
await (entityManager ? entityManager.save(entityActions) : repository.save(entityActions));
|
|
142
|
-
const savedEntities = await this.find({
|
|
143
|
-
findOptions: { ...findOptions, size }
|
|
144
|
-
})(repository).then(({ results }) => results);
|
|
145
|
-
await this.actionLogSuccess(actionLogOptions)(savedEntities);
|
|
146
|
-
return savedEntities;
|
|
147
162
|
};
|
|
148
163
|
}
|
|
149
|
-
preValidate({ actionLogOptions, findOptions, serviceName, validateKeys = [], validateMethod = 'and' }) {
|
|
150
|
-
|
|
164
|
+
async preValidate({ actionLogOptions, findOptions, serviceName, validateKeys = [], validateMethod = 'and' }) {
|
|
165
|
+
const processOrKeys = ({ notId, ...args }) => (keys) => keys
|
|
166
|
+
.map(key => ({ [key]: args[key] }))
|
|
167
|
+
.reduce((acc, cur) => ({ ...acc, ...cur }), notId ? { id: (0, typeorm_1.Not)(notId) } : {});
|
|
168
|
+
const processOrValidateWhere = (findOptions) => async (validateKeys) => {
|
|
151
169
|
const { notId, ...args } = findOptions;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
170
|
+
!Array.isArray(validateKeys[0]) &&
|
|
171
|
+
(await this.throwError({
|
|
172
|
+
code: 400000,
|
|
173
|
+
errorType: app_interface_1.APIError.HTTP_EXCEPTION,
|
|
174
|
+
message: `When using or as a validation method, validateKeys must be a nested array. validateKeys: ${JSON.stringify(validateKeys)}`,
|
|
175
|
+
status: 400
|
|
176
|
+
})(actionLogOptions));
|
|
177
|
+
const validateOrKeys = [...new Set(validateKeys.flat())];
|
|
178
|
+
const findOrOptions = validateKeys.map(processOrKeys(findOptions));
|
|
179
|
+
return {
|
|
180
|
+
where: [
|
|
162
181
|
...Object.entries(args)
|
|
163
|
-
.filter(([key]) => !
|
|
164
|
-
.map(([key, value]) => ({ ...
|
|
165
|
-
...
|
|
166
|
-
]
|
|
182
|
+
.filter(([key]) => !validateOrKeys.includes(key))
|
|
183
|
+
.map(([key, value]) => ({ ...(notId && { id: (0, typeorm_1.Not)(notId) }), [key]: value })),
|
|
184
|
+
...findOrOptions
|
|
185
|
+
],
|
|
186
|
+
findOrOptions
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
const { notId, ...args } = findOptions;
|
|
190
|
+
const { where: orWhere, findOrOptions } = validateMethod === 'or' ?
|
|
191
|
+
await processOrValidateWhere(findOptions)(validateKeys)
|
|
192
|
+
: {};
|
|
193
|
+
const where = validateMethod === 'and' ? { ...args, ...(notId && { id: (0, typeorm_1.Not)(notId) }) } : orWhere;
|
|
194
|
+
return async (repository) => {
|
|
167
195
|
const entity = await repository.findOne({ select: Object.keys(args), where });
|
|
168
196
|
if (entity) {
|
|
169
197
|
const key = Object.keys({
|
|
170
198
|
...args,
|
|
171
|
-
...
|
|
199
|
+
...findOrOptions?.reduce((acc, cur) => ({ ...acc, ...cur }), {})
|
|
172
200
|
}).join(',');
|
|
173
201
|
await this.throwError({
|
|
174
202
|
errorType: app_interface_1.APIError.UNPROCESSABLE_ENTITY,
|
|
@@ -194,7 +222,7 @@ let BaseService = class BaseService {
|
|
|
194
222
|
throwError({ errorType, ...args }) {
|
|
195
223
|
return async (actionLogOptions) => {
|
|
196
224
|
try {
|
|
197
|
-
(0, util_1.
|
|
225
|
+
(0, util_1.throwAPIError)(args)(errorType);
|
|
198
226
|
}
|
|
199
227
|
catch (error) {
|
|
200
228
|
actionLogOptions &&
|