@foxiko/nest-common 0.0.1
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/build/common/base.service.d.ts +25 -0
- package/build/common/base.service.js +45 -0
- package/build/common/base.service.js.map +1 -0
- package/build/common/decorators/crud.decorator.d.ts +28 -0
- package/build/common/decorators/crud.decorator.js +410 -0
- package/build/common/decorators/crud.decorator.js.map +1 -0
- package/build/common/decorators/embedded.decorator.d.ts +2 -0
- package/build/common/decorators/embedded.decorator.js +67 -0
- package/build/common/decorators/embedded.decorator.js.map +1 -0
- package/build/common/dto/pagination.dto.d.ts +7 -0
- package/build/common/dto/pagination.dto.js +37 -0
- package/build/common/dto/pagination.dto.js.map +1 -0
- package/build/common/utils/entity-name.util.d.ts +7 -0
- package/build/common/utils/entity-name.util.js +41 -0
- package/build/common/utils/entity-name.util.js.map +1 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +22 -0
- package/build/index.js.map +1 -0
- package/package.json +31 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Repository, FindOptionsWhere, DeepPartial, ObjectLiteral, FindManyOptions, QueryDeepPartialEntity } from 'typeorm';
|
|
2
|
+
export declare abstract class BaseService<T extends ObjectLiteral> {
|
|
3
|
+
protected readonly repository: Repository<T>;
|
|
4
|
+
protected constructor(repository: Repository<T>);
|
|
5
|
+
findAll(where: FindOptionsWhere<T>): Promise<T[]>;
|
|
6
|
+
query(where: FindOptionsWhere<T>, options: FindManyOptions<T>): Promise<[T[], number]>;
|
|
7
|
+
count(where: FindOptionsWhere<T>, options?: FindManyOptions<T>): Promise<number>;
|
|
8
|
+
findOne(where: FindOptionsWhere<T>): Promise<T>;
|
|
9
|
+
delete(where: FindOptionsWhere<T>): Promise<import("typeorm").DeleteResult>;
|
|
10
|
+
create(data: DeepPartial<T>): Promise<(T & {
|
|
11
|
+
createdAt: Date;
|
|
12
|
+
updatedAt: Date;
|
|
13
|
+
}) | ((T extends (infer U)[] ? DeepPartial<U>[] : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer M> ? Set<DeepPartial<M>> : T extends object ? { [K_1 in keyof T]?: DeepPartial<T[K_1]>; } : T) & {
|
|
14
|
+
createdAt: Date;
|
|
15
|
+
updatedAt: Date;
|
|
16
|
+
} & T)>;
|
|
17
|
+
createMany(data: DeepPartial<T>[]): Promise<((T & {
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
updatedAt: Date;
|
|
20
|
+
}) | ((T extends (infer U)[] ? DeepPartial<U>[] : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer M> ? Set<DeepPartial<M>> : T extends object ? { [K_1 in keyof T]?: DeepPartial<T[K_1]>; } : T) & {
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
} & T))[]>;
|
|
24
|
+
update(id: string, data: QueryDeepPartialEntity<T>): Promise<import("typeorm").UpdateResult>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseService = void 0;
|
|
4
|
+
class BaseService {
|
|
5
|
+
constructor(repository) {
|
|
6
|
+
this.repository = repository;
|
|
7
|
+
}
|
|
8
|
+
async findAll(where) {
|
|
9
|
+
return this.repository.find({ where, });
|
|
10
|
+
}
|
|
11
|
+
async query(where, options) {
|
|
12
|
+
return this.repository.findAndCount({ where, ...options });
|
|
13
|
+
}
|
|
14
|
+
async count(where, options) {
|
|
15
|
+
return this.repository.count({ where, ...options });
|
|
16
|
+
}
|
|
17
|
+
async findOne(where) {
|
|
18
|
+
return this.repository.findOne({ where });
|
|
19
|
+
}
|
|
20
|
+
async delete(where) {
|
|
21
|
+
return this.repository.delete(where);
|
|
22
|
+
}
|
|
23
|
+
async create(data) {
|
|
24
|
+
return this.repository.save({
|
|
25
|
+
...data,
|
|
26
|
+
createdAt: new Date(),
|
|
27
|
+
updatedAt: new Date(),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async createMany(data) {
|
|
31
|
+
return this.repository.save(data.map(data => ({
|
|
32
|
+
...data,
|
|
33
|
+
createdAt: new Date(),
|
|
34
|
+
updatedAt: new Date(),
|
|
35
|
+
})));
|
|
36
|
+
}
|
|
37
|
+
async update(id, data) {
|
|
38
|
+
return this.repository.update(id, {
|
|
39
|
+
...data,
|
|
40
|
+
updatedAt: new Date(),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.BaseService = BaseService;
|
|
45
|
+
//# sourceMappingURL=base.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.service.js","sourceRoot":"","sources":["../../src/common/base.service.ts"],"names":[],"mappings":";;;AAEA,MAAsB,WAAW;IAC/B,YAAyC,UAAyB;QAAzB,eAAU,GAAV,UAAU,CAAe;IAAI,CAAC;IAEvE,KAAK,CAAC,OAAO,CAAC,KAA0B;QACtC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,KAA0B,EAAE,OAA2B;QACjE,OAAO,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,KAA0B,EAAE,OAA4B;QAClE,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAA0B;QACtC,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAA0B;QACrC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAoB;QAC/B,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YAC1B,GAAG,IAAI;YACP,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,SAAS,EAAE,IAAI,IAAI,EAAE;SACtB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAsB;QACrC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC5C,GAAG,IAAI;YACP,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,SAAS,EAAE,IAAI,IAAI,EAAE;SACtB,CAAC,CAAC,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,IAA+B;QACtD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE;YAChC,GAAG,IAAI;YACP,SAAS,EAAE,IAAI,IAAI,EAAE;SACtB,CAAC,CAAC;IACL,CAAC;CAEF;AA9CD,kCA8CC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
import { DeepPartial, FindOptionsWhere, ObjectLiteral } from 'typeorm';
|
|
3
|
+
import { BaseService } from '../base.service';
|
|
4
|
+
export interface CrudOptions<T, C, U> {
|
|
5
|
+
tag?: string;
|
|
6
|
+
entity: Type<T>;
|
|
7
|
+
createDto: Type<C>;
|
|
8
|
+
updateDto: Type<U>;
|
|
9
|
+
operations?: {
|
|
10
|
+
create?: {} | false;
|
|
11
|
+
createMany?: {} | false;
|
|
12
|
+
update?: {} | false;
|
|
13
|
+
import?: {} | false;
|
|
14
|
+
query?: {
|
|
15
|
+
pagination?: boolean;
|
|
16
|
+
} | false;
|
|
17
|
+
read?: {} | false;
|
|
18
|
+
delete?: {} | false;
|
|
19
|
+
replace?: {} | false;
|
|
20
|
+
export?: {} | false;
|
|
21
|
+
};
|
|
22
|
+
persist?: (request: Request, params: Record<string, string>) => DeepPartial<T>;
|
|
23
|
+
filter?: (request: Request, params: Record<string, string>) => FindOptionsWhere<T>;
|
|
24
|
+
}
|
|
25
|
+
export interface ICrudController<T extends ObjectLiteral> {
|
|
26
|
+
readonly service: BaseService<T>;
|
|
27
|
+
}
|
|
28
|
+
export declare function Crud<T extends ObjectLiteral, C, U>(options: CrudOptions<T, C, U>): (target: Function) => void;
|
|
@@ -0,0 +1,410 @@
|
|
|
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.Crud = Crud;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const json2csv_1 = require("json2csv");
|
|
18
|
+
const stream_1 = require("stream");
|
|
19
|
+
const class_transformer_1 = require("class-transformer");
|
|
20
|
+
const entity_name_util_1 = require("../utils/entity-name.util");
|
|
21
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
22
|
+
const pagination_dto_1 = require("../dto/pagination.dto");
|
|
23
|
+
const Body = (dto) => {
|
|
24
|
+
return (target, propertyKey, parameterIndex) => {
|
|
25
|
+
if (Array.isArray(dto)) {
|
|
26
|
+
return (0, common_1.Body)(new common_1.ParseArrayPipe({ items: dto[0] }))(target, propertyKey, parameterIndex);
|
|
27
|
+
}
|
|
28
|
+
const metadata = Reflect.getMetadata('design:paramtypes', target, propertyKey);
|
|
29
|
+
if (metadata) {
|
|
30
|
+
const newParamTypes = [...metadata];
|
|
31
|
+
newParamTypes[0] = dto;
|
|
32
|
+
Reflect.defineMetadata('design:paramtypes', newParamTypes, target, propertyKey);
|
|
33
|
+
}
|
|
34
|
+
return (0, common_1.Body)()(target, propertyKey, parameterIndex);
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
function Crud(options) {
|
|
38
|
+
return function (target) {
|
|
39
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
40
|
+
const queryUsesPagination = ((_a = options.operations) === null || _a === void 0 ? void 0 : _a.query) !== false ? ((_c = (_b = options.operations) === null || _b === void 0 ? void 0 : _b.query) === null || _c === void 0 ? void 0 : _c.pagination) !== false : false;
|
|
41
|
+
let CrudHost = class CrudHost {
|
|
42
|
+
async import(body, req, params) {
|
|
43
|
+
const self = this;
|
|
44
|
+
for (const item of body) {
|
|
45
|
+
if (options.persist) {
|
|
46
|
+
const persist = options.persist(req, params);
|
|
47
|
+
Object.assign(item, persist);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return self.service.createMany(body);
|
|
51
|
+
}
|
|
52
|
+
async create(body, req, params) {
|
|
53
|
+
const self = this;
|
|
54
|
+
if (options.persist) {
|
|
55
|
+
const persist = options.persist(req, params);
|
|
56
|
+
Object.assign(body, persist);
|
|
57
|
+
}
|
|
58
|
+
console.log('self', self);
|
|
59
|
+
return self.service.create(body);
|
|
60
|
+
}
|
|
61
|
+
async query(req, params, page, limit) {
|
|
62
|
+
var _a;
|
|
63
|
+
const self = this;
|
|
64
|
+
const filter = (_a = options === null || options === void 0 ? void 0 : options.filter) === null || _a === void 0 ? void 0 : _a.call(options, req, params);
|
|
65
|
+
if (!limit)
|
|
66
|
+
limit = 100;
|
|
67
|
+
if (!page)
|
|
68
|
+
page = 0;
|
|
69
|
+
if (queryUsesPagination) {
|
|
70
|
+
const [data, total] = await self.service.query(filter !== null && filter !== void 0 ? filter : {}, {
|
|
71
|
+
skip: page * limit,
|
|
72
|
+
take: limit
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
data,
|
|
76
|
+
total,
|
|
77
|
+
page,
|
|
78
|
+
limit,
|
|
79
|
+
totalPages: Math.ceil(total / limit),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return self.service.findAll(filter !== null && filter !== void 0 ? filter : {});
|
|
83
|
+
}
|
|
84
|
+
async export(nestReq, req, params, res) {
|
|
85
|
+
var _a, _b, _c;
|
|
86
|
+
const self = this;
|
|
87
|
+
const filter = (_b = (_a = options === null || options === void 0 ? void 0 : options.filter) === null || _a === void 0 ? void 0 : _a.call(options, nestReq, params)) !== null && _b !== void 0 ? _b : {};
|
|
88
|
+
const isCsv = req.headers['accept'] === 'text/csv';
|
|
89
|
+
const batchSize = 500;
|
|
90
|
+
let page = 0;
|
|
91
|
+
let aborted = false;
|
|
92
|
+
req.on('close', () => {
|
|
93
|
+
aborted = true;
|
|
94
|
+
});
|
|
95
|
+
async function* generateData() {
|
|
96
|
+
while (!aborted) {
|
|
97
|
+
const [items, _] = await self.service.query(filter, {
|
|
98
|
+
skip: page * batchSize,
|
|
99
|
+
take: batchSize
|
|
100
|
+
});
|
|
101
|
+
if (items.length === 0)
|
|
102
|
+
break;
|
|
103
|
+
for (const item of items) {
|
|
104
|
+
yield (0, class_transformer_1.instanceToPlain)(item);
|
|
105
|
+
}
|
|
106
|
+
if (items.length < batchSize)
|
|
107
|
+
break;
|
|
108
|
+
page++;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (isCsv) {
|
|
112
|
+
res.header('Content-Type', 'text/csv');
|
|
113
|
+
res.header('Content-Disposition', `attachment; filename=${(_c = options.tag) !== null && _c !== void 0 ? _c : 'export'}.csv`);
|
|
114
|
+
const transformOpts = { header: true };
|
|
115
|
+
const json2csv = new json2csv_1.Transform(transformOpts);
|
|
116
|
+
stream_1.Readable.from(generateData()).pipe(json2csv).pipe(res);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
res.header('Content-Type', 'application/json');
|
|
120
|
+
async function* generateJson() {
|
|
121
|
+
yield '[';
|
|
122
|
+
let first = true;
|
|
123
|
+
for await (const item of generateData()) {
|
|
124
|
+
if (!first)
|
|
125
|
+
yield ',';
|
|
126
|
+
yield JSON.stringify(item);
|
|
127
|
+
first = false;
|
|
128
|
+
}
|
|
129
|
+
yield ']';
|
|
130
|
+
}
|
|
131
|
+
stream_1.Readable.from(generateJson()).pipe(res);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async read(req, id, params) {
|
|
135
|
+
var _a;
|
|
136
|
+
const self = this;
|
|
137
|
+
const filter = (_a = options === null || options === void 0 ? void 0 : options.filter) === null || _a === void 0 ? void 0 : _a.call(options, req, params);
|
|
138
|
+
const result = await self.service.findOne({
|
|
139
|
+
...filter !== null && filter !== void 0 ? filter : {},
|
|
140
|
+
id: +id,
|
|
141
|
+
});
|
|
142
|
+
if (!result) {
|
|
143
|
+
throw new common_1.NotFoundException(`${entity_name_util_1.EntityNameUtil.getName(options.entity.name)} not found`);
|
|
144
|
+
}
|
|
145
|
+
console.log('result', result);
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
async delete(req, id, params) {
|
|
149
|
+
var _a;
|
|
150
|
+
const self = this;
|
|
151
|
+
const filter = (_a = options === null || options === void 0 ? void 0 : options.filter) === null || _a === void 0 ? void 0 : _a.call(options, req, params);
|
|
152
|
+
const result = await self.service.findOne({
|
|
153
|
+
...filter !== null && filter !== void 0 ? filter : {},
|
|
154
|
+
id: +id,
|
|
155
|
+
});
|
|
156
|
+
if (!result) {
|
|
157
|
+
throw new common_1.NotFoundException(`${entity_name_util_1.EntityNameUtil.getName(options.entity.name)} not found`);
|
|
158
|
+
}
|
|
159
|
+
return self.service.delete(result.id);
|
|
160
|
+
}
|
|
161
|
+
async replace(body, req, id, params) {
|
|
162
|
+
var _a;
|
|
163
|
+
const self = this;
|
|
164
|
+
const filter = (_a = options === null || options === void 0 ? void 0 : options.filter) === null || _a === void 0 ? void 0 : _a.call(options, req, params);
|
|
165
|
+
const result = await self.service.findOne({
|
|
166
|
+
...filter !== null && filter !== void 0 ? filter : {},
|
|
167
|
+
id: +id,
|
|
168
|
+
});
|
|
169
|
+
if (!result) {
|
|
170
|
+
throw new common_1.NotFoundException(`${entity_name_util_1.EntityNameUtil.getName(options.entity.name)} not found`);
|
|
171
|
+
}
|
|
172
|
+
return self.service.update(result.id, body);
|
|
173
|
+
}
|
|
174
|
+
async update(body, req, id, params) {
|
|
175
|
+
var _a;
|
|
176
|
+
const self = this;
|
|
177
|
+
const filter = (_a = options === null || options === void 0 ? void 0 : options.filter) === null || _a === void 0 ? void 0 : _a.call(options, req, params);
|
|
178
|
+
const result = await self.service.findOne({
|
|
179
|
+
...filter !== null && filter !== void 0 ? filter : {},
|
|
180
|
+
id: +id,
|
|
181
|
+
});
|
|
182
|
+
if (!result) {
|
|
183
|
+
throw new common_1.NotFoundException(`${entity_name_util_1.EntityNameUtil.getName(options.entity.name)} not found`);
|
|
184
|
+
}
|
|
185
|
+
return self.service.update(result.id, body);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
__decorate([
|
|
189
|
+
(0, common_1.Post)('import'),
|
|
190
|
+
(0, swagger_1.ApiBadRequestResponse)(),
|
|
191
|
+
(0, swagger_1.ApiInternalServerErrorResponse)(),
|
|
192
|
+
(0, swagger_1.ApiBody)({ type: [options.createDto] }),
|
|
193
|
+
(0, swagger_1.ApiResponse)({
|
|
194
|
+
status: 201,
|
|
195
|
+
description: 'The records where successfully created.',
|
|
196
|
+
type: [options.entity],
|
|
197
|
+
}),
|
|
198
|
+
__param(0, Body([options.createDto])),
|
|
199
|
+
__param(1, (0, common_1.Req)()),
|
|
200
|
+
__param(2, (0, common_1.Param)()),
|
|
201
|
+
__metadata("design:type", Function),
|
|
202
|
+
__metadata("design:paramtypes", [Array, Object, Object]),
|
|
203
|
+
__metadata("design:returntype", Promise)
|
|
204
|
+
], CrudHost.prototype, "import", null);
|
|
205
|
+
__decorate([
|
|
206
|
+
(0, common_1.Post)(),
|
|
207
|
+
(0, swagger_1.ApiBadRequestResponse)(),
|
|
208
|
+
(0, swagger_1.ApiInternalServerErrorResponse)(),
|
|
209
|
+
(0, swagger_1.ApiResponse)({
|
|
210
|
+
status: 201,
|
|
211
|
+
description: 'The record has been successfully created.',
|
|
212
|
+
type: options.entity,
|
|
213
|
+
}),
|
|
214
|
+
__param(0, Body(options.createDto)),
|
|
215
|
+
__param(1, (0, common_1.Req)()),
|
|
216
|
+
__param(2, (0, common_1.Param)()),
|
|
217
|
+
__metadata("design:type", Function),
|
|
218
|
+
__metadata("design:paramtypes", [Object, Object, Object]),
|
|
219
|
+
__metadata("design:returntype", Promise)
|
|
220
|
+
], CrudHost.prototype, "create", null);
|
|
221
|
+
__decorate([
|
|
222
|
+
(0, common_1.Get)(),
|
|
223
|
+
(0, swagger_1.ApiBadRequestResponse)(),
|
|
224
|
+
(0, swagger_1.ApiInternalServerErrorResponse)(),
|
|
225
|
+
(0, swagger_1.ApiResponse)({
|
|
226
|
+
status: 200,
|
|
227
|
+
schema: {
|
|
228
|
+
allOf: [
|
|
229
|
+
{ $ref: (0, swagger_1.getSchemaPath)(pagination_dto_1.PaginationDto) },
|
|
230
|
+
{
|
|
231
|
+
type: 'object',
|
|
232
|
+
required: ['data',],
|
|
233
|
+
properties: {
|
|
234
|
+
data: {
|
|
235
|
+
type: 'array',
|
|
236
|
+
items: { $ref: (0, swagger_1.getSchemaPath)(options.entity) },
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
},
|
|
242
|
+
}),
|
|
243
|
+
__param(0, (0, common_1.Req)()),
|
|
244
|
+
__param(1, (0, common_1.Param)()),
|
|
245
|
+
__param(2, (0, common_1.Query)('page')),
|
|
246
|
+
__param(3, (0, common_1.Query)('limit')),
|
|
247
|
+
__metadata("design:type", Function),
|
|
248
|
+
__metadata("design:paramtypes", [Object, Object, Number, Number]),
|
|
249
|
+
__metadata("design:returntype", Promise)
|
|
250
|
+
], CrudHost.prototype, "query", null);
|
|
251
|
+
__decorate([
|
|
252
|
+
(0, common_1.Get)("/export"),
|
|
253
|
+
(0, swagger_1.ApiBadRequestResponse)(),
|
|
254
|
+
(0, swagger_1.ApiInternalServerErrorResponse)(),
|
|
255
|
+
(0, swagger_1.ApiProduces)('application/json', 'text/csv'),
|
|
256
|
+
(0, swagger_1.ApiResponse)({
|
|
257
|
+
status: 200,
|
|
258
|
+
description: 'Export data',
|
|
259
|
+
content: {
|
|
260
|
+
'application/json': {
|
|
261
|
+
schema: {
|
|
262
|
+
type: 'array',
|
|
263
|
+
items: { $ref: (0, swagger_1.getSchemaPath)(options.entity) }
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
'text/csv': {
|
|
267
|
+
schema: {
|
|
268
|
+
type: 'string'
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}),
|
|
273
|
+
__param(0, (0, common_1.Req)()),
|
|
274
|
+
__param(1, (0, common_1.Req)()),
|
|
275
|
+
__param(2, (0, common_1.Param)()),
|
|
276
|
+
__param(3, (0, common_1.Res)({ passthrough: true })),
|
|
277
|
+
__metadata("design:type", Function),
|
|
278
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object]),
|
|
279
|
+
__metadata("design:returntype", Promise)
|
|
280
|
+
], CrudHost.prototype, "export", null);
|
|
281
|
+
__decorate([
|
|
282
|
+
(0, common_1.Get)(':id'),
|
|
283
|
+
(0, swagger_1.ApiNotFoundResponse)(),
|
|
284
|
+
(0, swagger_1.ApiBadRequestResponse)(),
|
|
285
|
+
(0, swagger_1.ApiInternalServerErrorResponse)(),
|
|
286
|
+
(0, swagger_1.ApiResponse)({
|
|
287
|
+
status: 200,
|
|
288
|
+
type: options.entity,
|
|
289
|
+
}),
|
|
290
|
+
__param(0, (0, common_1.Req)()),
|
|
291
|
+
__param(1, (0, common_1.Param)('id')),
|
|
292
|
+
__param(2, (0, common_1.Param)()),
|
|
293
|
+
__metadata("design:type", Function),
|
|
294
|
+
__metadata("design:paramtypes", [Object, String, Object]),
|
|
295
|
+
__metadata("design:returntype", Promise)
|
|
296
|
+
], CrudHost.prototype, "read", null);
|
|
297
|
+
__decorate([
|
|
298
|
+
(0, common_1.Delete)(':id'),
|
|
299
|
+
(0, swagger_1.ApiNotFoundResponse)(),
|
|
300
|
+
(0, swagger_1.ApiBadRequestResponse)(),
|
|
301
|
+
(0, swagger_1.ApiInternalServerErrorResponse)(),
|
|
302
|
+
(0, swagger_1.ApiResponse)({
|
|
303
|
+
status: 204,
|
|
304
|
+
}),
|
|
305
|
+
__param(0, (0, common_1.Req)()),
|
|
306
|
+
__param(1, (0, common_1.Param)('id')),
|
|
307
|
+
__param(2, (0, common_1.Param)()),
|
|
308
|
+
__metadata("design:type", Function),
|
|
309
|
+
__metadata("design:paramtypes", [Object, String, Object]),
|
|
310
|
+
__metadata("design:returntype", Promise)
|
|
311
|
+
], CrudHost.prototype, "delete", null);
|
|
312
|
+
__decorate([
|
|
313
|
+
(0, common_1.Patch)(':id'),
|
|
314
|
+
(0, swagger_1.ApiNotFoundResponse)(),
|
|
315
|
+
(0, swagger_1.ApiBadRequestResponse)(),
|
|
316
|
+
(0, swagger_1.ApiInternalServerErrorResponse)(),
|
|
317
|
+
(0, swagger_1.ApiResponse)({
|
|
318
|
+
status: 200,
|
|
319
|
+
type: options.entity,
|
|
320
|
+
}),
|
|
321
|
+
__param(0, Body(options.createDto)),
|
|
322
|
+
__param(1, (0, common_1.Req)()),
|
|
323
|
+
__param(2, (0, common_1.Param)('id')),
|
|
324
|
+
__param(3, (0, common_1.Param)()),
|
|
325
|
+
__metadata("design:type", Function),
|
|
326
|
+
__metadata("design:paramtypes", [Object, Object, String, Object]),
|
|
327
|
+
__metadata("design:returntype", Promise)
|
|
328
|
+
], CrudHost.prototype, "replace", null);
|
|
329
|
+
__decorate([
|
|
330
|
+
(0, common_1.Put)(':id'),
|
|
331
|
+
(0, swagger_1.ApiNotFoundResponse)(),
|
|
332
|
+
(0, swagger_1.ApiBadRequestResponse)(),
|
|
333
|
+
(0, swagger_1.ApiInternalServerErrorResponse)(),
|
|
334
|
+
(0, swagger_1.ApiResponse)({
|
|
335
|
+
status: 200,
|
|
336
|
+
type: options.entity,
|
|
337
|
+
}),
|
|
338
|
+
__param(0, Body(options.updateDto)),
|
|
339
|
+
__param(1, (0, common_1.Req)()),
|
|
340
|
+
__param(2, (0, common_1.Param)('id')),
|
|
341
|
+
__param(3, (0, common_1.Param)()),
|
|
342
|
+
__metadata("design:type", Function),
|
|
343
|
+
__metadata("design:paramtypes", [Object, Object, String, Object]),
|
|
344
|
+
__metadata("design:returntype", Promise)
|
|
345
|
+
], CrudHost.prototype, "update", null);
|
|
346
|
+
CrudHost = __decorate([
|
|
347
|
+
(0, swagger_1.ApiExtraModels)(pagination_dto_1.PaginationDto),
|
|
348
|
+
(0, swagger_1.ApiExtraModels)(options.createDto),
|
|
349
|
+
(0, swagger_1.ApiExtraModels)(options.updateDto),
|
|
350
|
+
(0, swagger_1.ApiTags)((_d = options.tag) !== null && _d !== void 0 ? _d : entity_name_util_1.EntityNameUtil.classToName(options.entity))
|
|
351
|
+
], CrudHost);
|
|
352
|
+
const methods = Object.getOwnPropertyNames(CrudHost.prototype).filter(method => method !== 'constructor');
|
|
353
|
+
const path = Reflect.getMetadata('path', target);
|
|
354
|
+
const params = [];
|
|
355
|
+
if (path) {
|
|
356
|
+
const pathStr = Array.isArray(path) ? path[0] : path;
|
|
357
|
+
if (typeof pathStr === 'string') {
|
|
358
|
+
const regex = /:([^\/]+)/g;
|
|
359
|
+
let match;
|
|
360
|
+
while ((match = regex.exec(pathStr)) !== null) {
|
|
361
|
+
params.push(match[1]);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
for (const param of params) {
|
|
366
|
+
const apiParamDecorator = (0, swagger_1.ApiParam)({ name: param, type: 'string' });
|
|
367
|
+
for (const method of methods) {
|
|
368
|
+
const descriptor = Object.getOwnPropertyDescriptor(CrudHost.prototype, method);
|
|
369
|
+
if (descriptor) {
|
|
370
|
+
apiParamDecorator(CrudHost.prototype, method, descriptor);
|
|
371
|
+
Object.defineProperty(CrudHost.prototype, method, descriptor);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (((_e = options.operations) === null || _e === void 0 ? void 0 : _e.create) === false) {
|
|
376
|
+
delete CrudHost.prototype.create;
|
|
377
|
+
}
|
|
378
|
+
if (((_f = options.operations) === null || _f === void 0 ? void 0 : _f.update) === false) {
|
|
379
|
+
delete CrudHost.prototype.update;
|
|
380
|
+
}
|
|
381
|
+
if (((_g = options.operations) === null || _g === void 0 ? void 0 : _g.read) === false) {
|
|
382
|
+
delete CrudHost.prototype.read;
|
|
383
|
+
}
|
|
384
|
+
if (((_h = options.operations) === null || _h === void 0 ? void 0 : _h.query) === false) {
|
|
385
|
+
delete CrudHost.prototype.query;
|
|
386
|
+
}
|
|
387
|
+
if (((_j = options.operations) === null || _j === void 0 ? void 0 : _j.import) !== true) {
|
|
388
|
+
delete CrudHost.prototype.import;
|
|
389
|
+
}
|
|
390
|
+
if (((_k = options.operations) === null || _k === void 0 ? void 0 : _k.export) !== true) {
|
|
391
|
+
delete CrudHost.prototype.export;
|
|
392
|
+
}
|
|
393
|
+
if (((_l = options.operations) === null || _l === void 0 ? void 0 : _l.delete) !== true) {
|
|
394
|
+
delete CrudHost.prototype.delete;
|
|
395
|
+
}
|
|
396
|
+
if (((_m = options.operations) === null || _m === void 0 ? void 0 : _m.replace) !== true) {
|
|
397
|
+
delete CrudHost.prototype.replace;
|
|
398
|
+
}
|
|
399
|
+
for (const key of Object.getOwnPropertyNames(CrudHost.prototype)) {
|
|
400
|
+
if (key === 'constructor')
|
|
401
|
+
continue;
|
|
402
|
+
const metadata = Reflect.getMetadata('design:paramtypes', CrudHost.prototype, key);
|
|
403
|
+
Reflect.defineMetadata('design:paramtypes', [...metadata], CrudHost.prototype, key);
|
|
404
|
+
}
|
|
405
|
+
const originalParent = Object.getPrototypeOf(target.prototype);
|
|
406
|
+
Object.setPrototypeOf(CrudHost.prototype, originalParent);
|
|
407
|
+
Object.setPrototypeOf(target.prototype, CrudHost.prototype);
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
//# sourceMappingURL=crud.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.decorator.js","sourceRoot":"","sources":["../../../src/common/decorators/crud.decorator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAqEA,oBA8XC;AAncD,2CAA2J;AAG3J,uCAAqC;AACrC,mCAAkC;AAClC,yDAAoD;AAEpD,gEAA2D;AAC3D,6CAAkM;AAClM,0DAAsD;AAwCtD,MAAM,IAAI,GAAG,CAAK,GAAwB,EAAE,EAAE;IAC5C,OAAO,CACL,MAAc,EACd,WAA4B,EAC5B,cAAsB,EACtB,EAAE;QACF,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YACvB,OAAO,IAAA,aAAQ,EAAC,IAAI,uBAAc,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;QAC9F,CAAC;QACD,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,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C,CAAC;QAID,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YACjE,IAAI,GAAG,KAAK,aAAa;gBAAE,SAAS;YACpC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;YACnF,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;QACtF,CAAC;QAMD,MAAM,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAG/D,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QAI1D,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC9D,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Embedded = Embedded;
|
|
4
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const EMBEDDED_METADATA_KEY = 'custom:embedded_properties';
|
|
7
|
+
const EMBEDDED_CLASS_KEY = 'custom:embedded_class';
|
|
8
|
+
function Embedded(typeFunc) {
|
|
9
|
+
return (target, propertyKey) => {
|
|
10
|
+
const properties = Reflect.getMetadata(EMBEDDED_METADATA_KEY, target) || [];
|
|
11
|
+
if (!properties.includes(propertyKey)) {
|
|
12
|
+
properties.push(propertyKey);
|
|
13
|
+
Reflect.defineMetadata(EMBEDDED_METADATA_KEY, properties, target);
|
|
14
|
+
}
|
|
15
|
+
(0, class_transformer_1.Exclude)()(target, propertyKey);
|
|
16
|
+
(0, swagger_1.ApiHideProperty)()(target, propertyKey);
|
|
17
|
+
const targetConstructor = target.constructor;
|
|
18
|
+
let EmbeddedClass = Reflect.getMetadata(EMBEDDED_CLASS_KEY, targetConstructor);
|
|
19
|
+
if (!EmbeddedClass) {
|
|
20
|
+
EmbeddedClass = class {
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(EmbeddedClass, 'name', { value: `${targetConstructor.name}Embedded` });
|
|
23
|
+
Reflect.defineMetadata(EMBEDDED_CLASS_KEY, EmbeddedClass, targetConstructor);
|
|
24
|
+
Object.defineProperty(target, '_embedded', {
|
|
25
|
+
get: function () {
|
|
26
|
+
const embeddedProps = Reflect.getMetadata(EMBEDDED_METADATA_KEY, target) || [];
|
|
27
|
+
const result = {};
|
|
28
|
+
let hasValues = false;
|
|
29
|
+
for (const prop of embeddedProps) {
|
|
30
|
+
if (this[prop] !== undefined && this[prop] !== null) {
|
|
31
|
+
result[prop] = this[prop];
|
|
32
|
+
hasValues = true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return hasValues ? result : undefined;
|
|
36
|
+
},
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
});
|
|
40
|
+
(0, class_transformer_1.Expose)()(target, '_embedded');
|
|
41
|
+
(0, swagger_1.ApiProperty)({ type: EmbeddedClass })(target, '_embedded');
|
|
42
|
+
(0, class_transformer_1.Type)(() => EmbeddedClass)(target, '_embedded');
|
|
43
|
+
}
|
|
44
|
+
const designType = Reflect.getMetadata('design:type', target, propertyKey);
|
|
45
|
+
const isArray = designType === Array;
|
|
46
|
+
const resolvedType = typeFunc ? typeFunc() : designType;
|
|
47
|
+
Object.defineProperty(EmbeddedClass.prototype, propertyKey, {
|
|
48
|
+
value: undefined,
|
|
49
|
+
writable: true,
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
});
|
|
53
|
+
(0, class_transformer_1.Expose)()(EmbeddedClass.prototype, propertyKey);
|
|
54
|
+
if (isArray && resolvedType) {
|
|
55
|
+
(0, swagger_1.ApiProperty)({ type: resolvedType, isArray: true })(EmbeddedClass.prototype, propertyKey);
|
|
56
|
+
(0, class_transformer_1.Type)(() => resolvedType)(EmbeddedClass.prototype, propertyKey);
|
|
57
|
+
}
|
|
58
|
+
else if (resolvedType) {
|
|
59
|
+
(0, swagger_1.ApiProperty)({ type: resolvedType })(EmbeddedClass.prototype, propertyKey);
|
|
60
|
+
(0, class_transformer_1.Type)(() => resolvedType)(EmbeddedClass.prototype, propertyKey);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
(0, swagger_1.ApiProperty)()(EmbeddedClass.prototype, propertyKey);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=embedded.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedded.decorator.js","sourceRoot":"","sources":["../../../src/common/decorators/embedded.decorator.ts"],"names":[],"mappings":";;AAOA,4BAgFC;AAtFD,6CAA+D;AAC/D,yDAA2E;AAE3E,MAAM,qBAAqB,GAAG,4BAA4B,CAAC;AAC3D,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;AAEnD,SAAgB,QAAQ,CAAC,QAA0B;IACjD,OAAO,CAAC,MAAW,EAAE,WAA4B,EAAE,EAAE;QAEnD,MAAM,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,qBAAqB,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5E,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YACtC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC7B,OAAO,CAAC,cAAc,CAAC,qBAAqB,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;QACpE,CAAC;QAGD,IAAA,2BAAO,GAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAC/B,IAAA,yBAAe,GA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AE,CAAC,aAAa,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QACxD,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PaginationDto = void 0;
|
|
13
|
+
const class_transformer_1 = require("class-transformer");
|
|
14
|
+
class PaginationDto {
|
|
15
|
+
}
|
|
16
|
+
exports.PaginationDto = PaginationDto;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, class_transformer_1.Expose)(),
|
|
19
|
+
__metadata("design:type", Number)
|
|
20
|
+
], PaginationDto.prototype, "page", void 0);
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, class_transformer_1.Expose)(),
|
|
23
|
+
__metadata("design:type", Number)
|
|
24
|
+
], PaginationDto.prototype, "limit", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, class_transformer_1.Expose)(),
|
|
27
|
+
__metadata("design:type", Number)
|
|
28
|
+
], PaginationDto.prototype, "totalPages", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, class_transformer_1.Expose)(),
|
|
31
|
+
__metadata("design:type", Number)
|
|
32
|
+
], PaginationDto.prototype, "total", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, class_transformer_1.Expose)(),
|
|
35
|
+
__metadata("design:type", Array)
|
|
36
|
+
], PaginationDto.prototype, "data", void 0);
|
|
37
|
+
//# sourceMappingURL=pagination.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.dto.js","sourceRoot":"","sources":["../../../src/common/dto/pagination.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAA2C;AAE3C,MAAa,aAAa;CAezB;AAfD,sCAeC;AAbG;IADC,IAAA,0BAAM,GAAE;;2CACI;AAGb;IADC,IAAA,0BAAM,GAAE;;4CACK;AAGd;IADC,IAAA,0BAAM,GAAE;;iDACU;AAGnB;IADC,IAAA,0BAAM,GAAE;;4CACK;AAGd;IADC,IAAA,0BAAM,GAAE;;2CACC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class EntityNameUtil {
|
|
2
|
+
static routeToName(route: string): string;
|
|
3
|
+
static classToName(entityClass: any): string;
|
|
4
|
+
static getName(route?: string, entityClass?: any): string;
|
|
5
|
+
static pluralize(name: string): string;
|
|
6
|
+
static capitalize(name: string): string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityNameUtil = void 0;
|
|
4
|
+
class EntityNameUtil {
|
|
5
|
+
static routeToName(route) {
|
|
6
|
+
return route.replace(/-/g, ' ').replace(/s$/, '').trim();
|
|
7
|
+
}
|
|
8
|
+
static classToName(entityClass) {
|
|
9
|
+
if (!entityClass || !entityClass.name) {
|
|
10
|
+
return 'item';
|
|
11
|
+
}
|
|
12
|
+
const name = entityClass.name
|
|
13
|
+
.replace(/([A-Z])/g, ' $1')
|
|
14
|
+
.toLowerCase()
|
|
15
|
+
.trim();
|
|
16
|
+
return name.replace(/\s+entity$/, '').trim();
|
|
17
|
+
}
|
|
18
|
+
static getName(route, entityClass) {
|
|
19
|
+
if (route) {
|
|
20
|
+
return this.routeToName(route);
|
|
21
|
+
}
|
|
22
|
+
if (entityClass) {
|
|
23
|
+
return this.classToName(entityClass);
|
|
24
|
+
}
|
|
25
|
+
return 'item';
|
|
26
|
+
}
|
|
27
|
+
static pluralize(name) {
|
|
28
|
+
if (name.endsWith('y')) {
|
|
29
|
+
return name.slice(0, -1) + 'ies';
|
|
30
|
+
}
|
|
31
|
+
if (name.endsWith('s') || name.endsWith('x') || name.endsWith('z') || name.endsWith('ch') || name.endsWith('sh')) {
|
|
32
|
+
return name + 'es';
|
|
33
|
+
}
|
|
34
|
+
return name + 's';
|
|
35
|
+
}
|
|
36
|
+
static capitalize(name) {
|
|
37
|
+
return name.split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.EntityNameUtil = EntityNameUtil;
|
|
41
|
+
//# sourceMappingURL=entity-name.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-name.util.js","sourceRoot":"","sources":["../../../src/common/utils/entity-name.util.ts"],"names":[],"mappings":";;;AAGA,MAAa,cAAc;IAIzB,MAAM,CAAC,WAAW,CAAC,KAAa;QAC9B,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC3D,CAAC;IAKD,MAAM,CAAC,WAAW,CAAC,WAAgB;QACjC,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YACtC,OAAO,MAAM,CAAC;QAChB,CAAC;QAID,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI;aAC1B,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC;aAC1B,WAAW,EAAE;aACb,IAAI,E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/build/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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("./common/decorators/crud.decorator"), exports);
|
|
18
|
+
__exportStar(require("./common/decorators/embedded.decorator"), exports);
|
|
19
|
+
__exportStar(require("./common/base.service"), exports);
|
|
20
|
+
__exportStar(require("./common/dto/pagination.dto"), exports);
|
|
21
|
+
__exportStar(require("./common/utils/entity-name.util"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qEAAmD;AACnD,yEAAuD;AACvD,wDAAsC;AACtC,8DAA4C;AAC5C,kEAAgD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@foxiko/nest-common",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./build/index.js",
|
|
6
|
+
"typings": "./build/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"build"
|
|
9
|
+
],
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"@nestjs/common": "^11.0.0",
|
|
12
|
+
"@nestjs/core": "^11.0.0",
|
|
13
|
+
"@nestjs/typeorm": "^11.0.0",
|
|
14
|
+
"@nestjs/swagger": "^11.2.3",
|
|
15
|
+
"express": "^5.2.1",
|
|
16
|
+
"typeorm": "^0.3.28",
|
|
17
|
+
"class-transformer": "^0.5.1",
|
|
18
|
+
"class-validator": "^0.14.2"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
23
|
+
},
|
|
24
|
+
"author": "",
|
|
25
|
+
"license": "ISC",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/express": "^5.0.6",
|
|
28
|
+
"@types/json2csv": "^5.0.7",
|
|
29
|
+
"typescript": "^5.9.3"
|
|
30
|
+
}
|
|
31
|
+
}
|