@zola_do/crud 0.1.9
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/controller/entity-crud.controller.d.ts +16 -0
- package/dist/controller/entity-crud.controller.js +139 -0
- package/dist/controller/entity-crud.controller.js.map +1 -0
- package/dist/controller/extra-crud.controller.d.ts +18 -0
- package/dist/controller/extra-crud.controller.js +145 -0
- package/dist/controller/extra-crud.controller.js.map +1 -0
- package/dist/controller/index.d.ts +3 -0
- package/dist/controller/index.js +20 -0
- package/dist/controller/index.js.map +1 -0
- package/dist/controller/relation-crud.controller.d.ts +13 -0
- package/dist/controller/relation-crud.controller.js +101 -0
- package/dist/controller/relation-crud.controller.js.map +1 -0
- package/dist/crud-operation/controller/entity-crud.controller.d.ts +16 -0
- package/dist/crud-operation/controller/entity-crud.controller.js +136 -0
- package/dist/crud-operation/controller/entity-crud.controller.js.map +1 -0
- package/dist/crud-operation/controller/extra-crud.controller.d.ts +18 -0
- package/dist/crud-operation/controller/extra-crud.controller.js +142 -0
- package/dist/crud-operation/controller/extra-crud.controller.js.map +1 -0
- package/dist/crud-operation/controller/index.d.ts +3 -0
- package/dist/crud-operation/controller/index.js +20 -0
- package/dist/crud-operation/controller/index.js.map +1 -0
- package/dist/crud-operation/controller/relation-crud.controller.d.ts +13 -0
- package/dist/crud-operation/controller/relation-crud.controller.js +103 -0
- package/dist/crud-operation/controller/relation-crud.controller.js.map +1 -0
- package/dist/crud-operation/index.d.ts +3 -0
- package/dist/crud-operation/index.js +20 -0
- package/dist/crud-operation/index.js.map +1 -0
- package/dist/crud-operation/repository/entity-crud.repository.d.ts +18 -0
- package/dist/crud-operation/repository/entity-crud.repository.js +124 -0
- package/dist/crud-operation/repository/entity-crud.repository.js.map +1 -0
- package/dist/crud-operation/repository/extra-crud.repository.d.ts +20 -0
- package/dist/crud-operation/repository/extra-crud.repository.js +129 -0
- package/dist/crud-operation/repository/extra-crud.repository.js.map +1 -0
- package/dist/crud-operation/repository/index.d.ts +3 -0
- package/dist/crud-operation/repository/index.js +20 -0
- package/dist/crud-operation/repository/index.js.map +1 -0
- package/dist/crud-operation/repository/relation-crud.repository.d.ts +13 -0
- package/dist/crud-operation/repository/relation-crud.repository.js +116 -0
- package/dist/crud-operation/repository/relation-crud.repository.js.map +1 -0
- package/dist/crud-operation/service/entity-crud.service.d.ts +15 -0
- package/dist/crud-operation/service/entity-crud.service.js +49 -0
- package/dist/crud-operation/service/entity-crud.service.js.map +1 -0
- package/dist/crud-operation/service/extra-crud.service.d.ts +18 -0
- package/dist/crud-operation/service/extra-crud.service.js +55 -0
- package/dist/crud-operation/service/extra-crud.service.js.map +1 -0
- package/dist/crud-operation/service/index.d.ts +3 -0
- package/dist/crud-operation/service/index.js +20 -0
- package/dist/crud-operation/service/index.js.map +1 -0
- package/dist/crud-operation/service/relation-crud.service.d.ts +12 -0
- package/dist/crud-operation/service/relation-crud.service.js +37 -0
- package/dist/crud-operation/service/relation-crud.service.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/service/entity-crud.service.d.ts +17 -0
- package/dist/service/entity-crud.service.js +115 -0
- package/dist/service/entity-crud.service.js.map +1 -0
- package/dist/service/extra-crud.service.d.ts +18 -0
- package/dist/service/extra-crud.service.js +128 -0
- package/dist/service/extra-crud.service.js.map +1 -0
- package/dist/service/index.d.ts +3 -0
- package/dist/service/index.js +20 -0
- package/dist/service/index.js.map +1 -0
- package/dist/service/relation-crud.service.d.ts +13 -0
- package/dist/service/relation-crud.service.js +102 -0
- package/dist/service/relation-crud.service.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-crud.controller.js","sourceRoot":"","sources":["../../../src/crud-operation/controller/entity-crud.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAsBA,oDAkFC;AAxGD,2CAYwB;AACxB,wCAA+C;AAC/C,qCAAqD;A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K,EAAC,IAAI,CAAC,CAAA;QACX,WAAA,IAAA,aAAI,GAAE,CAAA;QACN,WAAA,IAAA,YAAG,GAAE,CAAA;;;;0DAKP;IAGK;QADL,IAAA,eAAM,EAAC,KAAK,CAAC;QACI,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;QAAc,WAAA,IAAA,YAAG,GAAE,CAAA;;;;8DAE/C;IAGK;QADL,IAAA,cAAK,EAAC,aAAa,CAAC;QACN,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;QAAc,WAAA,IAAA,YAAG,GAAE,CAAA;;;;2DAE5C;IASK;QAPL,IAAA,YAAG,EAAC,iBAAiB,CAAC;QACtB,IAAA,kBAAQ,EAAC;YACR,IAAI,EAAE,GAAG;YACT,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,sCAAsC;YACnD,QAAQ,EAAE,KAAK;SAChB,CAAC;QAEC,WAAA,IAAA,cAAK,EAAC,GAAG,CAAC,CAAA;QACV,WAAA,IAAA,YAAG,GAAE,CAAA;;;;mEAIP;IAxEG,wBAAwB;QAH7B,IAAA,mBAAU,GAAE;QACZ,IAAA,wBAAe,GAAgC;QAC/C,IAAA,uBAAa,GAAE;yCAEuB,2BAAiB;OADlD,wBAAwB,CAyE7B;IAED,OAAO,wBAAwB,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DeepPartial, ObjectLiteral } from 'typeorm';
|
|
2
|
+
import { DataResponseFormat } from '@zola_do/core';
|
|
3
|
+
import { ExtraCrudService } from '../../service';
|
|
4
|
+
import { ExtraCrudOptions } from '@zola_do/core';
|
|
5
|
+
export declare class BaseAPIDto {
|
|
6
|
+
}
|
|
7
|
+
export declare function ExtraCrudController<TEntity extends ObjectLiteral>(options: ExtraCrudOptions): {
|
|
8
|
+
new (service: ExtraCrudService<TEntity>): {
|
|
9
|
+
readonly service: ExtraCrudService<TEntity>;
|
|
10
|
+
create(itemData: DeepPartial<TEntity>, req?: any): Promise<TEntity>;
|
|
11
|
+
findAll(id: string, q: string, req?: any): Promise<DataResponseFormat<TEntity>>;
|
|
12
|
+
findOne(id: string, req?: any): Promise<TEntity | undefined>;
|
|
13
|
+
update(id: string, itemData: Partial<TEntity>, req?: any): Promise<TEntity | undefined>;
|
|
14
|
+
softDelete(id: string, req?: any): Promise<void>;
|
|
15
|
+
restore(id: string, req?: any): Promise<void>;
|
|
16
|
+
findAllArchived(id: string, q?: string, req?: any): Promise<DataResponseFormat<TEntity>>;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,142 @@
|
|
|
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.BaseAPIDto = void 0;
|
|
16
|
+
exports.ExtraCrudController = ExtraCrudController;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const typeorm_1 = require("typeorm");
|
|
19
|
+
const service_1 = require("../../service");
|
|
20
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
21
|
+
const collection_query_1 = require("@zola_do/collection-query");
|
|
22
|
+
const core_1 = require("@zola_do/core");
|
|
23
|
+
class BaseAPIDto {
|
|
24
|
+
}
|
|
25
|
+
exports.BaseAPIDto = BaseAPIDto;
|
|
26
|
+
function ExtraCrudController(options) {
|
|
27
|
+
var _a;
|
|
28
|
+
const { entityIdName, createDto, updateDto } = options;
|
|
29
|
+
let ExtraCrudControllerHost = class ExtraCrudControllerHost {
|
|
30
|
+
constructor(service) {
|
|
31
|
+
this.service = service;
|
|
32
|
+
}
|
|
33
|
+
async create(itemData, req) {
|
|
34
|
+
if (options === null || options === void 0 ? void 0 : options.createDto)
|
|
35
|
+
await (0, core_1.validateDto)(options.createDto, itemData);
|
|
36
|
+
return await this.service.create(itemData, req);
|
|
37
|
+
}
|
|
38
|
+
async findAll(id, q, req) {
|
|
39
|
+
const query = (0, collection_query_1.decodeCollectionQuery)(q);
|
|
40
|
+
return await this.service.findAll(id, query, options, req);
|
|
41
|
+
}
|
|
42
|
+
async findOne(id, req) {
|
|
43
|
+
return await this.service.findOne(id, req);
|
|
44
|
+
}
|
|
45
|
+
async update(id, itemData, req) {
|
|
46
|
+
if (options === null || options === void 0 ? void 0 : options.updateDto)
|
|
47
|
+
await (0, core_1.validateDto)(options.updateDto, itemData);
|
|
48
|
+
return await this.service.update(id, itemData);
|
|
49
|
+
}
|
|
50
|
+
async softDelete(id, req) {
|
|
51
|
+
return await this.service.softDelete(id, req);
|
|
52
|
+
}
|
|
53
|
+
async restore(id, req) {
|
|
54
|
+
return await this.service.restore(id, req);
|
|
55
|
+
}
|
|
56
|
+
async findAllArchived(id, q, req) {
|
|
57
|
+
const query = (0, collection_query_1.decodeCollectionQuery)(q);
|
|
58
|
+
return await this.service.findAllArchived(id, query, options, req);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, common_1.Post)(),
|
|
63
|
+
(0, swagger_1.ApiBody)({ type: createDto || BaseAPIDto }),
|
|
64
|
+
__param(0, (0, common_1.Body)()),
|
|
65
|
+
__param(1, (0, common_1.Req)()),
|
|
66
|
+
__metadata("design:type", Function),
|
|
67
|
+
__metadata("design:paramtypes", [typeof (_a = typeof typeorm_1.DeepPartial !== "undefined" && typeorm_1.DeepPartial) === "function" ? _a : Object, Object]),
|
|
68
|
+
__metadata("design:returntype", Promise)
|
|
69
|
+
], ExtraCrudControllerHost.prototype, "create", null);
|
|
70
|
+
__decorate([
|
|
71
|
+
(0, common_1.Get)('list/:id'),
|
|
72
|
+
(0, swagger_1.ApiQuery)({
|
|
73
|
+
name: 'q',
|
|
74
|
+
type: String,
|
|
75
|
+
description: 'Collection Query Parameter. Optional',
|
|
76
|
+
required: false,
|
|
77
|
+
}),
|
|
78
|
+
__param(0, (0, common_1.Param)('id')),
|
|
79
|
+
__param(1, (0, common_1.Query)('q')),
|
|
80
|
+
__param(2, (0, common_1.Req)()),
|
|
81
|
+
__metadata("design:type", Function),
|
|
82
|
+
__metadata("design:paramtypes", [String, String, Object]),
|
|
83
|
+
__metadata("design:returntype", Promise)
|
|
84
|
+
], ExtraCrudControllerHost.prototype, "findAll", null);
|
|
85
|
+
__decorate([
|
|
86
|
+
(0, common_1.Get)(':id'),
|
|
87
|
+
__param(0, (0, common_1.Param)('id')),
|
|
88
|
+
__param(1, (0, common_1.Req)()),
|
|
89
|
+
__metadata("design:type", Function),
|
|
90
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
91
|
+
__metadata("design:returntype", Promise)
|
|
92
|
+
], ExtraCrudControllerHost.prototype, "findOne", null);
|
|
93
|
+
__decorate([
|
|
94
|
+
(0, common_1.Put)(':id'),
|
|
95
|
+
(0, swagger_1.ApiBody)({ type: updateDto || BaseAPIDto }),
|
|
96
|
+
__param(0, (0, common_1.Param)('id')),
|
|
97
|
+
__param(1, (0, common_1.Body)()),
|
|
98
|
+
__param(2, (0, common_1.Req)()),
|
|
99
|
+
__metadata("design:type", Function),
|
|
100
|
+
__metadata("design:paramtypes", [String, Object, Object]),
|
|
101
|
+
__metadata("design:returntype", Promise)
|
|
102
|
+
], ExtraCrudControllerHost.prototype, "update", null);
|
|
103
|
+
__decorate([
|
|
104
|
+
(0, common_1.Delete)(':id'),
|
|
105
|
+
__param(0, (0, common_1.Param)('id')),
|
|
106
|
+
__param(1, (0, common_1.Req)()),
|
|
107
|
+
__metadata("design:type", Function),
|
|
108
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
109
|
+
__metadata("design:returntype", Promise)
|
|
110
|
+
], ExtraCrudControllerHost.prototype, "softDelete", null);
|
|
111
|
+
__decorate([
|
|
112
|
+
(0, common_1.Patch)('restore/:id'),
|
|
113
|
+
__param(0, (0, common_1.Param)('id')),
|
|
114
|
+
__param(1, (0, common_1.Req)()),
|
|
115
|
+
__metadata("design:type", Function),
|
|
116
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
117
|
+
__metadata("design:returntype", Promise)
|
|
118
|
+
], ExtraCrudControllerHost.prototype, "restore", null);
|
|
119
|
+
__decorate([
|
|
120
|
+
(0, common_1.Get)('list/archived/items/:id'),
|
|
121
|
+
(0, swagger_1.ApiQuery)({
|
|
122
|
+
name: 'q',
|
|
123
|
+
type: String,
|
|
124
|
+
description: 'Collection Query Parameter. Optional',
|
|
125
|
+
required: false,
|
|
126
|
+
}),
|
|
127
|
+
__param(0, (0, common_1.Param)('id')),
|
|
128
|
+
__param(1, (0, common_1.Query)('q')),
|
|
129
|
+
__param(2, (0, common_1.Req)()),
|
|
130
|
+
__metadata("design:type", Function),
|
|
131
|
+
__metadata("design:paramtypes", [String, String, Object]),
|
|
132
|
+
__metadata("design:returntype", Promise)
|
|
133
|
+
], ExtraCrudControllerHost.prototype, "findAllArchived", null);
|
|
134
|
+
ExtraCrudControllerHost = __decorate([
|
|
135
|
+
(0, common_1.Controller)(),
|
|
136
|
+
(0, common_1.UseInterceptors)(),
|
|
137
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
138
|
+
__metadata("design:paramtypes", [service_1.ExtraCrudService])
|
|
139
|
+
], ExtraCrudControllerHost);
|
|
140
|
+
return ExtraCrudControllerHost;
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=extra-crud.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extra-crud.controller.js","sourceRoot":"","sources":["../../../src/crud-operation/controller/extra-crud.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAuBA,kDAoFC;AA3GD,2CAYwB;AACxB,qCAAqD;AAErD,2CAAiD;AACjD,6CAAmE;AAEnE,gEAAkE;AAClE,wCAA4C;AAE5C,MAAa,UAAU;CAAG;AAA1B,gCAA0B;AAE1B,SAAgB,mBAAmB,CACjC,OAAyB;;IAEzB,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAEvD,IAGM,uBAAuB,GAH7B,MAGM,uBAAuB;QAC3B,YAA4B,OAAkC;YAAlC,YAAO,GAAP,OAAO,CAA2B;QAAG,CAAC;QAI5D,AAAN,KAAK,CAAC,MAAM,CACF,QAA8B,EAC/B,GAAS;YAEhB,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS;gBAAE,MAAM,IAAA,kBAAW,EAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YACvE,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QAClD,CAAC;QASK,AAAN,KAAK,CAAC,OAAO,CACE,EAAU,EACX,CAAS,EACd,GAAS;YAEhB,MAAM,KAAK,GAAG,IAAA,wCAAqB,EAAC,CAAC,CAAC,CAAC;YACvC,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;QAC7D,CAAC;QAGK,AAAN,KAAK,CAAC,OAAO,CACE,EAAU,EAChB,GAAS;YAEhB,OAAO,MAAM,I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U,GAAE;QACZ,IAAA,wBAAe,GAAgC;QAC/C,IAAA,uBAAa,GAAE;yCAEuB,0BAAgB;OADjD,uBAAuB,CAyE5B;IAED,OAAO,uBAAuB,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./entity-crud.controller"), exports);
|
|
18
|
+
__exportStar(require("./relation-crud.controller"), exports);
|
|
19
|
+
__exportStar(require("./extra-crud.controller"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/crud-operation/controller/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,6DAA2C;AAC3C,0DAAwC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DataResponseFormat } from '@zola_do/core';
|
|
2
|
+
import { RelationCrudService } from '../../service';
|
|
3
|
+
import { RelationCrudOptions } from '@zola_do/core';
|
|
4
|
+
import { ObjectLiteral } from 'typeorm';
|
|
5
|
+
export declare function RelationCrudController<TEntity extends ObjectLiteral>(options: RelationCrudOptions): {
|
|
6
|
+
new (service: RelationCrudService<TEntity>): {
|
|
7
|
+
readonly service: RelationCrudService<TEntity>;
|
|
8
|
+
bulkSaveFirst(itemData: any, req?: any): Promise<any>;
|
|
9
|
+
bulkSaveSecond(itemData: any, req?: any): Promise<any>;
|
|
10
|
+
findAllFirst(id: string, q: string, req?: any): Promise<DataResponseFormat<TEntity>>;
|
|
11
|
+
findAllSecond(id: string, q: string, req?: any): Promise<DataResponseFormat<TEntity>>;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
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.RelationCrudController = RelationCrudController;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const service_1 = require("../../service");
|
|
18
|
+
const extra_crud_controller_1 = require("./extra-crud.controller");
|
|
19
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
20
|
+
const collection_query_1 = require("@zola_do/collection-query");
|
|
21
|
+
const core_1 = require("@zola_do/core");
|
|
22
|
+
function RelationCrudController(options) {
|
|
23
|
+
const { firstEntityIdName, firstInclude = 'first', secondEntityIdName, secondInclude = 'second', assignFirstDto, assignSecondDto, } = options;
|
|
24
|
+
let RelationCrudControllerHost = class RelationCrudControllerHost {
|
|
25
|
+
constructor(service) {
|
|
26
|
+
this.service = service;
|
|
27
|
+
}
|
|
28
|
+
async bulkSaveFirst(itemData, req) {
|
|
29
|
+
if (options === null || options === void 0 ? void 0 : options.assignFirstDto)
|
|
30
|
+
await (0, core_1.validateDto)(options.assignFirstDto, itemData);
|
|
31
|
+
return this.service.bulkSaveFirst(itemData, options);
|
|
32
|
+
}
|
|
33
|
+
async bulkSaveSecond(itemData, req) {
|
|
34
|
+
if (options === null || options === void 0 ? void 0 : options.assignSecondDto)
|
|
35
|
+
await (0, core_1.validateDto)(options.assignSecondDto, itemData);
|
|
36
|
+
return this.service.bulkSaveSecond(itemData, options);
|
|
37
|
+
}
|
|
38
|
+
async findAllFirst(id, q, req) {
|
|
39
|
+
const query = (0, collection_query_1.decodeCollectionQuery)(q);
|
|
40
|
+
return this.service.findAllFirst(id, query, options);
|
|
41
|
+
}
|
|
42
|
+
async findAllSecond(id, q, req) {
|
|
43
|
+
const query = (0, collection_query_1.decodeCollectionQuery)(q);
|
|
44
|
+
return this.service.findAllSecond(id, query, options);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, common_1.Post)(`assign-${firstInclude}`),
|
|
49
|
+
(0, swagger_1.ApiBody)({ type: assignFirstDto || extra_crud_controller_1.BaseAPIDto }),
|
|
50
|
+
__param(0, (0, common_1.Body)()),
|
|
51
|
+
__param(1, (0, common_1.Req)()),
|
|
52
|
+
__metadata("design:type", Function),
|
|
53
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
54
|
+
__metadata("design:returntype", Promise)
|
|
55
|
+
], RelationCrudControllerHost.prototype, "bulkSaveFirst", null);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, common_1.Post)(`assign-${secondInclude}`),
|
|
58
|
+
(0, swagger_1.ApiBody)({ type: assignSecondDto || extra_crud_controller_1.BaseAPIDto }),
|
|
59
|
+
__param(0, (0, common_1.Body)()),
|
|
60
|
+
__param(1, (0, common_1.Req)()),
|
|
61
|
+
__metadata("design:type", Function),
|
|
62
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
63
|
+
__metadata("design:returntype", Promise)
|
|
64
|
+
], RelationCrudControllerHost.prototype, "bulkSaveSecond", null);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, common_1.Get)(`:id/${firstInclude}`),
|
|
67
|
+
(0, swagger_1.ApiQuery)({
|
|
68
|
+
name: 'q',
|
|
69
|
+
type: String,
|
|
70
|
+
description: 'Collection Query Parameter. Optional',
|
|
71
|
+
required: false,
|
|
72
|
+
}),
|
|
73
|
+
__param(0, (0, common_1.Param)('id')),
|
|
74
|
+
__param(1, (0, common_1.Query)('q')),
|
|
75
|
+
__param(2, (0, common_1.Req)()),
|
|
76
|
+
__metadata("design:type", Function),
|
|
77
|
+
__metadata("design:paramtypes", [String, String, Object]),
|
|
78
|
+
__metadata("design:returntype", Promise)
|
|
79
|
+
], RelationCrudControllerHost.prototype, "findAllFirst", null);
|
|
80
|
+
__decorate([
|
|
81
|
+
(0, common_1.Get)(`:id/${secondInclude}`),
|
|
82
|
+
(0, swagger_1.ApiQuery)({
|
|
83
|
+
name: 'q',
|
|
84
|
+
type: String,
|
|
85
|
+
description: 'Collection Query Parameter. Optional',
|
|
86
|
+
required: false,
|
|
87
|
+
}),
|
|
88
|
+
__param(0, (0, common_1.Param)('id')),
|
|
89
|
+
__param(1, (0, common_1.Query)('q')),
|
|
90
|
+
__param(2, (0, common_1.Req)()),
|
|
91
|
+
__metadata("design:type", Function),
|
|
92
|
+
__metadata("design:paramtypes", [String, String, Object]),
|
|
93
|
+
__metadata("design:returntype", Promise)
|
|
94
|
+
], RelationCrudControllerHost.prototype, "findAllSecond", null);
|
|
95
|
+
RelationCrudControllerHost = __decorate([
|
|
96
|
+
(0, common_1.Controller)(),
|
|
97
|
+
(0, common_1.UseInterceptors)(),
|
|
98
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
99
|
+
__metadata("design:paramtypes", [service_1.RelationCrudService])
|
|
100
|
+
], RelationCrudControllerHost);
|
|
101
|
+
return RelationCrudControllerHost;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=relation-crud.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relation-crud.controller.js","sourceRoot":"","sources":["../../../src/crud-operation/controller/relation-crud.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAmBA,wDAuEC;AA1FD,2CASwB;AAExB,2CAAoD;AACpD,mEAAqD;AACrD,6CAAmE;AAGnE,gEAAkE;AAClE,wCAA4C;AAE5C,SAAgB,sBAAsB,CACpC,OAA4B;IAE5B,MAAM,EACJ,iBAAiB,EACjB,YAAY,GAAG,OAAO,EACtB,kBAAkB,EAClB,aAAa,GAAG,QAAQ,EACxB,cAAc,EACd,eAAe,GAChB,GAAG,OAAO,CAAC;IAEZ,IAGM,0BAA0B,GAHhC,MAGM,0BAA0B;QAC9B,YAA4B,OAAqC;YAArC,YAAO,GAAP,OAAO,CAA8B;QAAG,CAAC;QAI/D,AAAN,KAAK,CAAC,aAAa,CAAS,QAAa,EAAS,GAAS;YACzD,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc;gBACzB,MAAM,IAAA,kBAAW,EAAC,OAAO,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;YACtD,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACvD,CAAC;QAIK,AAAN,KAAK,CAAC,cAAc,CACV,QAAa,EACd,GAAS;YAEhB,IA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,MAAM;YACZ,WAAW,EAAE,sCAAsC;YACnD,QAAQ,EAAE,KAAK;SAChB,CAAC;QAEC,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;QACX,WAAA,IAAA,cAAK,EAAC,GAAG,CAAC,CAAA;QACV,WAAA,IAAA,YAAG,GAAE,CAAA;;;;kEAIP;IASK;QAPL,IAAA,YAAG,EAAC,OAAO,aAAa,EAAE,CAAC;QAC3B,IAAA,kBAAQ,EAAC;YACR,IAAI,EAAE,GAAG;YACT,IAAI,EAAE,MAAM;YACZ,WAAW,EAAE,sCAAsC;YACnD,QAAQ,EAAE,KAAK;SAChB,CAAC;QAEC,WAAA,IAAA,cAAK,EAAC,IAAI,CAAC,CAAA;QACX,WAAA,IAAA,cAAK,EAAC,GAAG,CAAC,CAAA;QACV,WAAA,IAAA,YAAG,GAAE,CAAA;;;;mEAIP;IApDG,0BAA0B;QAH/B,IAAA,mBAAU,GAAE;QACZ,IAAA,wBAAe,GAAgC;QAC/C,IAAA,uBAAa,GAAE;yCAEuB,6BAAmB;OADpD,0BAA0B,CAqD/B;IAED,OAAO,0BAA0B,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./controller"), exports);
|
|
18
|
+
__exportStar(require("./repository"), exports);
|
|
19
|
+
__exportStar(require("./service"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/crud-operation/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,4CAA0B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Repository, DeepPartial, ObjectLiteral } from 'typeorm';
|
|
2
|
+
import { CollectionQuery } from '@zola_do/collection-query';
|
|
3
|
+
import { DataResponseFormat } from '@zola_do/core';
|
|
4
|
+
export declare class EntityCrudRepository<T extends ObjectLiteral> {
|
|
5
|
+
private readonly repository;
|
|
6
|
+
private requestR?;
|
|
7
|
+
constructor(repository: Repository<T>, requestR?: Request);
|
|
8
|
+
getRepository(): any;
|
|
9
|
+
create(itemData: DeepPartial<any>, req?: any): Promise<any>;
|
|
10
|
+
findAll(query: CollectionQuery, req?: any): Promise<DataResponseFormat<T>>;
|
|
11
|
+
findOne(id: any, req?: any): Promise<T | undefined>;
|
|
12
|
+
update(id: string, itemData: any): Promise<T | undefined>;
|
|
13
|
+
softDelete(id: string, req?: any): Promise<void>;
|
|
14
|
+
restore(id: string, req?: any): Promise<void>;
|
|
15
|
+
findAllArchived(query: CollectionQuery, req?: any): Promise<DataResponseFormat<T>>;
|
|
16
|
+
findOneOrFail(id: any): Promise<T>;
|
|
17
|
+
private findOneOrFailWithDeleted;
|
|
18
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
var _a;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.EntityCrudRepository = void 0;
|
|
17
|
+
const typeorm_1 = require("typeorm");
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
const collection_query_1 = require("@zola_do/collection-query");
|
|
20
|
+
const core_1 = require("@zola_do/core");
|
|
21
|
+
const core_2 = require("@nestjs/core");
|
|
22
|
+
const interceptors_1 = require("@zola_do/interceptors");
|
|
23
|
+
let EntityCrudRepository = class EntityCrudRepository {
|
|
24
|
+
constructor(repository, requestR) {
|
|
25
|
+
this.repository = repository;
|
|
26
|
+
this.requestR = requestR;
|
|
27
|
+
}
|
|
28
|
+
getRepository() {
|
|
29
|
+
var _a;
|
|
30
|
+
const manager = this.requestR[interceptors_1.ENTITY_MANAGER_KEY];
|
|
31
|
+
const repo = (_a = manager === null || manager === void 0 ? void 0 : manager.getRepository(this.repository.metadata.tableName)) !== null && _a !== void 0 ? _a : this.repository;
|
|
32
|
+
return repo;
|
|
33
|
+
}
|
|
34
|
+
async create(itemData, req) {
|
|
35
|
+
var _a;
|
|
36
|
+
if ((_a = req === null || req === void 0 ? void 0 : req.user) === null || _a === void 0 ? void 0 : _a.organization) {
|
|
37
|
+
itemData.organizationId = req.user.organization.id;
|
|
38
|
+
}
|
|
39
|
+
const repo = this.getRepository();
|
|
40
|
+
const item = repo.create(itemData);
|
|
41
|
+
await repo.insert(item);
|
|
42
|
+
return item;
|
|
43
|
+
}
|
|
44
|
+
async findAll(query, req) {
|
|
45
|
+
const repo = this.getRepository();
|
|
46
|
+
const dataQuery = collection_query_1.QueryConstructor.constructQuery(repo, query);
|
|
47
|
+
const response = new core_1.DataResponseFormat();
|
|
48
|
+
if (query.count) {
|
|
49
|
+
response.total = await dataQuery.getCount();
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const [result, total] = await dataQuery.getManyAndCount();
|
|
53
|
+
response.total = total;
|
|
54
|
+
response.items = result;
|
|
55
|
+
}
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
58
|
+
async findOne(id, req) {
|
|
59
|
+
const repo = this.getRepository();
|
|
60
|
+
return await repo.findOneBy({ id });
|
|
61
|
+
}
|
|
62
|
+
async update(id, itemData) {
|
|
63
|
+
const repo = this.getRepository();
|
|
64
|
+
const item = await this.findOneOrFail(id);
|
|
65
|
+
await repo.update(item.id, itemData);
|
|
66
|
+
return Object.assign(Object.assign({}, item), itemData);
|
|
67
|
+
}
|
|
68
|
+
async softDelete(id, req) {
|
|
69
|
+
const repo = this.getRepository();
|
|
70
|
+
const item = await this.findOneOrFail(id);
|
|
71
|
+
await repo.softRemove(item);
|
|
72
|
+
}
|
|
73
|
+
async restore(id, req) {
|
|
74
|
+
const repo = this.getRepository();
|
|
75
|
+
await this.findOneOrFailWithDeleted(id);
|
|
76
|
+
await repo.restore(id);
|
|
77
|
+
}
|
|
78
|
+
async findAllArchived(query, req) {
|
|
79
|
+
const repo = this.getRepository();
|
|
80
|
+
query.where.push([
|
|
81
|
+
{ column: 'deletedAt', value: '', operator: 'IsNotNull' },
|
|
82
|
+
]);
|
|
83
|
+
const dataQuery = collection_query_1.QueryConstructor.constructQuery(repo, query);
|
|
84
|
+
dataQuery.withDeleted();
|
|
85
|
+
const response = new core_1.DataResponseFormat();
|
|
86
|
+
if (query.count) {
|
|
87
|
+
response.total = await dataQuery.getCount();
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const [result, total] = await dataQuery.getManyAndCount();
|
|
91
|
+
response.total = total;
|
|
92
|
+
response.items = result;
|
|
93
|
+
}
|
|
94
|
+
return response;
|
|
95
|
+
}
|
|
96
|
+
async findOneOrFail(id) {
|
|
97
|
+
const repo = this.getRepository();
|
|
98
|
+
const item = await repo.findOneBy({ id });
|
|
99
|
+
if (!item) {
|
|
100
|
+
throw new common_1.NotFoundException(`not_found`);
|
|
101
|
+
}
|
|
102
|
+
return item;
|
|
103
|
+
}
|
|
104
|
+
async findOneOrFailWithDeleted(id) {
|
|
105
|
+
const repo = this.getRepository();
|
|
106
|
+
const item = await repo.findOne({
|
|
107
|
+
where: {
|
|
108
|
+
id,
|
|
109
|
+
},
|
|
110
|
+
withDeleted: true,
|
|
111
|
+
});
|
|
112
|
+
if (!item) {
|
|
113
|
+
throw new common_1.NotFoundException(`not_found`);
|
|
114
|
+
}
|
|
115
|
+
return item;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
exports.EntityCrudRepository = EntityCrudRepository;
|
|
119
|
+
exports.EntityCrudRepository = EntityCrudRepository = __decorate([
|
|
120
|
+
(0, common_1.Injectable)(),
|
|
121
|
+
__param(1, (0, common_1.Inject)(core_2.REQUEST)),
|
|
122
|
+
__metadata("design:paramtypes", [typeof (_a = typeof typeorm_1.Repository !== "undefined" && typeorm_1.Repository) === "function" ? _a : Object, Request])
|
|
123
|
+
], EntityCrudRepository);
|
|
124
|
+
//# sourceMappingURL=entity-crud.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-crud.repository.js","sourceRoot":"","sources":["../../../src/crud-operation/repository/entity-crud.repository.ts"],"names":[],"mappings":";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AC;QAClC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;YAC9B,KAAK,EAAE;gBACL,EAAE;aACH;YACD,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,0BAAiB,CAAC,WAAW,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA/GY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAIR,WAAA,IAAA,eAAM,EAAC,cAAO,CAAC,CAAA;yDADa,oBAAU,oBAAV,oBAAU,gCACH,OAAO;GAHlC,oBAAoB,CA+GhC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Repository, DeepPartial, ObjectLiteral } from 'typeorm';
|
|
2
|
+
import { CollectionQuery } from '@zola_do/collection-query';
|
|
3
|
+
import { DataResponseFormat } from '@zola_do/core';
|
|
4
|
+
import { ExtraCrudOptions } from '@zola_do/core';
|
|
5
|
+
import { Request } from 'express';
|
|
6
|
+
export declare class ExtraCrudRepository<T extends ObjectLiteral> {
|
|
7
|
+
private readonly repository;
|
|
8
|
+
private readonly entity?;
|
|
9
|
+
private request?;
|
|
10
|
+
constructor(repository: Repository<T>, entity?: any, request?: Request);
|
|
11
|
+
create(itemData: DeepPartial<any>, req?: any): Promise<any>;
|
|
12
|
+
findAll(entityId: string, query: CollectionQuery, extraCrudOptions: ExtraCrudOptions, req?: any): Promise<DataResponseFormat<T>>;
|
|
13
|
+
findOne(id: any, req?: any): Promise<T | undefined>;
|
|
14
|
+
update(id: string, itemData: any): Promise<T | undefined>;
|
|
15
|
+
softDelete(id: string, req?: any): Promise<void>;
|
|
16
|
+
restore(id: string, req?: any): Promise<void>;
|
|
17
|
+
findAllArchived(entityId: string, query: CollectionQuery, extraCrudOptions: ExtraCrudOptions, req?: any): Promise<DataResponseFormat<T>>;
|
|
18
|
+
findOneOrFail(id: any): Promise<T>;
|
|
19
|
+
private findOneOrFailWithDeleted;
|
|
20
|
+
}
|