dev4fun-utils 0.0.1 → 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/README.md +310 -68
- package/package.json +7 -15
- package/dist/common/base/base.typeorm.d.ts +0 -9
- package/dist/common/base/base.typeorm.js +0 -75
- package/dist/common/base/base.typeorm.js.map +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -18
- package/dist/index.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -1,98 +1,340 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
|
7
|
-
|
|
8
|
-
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
|
9
|
-
<p align="center">
|
|
10
|
-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
|
11
|
-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
|
12
|
-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
|
13
|
-
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
|
14
|
-
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
|
15
|
-
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
|
16
|
-
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
|
17
|
-
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
|
|
18
|
-
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
|
19
|
-
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
|
|
20
|
-
</p>
|
|
21
|
-
<!--[](https://opencollective.com/nest#backer)
|
|
22
|
-
[](https://opencollective.com/nest#sponsor)-->
|
|
23
|
-
|
|
24
|
-
## Description
|
|
25
|
-
|
|
26
|
-
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
|
27
|
-
|
|
28
|
-
## Project setup
|
|
1
|
+
# dev4fun-utils
|
|
2
|
+
|
|
3
|
+
Thư viện tiện ích cho NestJS với TypeORM base entities, decorators và các công cụ hỗ trợ phổ biến.
|
|
4
|
+
|
|
5
|
+
## Cài đặt
|
|
29
6
|
|
|
30
7
|
```bash
|
|
31
|
-
|
|
8
|
+
bun add dev4fun-utils
|
|
32
9
|
```
|
|
33
10
|
|
|
34
|
-
|
|
11
|
+
hoặc
|
|
35
12
|
|
|
36
13
|
```bash
|
|
37
|
-
|
|
38
|
-
|
|
14
|
+
npm install dev4fun-utils
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Tính năng
|
|
18
|
+
|
|
19
|
+
### Base Entities
|
|
20
|
+
|
|
21
|
+
#### BaseTypeormEntity
|
|
22
|
+
|
|
23
|
+
Base entity cho TypeORM với các trường tự động:
|
|
24
|
+
- `id`: Primary key tự động tăng
|
|
25
|
+
- `createdAt`: Thời gian tạo (timestamp)
|
|
26
|
+
- `updatedAt`: Thời gian cập nhật (timestamp)
|
|
27
|
+
- `deletedAt`: Thời gian xóa (soft delete, timestamp)
|
|
39
28
|
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
```typescript
|
|
30
|
+
import { BaseTypeormEntity } from 'dev4fun-utils';
|
|
31
|
+
import { Entity } from 'typeorm';
|
|
42
32
|
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
@Entity()
|
|
34
|
+
export class User extends BaseTypeormEntity {
|
|
35
|
+
// Các trường của bạn
|
|
36
|
+
}
|
|
45
37
|
```
|
|
46
38
|
|
|
47
|
-
|
|
39
|
+
### Base Exception
|
|
48
40
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
#### BaseException
|
|
42
|
+
|
|
43
|
+
Class exception mở rộng từ HttpException với mã lỗi tùy chỉnh:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { BaseException } from 'dev4fun-utils';
|
|
52
47
|
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
// Sử dụng các exception có sẵn
|
|
49
|
+
throw BaseException.NOT_FOUND;
|
|
50
|
+
throw BaseException.BAD_REQUEST;
|
|
51
|
+
throw BaseException.UNAUTHORIZED;
|
|
52
|
+
throw BaseException.FORBIDDEN;
|
|
53
|
+
throw BaseException.INTERNAL_SERVER_ERROR;
|
|
54
|
+
throw BaseException.SERVICE_UNAVAILABLE;
|
|
55
|
+
throw BaseException.GATEWAY_TIMEOUT;
|
|
56
|
+
throw BaseException.PRECONDITION_FAILED;
|
|
57
|
+
throw BaseException.PAYLOAD_TOO_LARGE;
|
|
58
|
+
throw BaseException.UNPROCESSABLE_ENTITY;
|
|
59
|
+
throw BaseException.TOO_MANY_REQUESTS;
|
|
55
60
|
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
// Hoặc tạo exception tùy chỉnh
|
|
62
|
+
throw new BaseException('Custom message', 400, 'CUSTOM_ERROR');
|
|
58
63
|
```
|
|
59
64
|
|
|
60
|
-
|
|
65
|
+
### Decorators
|
|
61
66
|
|
|
62
|
-
|
|
67
|
+
#### @Retry
|
|
63
68
|
|
|
64
|
-
|
|
69
|
+
Thử lại method khi gặp lỗi:
|
|
65
70
|
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
```typescript
|
|
72
|
+
import { Retry } from 'dev4fun-utils';
|
|
73
|
+
|
|
74
|
+
class MyService {
|
|
75
|
+
@Retry(3, 1000) // Thử lại 3 lần, mỗi lần cách nhau 1 giây
|
|
76
|
+
async fetchData() {
|
|
77
|
+
// Code của bạn
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### @Timeout
|
|
83
|
+
|
|
84
|
+
Thiết lập timeout cho method:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { Timeout } from 'dev4fun-utils';
|
|
88
|
+
|
|
89
|
+
class MyService {
|
|
90
|
+
@Timeout(5000) // Timeout sau 5 giây
|
|
91
|
+
async fetchData() {
|
|
92
|
+
// Code của bạn
|
|
93
|
+
}
|
|
94
|
+
}
|
|
69
95
|
```
|
|
70
96
|
|
|
71
|
-
|
|
97
|
+
#### @Cache
|
|
72
98
|
|
|
73
|
-
|
|
99
|
+
Cache kết quả của method:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { Cache } from 'dev4fun-utils';
|
|
103
|
+
|
|
104
|
+
class MyService {
|
|
105
|
+
@Cache(60000) // Cache trong 60 giây
|
|
106
|
+
async getData() {
|
|
107
|
+
// Code của bạn
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
74
111
|
|
|
75
|
-
|
|
112
|
+
#### @Watch
|
|
76
113
|
|
|
77
|
-
|
|
78
|
-
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
|
|
79
|
-
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
|
|
80
|
-
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
|
|
81
|
-
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
|
|
82
|
-
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
|
|
83
|
-
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
|
|
84
|
-
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).
|
|
114
|
+
Log thông tin khi method được gọi:
|
|
85
115
|
|
|
86
|
-
|
|
116
|
+
```typescript
|
|
117
|
+
import { Watch } from 'dev4fun-utils';
|
|
87
118
|
|
|
88
|
-
|
|
119
|
+
class MyService {
|
|
120
|
+
@Watch()
|
|
121
|
+
async processData(data: any) {
|
|
122
|
+
// Code của bạn
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### @Validate và @NonNull
|
|
128
|
+
|
|
129
|
+
Validate tham số không được null:
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { Validate, NonNull } from 'dev4fun-utils';
|
|
133
|
+
|
|
134
|
+
class MyService {
|
|
135
|
+
@Validate()
|
|
136
|
+
async processData(@NonNull data: string) {
|
|
137
|
+
// Code của bạn
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
89
141
|
|
|
90
|
-
|
|
142
|
+
### DTOs
|
|
91
143
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
144
|
+
#### IdDto
|
|
145
|
+
|
|
146
|
+
DTO cho ID:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { IdDto } from 'dev4fun-utils';
|
|
150
|
+
|
|
151
|
+
class MyController {
|
|
152
|
+
@Get(':id')
|
|
153
|
+
async getById(@Param() params: IdDto) {
|
|
154
|
+
// params.id là number
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### PageDto
|
|
160
|
+
|
|
161
|
+
DTO cho phân trang:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { PageDto } from 'dev4fun-utils';
|
|
165
|
+
|
|
166
|
+
class MyController {
|
|
167
|
+
@Get()
|
|
168
|
+
async getList(@Query() query: PageDto) {
|
|
169
|
+
// query.page, query.size, query.search, query.sort
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### TimeDto
|
|
175
|
+
|
|
176
|
+
DTO cho khoảng thời gian:
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
import { TimeDto } from 'dev4fun-utils';
|
|
180
|
+
|
|
181
|
+
class MyController {
|
|
182
|
+
@Get()
|
|
183
|
+
async getByTime(@Query() query: TimeDto) {
|
|
184
|
+
// query.startDate, query.endDate
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Structs
|
|
190
|
+
|
|
191
|
+
#### Page
|
|
192
|
+
|
|
193
|
+
Struct cho phân trang với TypeORM:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
import { Page, PageDto } from 'dev4fun-utils';
|
|
197
|
+
import { SelectQueryBuilder } from 'typeorm';
|
|
198
|
+
|
|
199
|
+
async function getUsers(dto: PageDto) {
|
|
200
|
+
const page = new Page(dto, 0);
|
|
201
|
+
page.queryBuilder = userRepository.createQueryBuilder('user');
|
|
202
|
+
await page.execute();
|
|
203
|
+
return page; // page.data, page.total, page.totalPages, etc.
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
#### Batch
|
|
208
|
+
|
|
209
|
+
Xử lý dữ liệu theo batch:
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
import { Batch } from 'dev4fun-utils';
|
|
213
|
+
|
|
214
|
+
const batch = Batch.fromArray([1, 2, 3, 4, 5], 2); // Chia thành batch 2 phần tử
|
|
215
|
+
|
|
216
|
+
await batch.runAsync(async (items, index) => {
|
|
217
|
+
console.log(`Batch ${index}:`, items);
|
|
218
|
+
}, false, 1000); // Chạy tuần tự, delay 1 giây giữa các batch
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
#### Queue
|
|
222
|
+
|
|
223
|
+
Hàng đợi (FIFO):
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
import { Queue } from 'dev4fun-utils';
|
|
227
|
+
|
|
228
|
+
const queue = Queue.fromArray([1, 2, 3]);
|
|
229
|
+
|
|
230
|
+
queue.enqueue(4); // Thêm vào cuối
|
|
231
|
+
const item = queue.dequeue(); // Lấy phần tử đầu tiên
|
|
232
|
+
const peek = queue.peek(); // Xem phần tử đầu tiên không xóa
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
#### Stack
|
|
236
|
+
|
|
237
|
+
Ngăn xếp (LIFO):
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
import { Stack } from 'dev4fun-utils';
|
|
241
|
+
|
|
242
|
+
const stack = Stack.fromArray([1, 2, 3]);
|
|
243
|
+
|
|
244
|
+
stack.push(4); // Thêm vào đầu
|
|
245
|
+
const item = stack.pop(); // Lấy phần tử đầu tiên
|
|
246
|
+
const top = stack.top(); // Xem phần tử đầu tiên không xóa
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### Tree
|
|
250
|
+
|
|
251
|
+
Cấu trúc cây:
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
import { Tree, TreeNode } from 'dev4fun-utils';
|
|
255
|
+
|
|
256
|
+
const tree = new Tree('root');
|
|
257
|
+
const node1 = tree.addNode('node1');
|
|
258
|
+
const node2 = tree.addNode('node2');
|
|
259
|
+
|
|
260
|
+
node1.addChild(new TreeNode('child1', node1));
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Utils
|
|
264
|
+
|
|
265
|
+
#### MethodUtil
|
|
266
|
+
|
|
267
|
+
Các tiện ích cho method:
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
import { MethodUtil } from 'dev4fun-utils';
|
|
271
|
+
|
|
272
|
+
// Delay
|
|
273
|
+
await MethodUtil.delay(1000); // Delay 1 giây
|
|
274
|
+
|
|
275
|
+
// Execute với timeout
|
|
276
|
+
await MethodUtil.executeWithTimeout(promise, 5000);
|
|
277
|
+
|
|
278
|
+
// Execute với retry
|
|
279
|
+
await MethodUtil.executeWithRetry(promise, 3, 1000);
|
|
280
|
+
|
|
281
|
+
// Execute command
|
|
282
|
+
const output = await MethodUtil.cmdExecute('ls -la');
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
#### NumberUtil
|
|
286
|
+
|
|
287
|
+
Các tiện ích cho số:
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
import { NumberUtil } from 'dev4fun-utils';
|
|
291
|
+
|
|
292
|
+
// Random integer
|
|
293
|
+
const num = NumberUtil.nextInt(1, 100);
|
|
294
|
+
|
|
295
|
+
// Random float
|
|
296
|
+
const float = NumberUtil.nextFloat(0, 1);
|
|
297
|
+
|
|
298
|
+
// Format VND
|
|
299
|
+
const formatted = NumberUtil.formatVND(1000000); // "1,000,000"
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
#### StringUtil
|
|
303
|
+
|
|
304
|
+
Các tiện ích cho chuỗi:
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
import { StringUtil } from 'dev4fun-utils';
|
|
308
|
+
|
|
309
|
+
// Hash password
|
|
310
|
+
const hash = await StringUtil.hashValue('password', 16);
|
|
311
|
+
|
|
312
|
+
// Verify hash
|
|
313
|
+
const isValid = await StringUtil.verifyHash('password', hash);
|
|
314
|
+
|
|
315
|
+
// Random string
|
|
316
|
+
const random = StringUtil.randomString(10);
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Module
|
|
320
|
+
|
|
321
|
+
Import CommonModule vào ứng dụng NestJS của bạn:
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
import { CommonModule } from 'dev4fun-utils';
|
|
325
|
+
import { Module } from '@nestjs/common';
|
|
326
|
+
|
|
327
|
+
@Module({
|
|
328
|
+
imports: [CommonModule],
|
|
329
|
+
})
|
|
330
|
+
export class AppModule {}
|
|
331
|
+
```
|
|
95
332
|
|
|
96
333
|
## License
|
|
97
334
|
|
|
98
|
-
|
|
335
|
+
MIT
|
|
336
|
+
|
|
337
|
+
## Author
|
|
338
|
+
|
|
339
|
+
Nguyen Chau Tuan
|
|
340
|
+
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dev4fun-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Utility package for NestJS with TypeORM base entities and common decorators",
|
|
5
|
-
"author": "",
|
|
5
|
+
"author": "Nguyen Chau Tuan",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
@@ -19,30 +19,22 @@
|
|
|
19
19
|
],
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": ""
|
|
22
|
+
"url": "https://github.com/nctuanit/dev4fun-utils"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "nest build",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"start": "nest start",
|
|
29
|
-
"start:dev": "nest start --watch",
|
|
30
|
-
"start:debug": "nest start --debug --watch",
|
|
31
|
-
"start:prod": "node dist/main",
|
|
32
|
-
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
33
|
-
"test": "jest",
|
|
34
|
-
"test:watch": "jest --watch",
|
|
35
|
-
"test:cov": "jest --coverage",
|
|
36
|
-
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
37
|
-
"test:e2e": "jest --config ./test/jest-e2e.json"
|
|
26
|
+
"publish": "npm run build && npm version patch && bun publish --access public",
|
|
27
|
+
"version": "node updateversion.js"
|
|
38
28
|
},
|
|
39
29
|
"dependencies": {
|
|
40
30
|
"@nestjs/common": "^11.0.1",
|
|
41
31
|
"@nestjs/core": "^11.0.1",
|
|
42
32
|
"@nestjs/platform-express": "^11.0.1",
|
|
43
33
|
"@nestjs/swagger": "^11.2.3",
|
|
34
|
+
"argon2": "^0.44.0",
|
|
44
35
|
"class-transformer": "^0.5.1",
|
|
45
36
|
"class-validator": "^0.14.3",
|
|
37
|
+
"hashids": "^2.3.0",
|
|
46
38
|
"pg": "^8.16.3",
|
|
47
39
|
"reflect-metadata": "^0.2.2",
|
|
48
40
|
"rxjs": "^7.8.1",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare abstract class BaseTypeormEntity {
|
|
2
|
-
readonly id: number;
|
|
3
|
-
readonly createdAt: number;
|
|
4
|
-
readonly updatedAt: number;
|
|
5
|
-
readonly deletedAt?: number;
|
|
6
|
-
static IsEntity(): boolean;
|
|
7
|
-
constructor(data?: Partial<BaseTypeormEntity>);
|
|
8
|
-
addJson(data: Partial<this>): void;
|
|
9
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
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.BaseTypeormEntity = void 0;
|
|
13
|
-
const typeorm_1 = require("typeorm");
|
|
14
|
-
const class_validator_1 = require("class-validator");
|
|
15
|
-
const swagger_1 = require("@nestjs/swagger");
|
|
16
|
-
const class_transformer_1 = require("class-transformer");
|
|
17
|
-
class BaseTypeormEntity {
|
|
18
|
-
id;
|
|
19
|
-
createdAt;
|
|
20
|
-
updatedAt;
|
|
21
|
-
deletedAt;
|
|
22
|
-
static IsEntity() {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
constructor(data) {
|
|
26
|
-
if (data) {
|
|
27
|
-
Object.assign(this, data);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
addJson(data) {
|
|
31
|
-
Object.assign(this, data);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.BaseTypeormEntity = BaseTypeormEntity;
|
|
35
|
-
__decorate([
|
|
36
|
-
(0, typeorm_1.PrimaryGeneratedColumn)(),
|
|
37
|
-
(0, class_validator_1.IsNumber)(),
|
|
38
|
-
(0, class_validator_1.Min)(0),
|
|
39
|
-
(0, swagger_1.ApiProperty)({
|
|
40
|
-
description: 'The id of the entity',
|
|
41
|
-
example: 1,
|
|
42
|
-
}),
|
|
43
|
-
__metadata("design:type", Number)
|
|
44
|
-
], BaseTypeormEntity.prototype, "id", void 0);
|
|
45
|
-
__decorate([
|
|
46
|
-
(0, typeorm_1.CreateDateColumn)({ type: 'timestamp' }),
|
|
47
|
-
(0, swagger_1.ApiProperty)({
|
|
48
|
-
description: 'The creation date of the entity',
|
|
49
|
-
example: Date.now(),
|
|
50
|
-
type: Number,
|
|
51
|
-
}),
|
|
52
|
-
(0, class_transformer_1.Transform)(({ value }) => value ? new Date(value).getTime() : null),
|
|
53
|
-
__metadata("design:type", Number)
|
|
54
|
-
], BaseTypeormEntity.prototype, "createdAt", void 0);
|
|
55
|
-
__decorate([
|
|
56
|
-
(0, typeorm_1.UpdateDateColumn)({ type: 'timestamp' }),
|
|
57
|
-
(0, swagger_1.ApiProperty)({
|
|
58
|
-
description: 'The update date of the entity',
|
|
59
|
-
example: Date.now(),
|
|
60
|
-
type: Number,
|
|
61
|
-
}),
|
|
62
|
-
(0, class_transformer_1.Transform)(({ value }) => value ? new Date(value).getTime() : null),
|
|
63
|
-
__metadata("design:type", Number)
|
|
64
|
-
], BaseTypeormEntity.prototype, "updatedAt", void 0);
|
|
65
|
-
__decorate([
|
|
66
|
-
(0, typeorm_1.DeleteDateColumn)({ type: 'timestamp' }),
|
|
67
|
-
(0, swagger_1.ApiProperty)({
|
|
68
|
-
description: 'The deletion date of the entity',
|
|
69
|
-
example: Date.now(),
|
|
70
|
-
type: Number,
|
|
71
|
-
}),
|
|
72
|
-
(0, class_transformer_1.Transform)(({ value }) => value ? new Date(value).getTime() : null),
|
|
73
|
-
__metadata("design:type", Number)
|
|
74
|
-
], BaseTypeormEntity.prototype, "deletedAt", void 0);
|
|
75
|
-
//# sourceMappingURL=base.typeorm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base.typeorm.js","sourceRoot":"","sources":["../../../src/common/base/base.typeorm.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAuH;AACvH,qDAA4D;AAC5D,6CAA8C;AAC9C,yDAA8C;AAE9C,MAAsB,iBAAiB;IAQ1B,EAAE,CAAS;IASX,SAAS,CAAS;IASlB,SAAS,CAAS;IASlB,SAAS,CAAU;IAE5B,MAAM,CAAC,QAAQ;QACX,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,YAAY,IAAiC;QACzC,IAAI,IAAI,EAAE,CAAC;YACP,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC9B,CAAC;IACL,CAAC;IAED,OAAO,CAAC,IAAmB;QACvB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;CACJ;AAlDD,8CAkDC;AA1CY;IAPR,IAAA,gCAAsB,GAAE;IACxB,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,CAAC,CAAC;IACN,IAAA,qBAAW,EAAC;QACT,WAAW,EAAE,sBAAsB;QACnC,OAAO,EAAE,CAAC;KACb,CAAC;;6CACkB;AASX;IAPR,IAAA,0BAAgB,EAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IACvC,IAAA,qBAAW,EAAC;QACT,WAAW,EAAE,iCAAiC;QAC9C,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;QACnB,IAAI,EAAE,MAAM;KACf,CAAC;IACD,IAAA,6BAAS,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;;oDACxC;AASlB;IAPR,IAAA,0BAAgB,EAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IACvC,IAAA,qBAAW,EAAC;QACT,WAAW,EAAE,+BAA+B;QAC5C,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;QACnB,IAAI,EAAE,MAAM;KACf,CAAC;IACD,IAAA,6BAAS,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;;oDACxC;AASlB;IAPR,IAAA,0BAAgB,EAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IACvC,IAAA,qBAAW,EAAC;QACT,WAAW,EAAE,iCAAiC;QAC9C,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;QACnB,IAAI,EAAE,MAAM;KACf,CAAC;IACD,IAAA,6BAAS,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;;oDACvC"}
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './common/base/base.typeorm';
|
package/dist/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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/base/base.typeorm"), exports);
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C"}
|