av6-core 1.0.0
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 +156 -0
- package/dist/index.d.mts +262 -0
- package/dist/index.d.ts +262 -0
- package/dist/index.js +1154 -0
- package/dist/index.mjs +1113 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# AV6 Core
|
|
2
|
+
|
|
3
|
+
A comprehensive utility library for AV6 Node.js projects, providing common functionality for data operations, caching, and Excel handling.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Dynamic Data Operations**: Flexible search, fetch, and CRUD operations with support for dynamic models
|
|
8
|
+
- **Caching Support**: Built-in Redis caching for improved performance
|
|
9
|
+
- **Excel Import/Export**: Seamless Excel file handling for data import and export
|
|
10
|
+
- **Pagination**: Built-in pagination for search results
|
|
11
|
+
- **DTO Mapping**: Support for Data Transfer Object mapping
|
|
12
|
+
- **Type Safety**: Written in TypeScript with comprehensive type definitions
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install av6-core
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Basic Setup
|
|
23
|
+
|
|
24
|
+
To use the library, you need to provide the necessary dependencies:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { commonService, Deps } from 'av6-core';
|
|
28
|
+
import { PrismaClient } from '@prisma/client';
|
|
29
|
+
import winston from 'winston';
|
|
30
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
31
|
+
|
|
32
|
+
// Initialize dependencies
|
|
33
|
+
const deps: Deps = {
|
|
34
|
+
config: {
|
|
35
|
+
REDIS_PREFIX: 'your-prefix:',
|
|
36
|
+
CACHE_KEY_NAME: 'your-cache-key'
|
|
37
|
+
},
|
|
38
|
+
mapper: {
|
|
39
|
+
dtoMapping: {}, // Your DTO mapping functions
|
|
40
|
+
mappingExport: {}, // Your export mapping functions
|
|
41
|
+
mappingImport: {}, // Your import mapping functions
|
|
42
|
+
},
|
|
43
|
+
helpers: {
|
|
44
|
+
generateErrorMessage: (type, ...variables) => {
|
|
45
|
+
// Your error message generation logic
|
|
46
|
+
},
|
|
47
|
+
ErrorHandler: class ErrorHandler extends Error {
|
|
48
|
+
// Your error handler implementation
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
logger: winston.createLogger({
|
|
52
|
+
// Your logger configuration
|
|
53
|
+
}),
|
|
54
|
+
cacheAdapter: {
|
|
55
|
+
// Your cache adapter implementation
|
|
56
|
+
},
|
|
57
|
+
requestStorage: new AsyncLocalStorage(),
|
|
58
|
+
db: new PrismaClient()
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Initialize the service
|
|
62
|
+
const service = commonService(deps);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Search Operations
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
// Perform a search operation
|
|
69
|
+
const searchResult = await service.search({
|
|
70
|
+
pageNo: 1,
|
|
71
|
+
pageSize: 10,
|
|
72
|
+
shortCode: 'USER',
|
|
73
|
+
searchColumns: ['name', 'email'],
|
|
74
|
+
searchText: 'john',
|
|
75
|
+
sortBy: 'createdAt',
|
|
76
|
+
sortDir: 'DESC',
|
|
77
|
+
shortCodeData: {
|
|
78
|
+
shortCode: 'USER',
|
|
79
|
+
tableName: 'user',
|
|
80
|
+
isDTO: true,
|
|
81
|
+
isCacheable: true
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Fetch Record
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
// Fetch a specific record
|
|
90
|
+
const record = await service.fetch({
|
|
91
|
+
shortCode: 'USER',
|
|
92
|
+
id: 123,
|
|
93
|
+
shortCodeData: {
|
|
94
|
+
shortCode: 'USER',
|
|
95
|
+
tableName: 'user',
|
|
96
|
+
isDTO: true,
|
|
97
|
+
isCacheable: true
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Excel Operations
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
// Import data from Excel
|
|
106
|
+
const importResult = await service.commonExcelImport({
|
|
107
|
+
shortCode: 'USER',
|
|
108
|
+
file: excelFile, // File object from upload
|
|
109
|
+
shortCodeData: {
|
|
110
|
+
shortCode: 'USER',
|
|
111
|
+
tableName: 'user'
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Export data to Excel
|
|
116
|
+
const workbook = await service.commonExcelExport({
|
|
117
|
+
shortCode: 'USER',
|
|
118
|
+
isSample: false,
|
|
119
|
+
shortCodeData: {
|
|
120
|
+
shortCode: 'USER',
|
|
121
|
+
tableName: 'user'
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## API Reference
|
|
127
|
+
|
|
128
|
+
### Common Service
|
|
129
|
+
|
|
130
|
+
The library provides a comprehensive service for common operations:
|
|
131
|
+
|
|
132
|
+
- `search`: Search records with pagination and filtering
|
|
133
|
+
- `dropdownSearch`: Search records for dropdown components
|
|
134
|
+
- `fixedSearch`: Search with fixed criteria
|
|
135
|
+
- `fixedSearchWoPaginationService`: Search with fixed criteria without pagination
|
|
136
|
+
- `commonExcelService`: Generate Excel workbooks
|
|
137
|
+
- `fetch`: Fetch a specific record by ID
|
|
138
|
+
- `commonExcelImport`: Import data from Excel files
|
|
139
|
+
- `commonExcelExport`: Export data to Excel files
|
|
140
|
+
- `delete`: Delete a record
|
|
141
|
+
- `updateStatus`: Update the status of a record
|
|
142
|
+
- `fetchImageStream`: Fetch an image as a stream
|
|
143
|
+
|
|
144
|
+
### Utility Functions
|
|
145
|
+
|
|
146
|
+
The library also provides utility functions:
|
|
147
|
+
|
|
148
|
+
- `customOmit`: Omit specific keys from an object
|
|
149
|
+
- `objectTo2DArray`: Convert an object to a 2D array
|
|
150
|
+
- `toRelativeImageUrl`: Convert an absolute path to a relative image URL
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
ISC
|
|
155
|
+
|
|
156
|
+
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { PrismaClient } from '@prisma/client';
|
|
2
|
+
import winston from 'winston';
|
|
3
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
4
|
+
import { Readable } from 'stream';
|
|
5
|
+
import { JsonValue } from '@prisma/client/runtime/library';
|
|
6
|
+
import ExcelJs from 'exceljs';
|
|
7
|
+
import { AxiosResponse } from 'axios';
|
|
8
|
+
|
|
9
|
+
declare enum ErrorMessageType {
|
|
10
|
+
INVALID_ID = "Invalid id: %1 Numeric value expected.",
|
|
11
|
+
INVALID_STATUS = "Invalid status for %1.",
|
|
12
|
+
INVALID_RANGE = "Invalid range for: %1 and %2.",
|
|
13
|
+
INVALID_FOREIGN_KEY = "Invalid foreign key for %1.",
|
|
14
|
+
DUPLICATE_ITEM = "%1 already exists.",
|
|
15
|
+
NOT_FOUND = "%1 doesn't exist.",
|
|
16
|
+
INVALID_TABLE = "Invalid table name",
|
|
17
|
+
INVALID_VALUE = "%1 is not a valid value",
|
|
18
|
+
INVALID_DATE = "%1 is not a valid date, must be a valid ISO-8601 date",
|
|
19
|
+
INVALID_PARENT_CHILD = "%1 Invalid parent child linking",
|
|
20
|
+
INVALID_FIELD = "%1 is not a valid field",
|
|
21
|
+
FIELD_REQUIRED = "%1 is required",
|
|
22
|
+
VALUE_MISMATCH = "%1 value mismatch",
|
|
23
|
+
ALREADY_VERIFIED = "%1 is already verified.",
|
|
24
|
+
MISMATCH = "%1 and %2 mismatch.",
|
|
25
|
+
INSUFFICIENT_STOCK = "%1 has insufficient stock",
|
|
26
|
+
ACCESS_FAIL = "You are not authorized.",
|
|
27
|
+
NON_RETURNABLE = "%1 is not returnable",
|
|
28
|
+
EXCEL = "No data found to be downloaded"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface ToggleActive {
|
|
32
|
+
id: number;
|
|
33
|
+
action: "ACTIVE" | "IN_ACTIVE";
|
|
34
|
+
}
|
|
35
|
+
interface SearchRequest {
|
|
36
|
+
pageNo: number;
|
|
37
|
+
pageSize: number;
|
|
38
|
+
shortCode: string;
|
|
39
|
+
searchColumns: string[];
|
|
40
|
+
searchText?: string;
|
|
41
|
+
sortBy?: string;
|
|
42
|
+
sortDir?: "ASC" | "DESC";
|
|
43
|
+
includes?: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
interface NewSearchRequest {
|
|
46
|
+
pageNo: number;
|
|
47
|
+
pageSize: number;
|
|
48
|
+
shortCode: string;
|
|
49
|
+
searchColumns: Col[];
|
|
50
|
+
searchText?: string;
|
|
51
|
+
sortBy?: string;
|
|
52
|
+
sortDir?: "ASC" | "DESC";
|
|
53
|
+
includes?: Record<string, unknown>;
|
|
54
|
+
}
|
|
55
|
+
interface CommonFilterRequest {
|
|
56
|
+
pageNo: number;
|
|
57
|
+
pageSize: number;
|
|
58
|
+
sortBy?: string;
|
|
59
|
+
sortDir?: "ASC" | "DESC";
|
|
60
|
+
}
|
|
61
|
+
interface File {
|
|
62
|
+
fieldname: string;
|
|
63
|
+
originalname: string;
|
|
64
|
+
encoding: string;
|
|
65
|
+
mimetype: string;
|
|
66
|
+
size: number;
|
|
67
|
+
stream: Readable;
|
|
68
|
+
destination: string;
|
|
69
|
+
filename: string;
|
|
70
|
+
path: string;
|
|
71
|
+
buffer: Buffer;
|
|
72
|
+
}
|
|
73
|
+
interface ImportExcel {
|
|
74
|
+
shortCode: string;
|
|
75
|
+
file: File;
|
|
76
|
+
}
|
|
77
|
+
type DynamicShortCode = {
|
|
78
|
+
shortCode: string;
|
|
79
|
+
tableName: string;
|
|
80
|
+
isDTO?: boolean;
|
|
81
|
+
isCacheable?: boolean;
|
|
82
|
+
isDropDown?: boolean;
|
|
83
|
+
permission?: string | null;
|
|
84
|
+
whereClause?: JsonValue | null;
|
|
85
|
+
selectClause?: JsonValue | null;
|
|
86
|
+
};
|
|
87
|
+
interface ExportExcel {
|
|
88
|
+
shortCode: string;
|
|
89
|
+
isSample?: boolean;
|
|
90
|
+
}
|
|
91
|
+
interface Col {
|
|
92
|
+
col: string;
|
|
93
|
+
type: "string" | "number";
|
|
94
|
+
}
|
|
95
|
+
interface ColValue {
|
|
96
|
+
value: string[] | number[];
|
|
97
|
+
type: "string" | "number" | "date" | "range" | "gt" | "lt";
|
|
98
|
+
}
|
|
99
|
+
interface NewFixedSearchRequest extends NewSearchRequest {
|
|
100
|
+
fixedSearch?: Record<string, ColValue>;
|
|
101
|
+
fixedNotSearch?: Record<string, ColValue>;
|
|
102
|
+
}
|
|
103
|
+
interface NewFixedSearchRequestService<T extends DynamicShortCode> extends NewFixedSearchRequest {
|
|
104
|
+
shortCodeData: T;
|
|
105
|
+
}
|
|
106
|
+
interface CommonExcelRequest<T extends DynamicShortCode> extends Omit<NewFixedSearchRequestService<T>, "pageNo" | "pageSize"> {
|
|
107
|
+
config: ExcelConfig[];
|
|
108
|
+
sheetName: string;
|
|
109
|
+
type: "NORMAL" | "GROUPED";
|
|
110
|
+
detailedConfig?: ExcelConfig[];
|
|
111
|
+
detailAccessorKey?: string;
|
|
112
|
+
headerAccessorKey?: string;
|
|
113
|
+
}
|
|
114
|
+
interface ExcelConfig {
|
|
115
|
+
label: string;
|
|
116
|
+
accessorKey: string;
|
|
117
|
+
}
|
|
118
|
+
interface FixedSearchRequest extends SearchRequest {
|
|
119
|
+
fixedSearch?: Record<string, unknown[]>;
|
|
120
|
+
fixedNotSearch?: Record<string, unknown[]>;
|
|
121
|
+
}
|
|
122
|
+
interface SearchRequestService<T extends DynamicShortCode> extends SearchRequest {
|
|
123
|
+
shortCodeData: T;
|
|
124
|
+
}
|
|
125
|
+
interface DropdownRequest {
|
|
126
|
+
shortCode: string;
|
|
127
|
+
searchColumns: string[];
|
|
128
|
+
searchText?: string;
|
|
129
|
+
}
|
|
130
|
+
interface DropdownRequestService<T extends DynamicShortCode> extends DropdownRequest {
|
|
131
|
+
shortCodeData: T;
|
|
132
|
+
}
|
|
133
|
+
interface FixedSearchRequestService<T extends DynamicShortCode> extends FixedSearchRequest {
|
|
134
|
+
shortCodeData: T;
|
|
135
|
+
}
|
|
136
|
+
interface FetchRequest {
|
|
137
|
+
shortCode: string;
|
|
138
|
+
id: number;
|
|
139
|
+
}
|
|
140
|
+
interface FetchRequestRepository<T extends DynamicShortCode> extends FetchRequest {
|
|
141
|
+
shortCodeData: T;
|
|
142
|
+
}
|
|
143
|
+
interface ImportExcelRequestService<T extends DynamicShortCode> extends ImportExcel {
|
|
144
|
+
shortCodeData: T;
|
|
145
|
+
data?: unknown[];
|
|
146
|
+
}
|
|
147
|
+
interface ExportExcelRequestService<T extends DynamicShortCode> extends ExportExcel {
|
|
148
|
+
shortCodeData: T;
|
|
149
|
+
isSampleRequest?: boolean;
|
|
150
|
+
}
|
|
151
|
+
interface DeleteParams {
|
|
152
|
+
shortCode: string;
|
|
153
|
+
id: number;
|
|
154
|
+
}
|
|
155
|
+
interface DeleteRequestRepository<T extends DynamicShortCode> extends DeleteParams {
|
|
156
|
+
shortCodeData: T;
|
|
157
|
+
}
|
|
158
|
+
interface updateStatusParams {
|
|
159
|
+
shortCode: string;
|
|
160
|
+
id: number;
|
|
161
|
+
status: string;
|
|
162
|
+
}
|
|
163
|
+
interface UpdateStatusRequestRepository<T extends DynamicShortCode> extends updateStatusParams {
|
|
164
|
+
shortCodeData: T;
|
|
165
|
+
}
|
|
166
|
+
interface PaginatedResponse<T> {
|
|
167
|
+
totalRecords: number;
|
|
168
|
+
currentPageNumber: number;
|
|
169
|
+
lastPageNumber: number;
|
|
170
|
+
pageSize: number;
|
|
171
|
+
data: T[];
|
|
172
|
+
}
|
|
173
|
+
interface CalculationRes {
|
|
174
|
+
netDiscount: number;
|
|
175
|
+
netTax: number;
|
|
176
|
+
totalAmount: number;
|
|
177
|
+
}
|
|
178
|
+
type DtoMappingFunction = (data: unknown) => unknown;
|
|
179
|
+
interface Helpers {
|
|
180
|
+
generateErrorMessage(type: keyof typeof ErrorMessageType, ...variables: string[]): string;
|
|
181
|
+
ErrorHandler: new (status: number, message: string, errors?: ValidationErrorItem[]) => Error;
|
|
182
|
+
}
|
|
183
|
+
type DataType = {
|
|
184
|
+
id: number;
|
|
185
|
+
numCode?: number;
|
|
186
|
+
emailType?: string;
|
|
187
|
+
shortCode?: string;
|
|
188
|
+
};
|
|
189
|
+
interface CacheAdapter {
|
|
190
|
+
getCacheById(key: string, id: number | string): Promise<any | undefined>;
|
|
191
|
+
updateCache(key: string, id: number | string, value: unknown): Promise<void>;
|
|
192
|
+
createCache(table: string, data: DataType[]): Promise<void>;
|
|
193
|
+
deleteCache(key: string, id: number | string): Promise<void>;
|
|
194
|
+
}
|
|
195
|
+
interface Mapper {
|
|
196
|
+
dtoMapping: Record<string, DtoMappingFunction>;
|
|
197
|
+
mappingExport: {
|
|
198
|
+
[key: string]: (record: unknown) => unknown;
|
|
199
|
+
};
|
|
200
|
+
mappingImport: {
|
|
201
|
+
[key: string]: () => {
|
|
202
|
+
mapper: unknown;
|
|
203
|
+
validation?: unknown;
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
interface Config {
|
|
208
|
+
REDIS_PREFIX: string;
|
|
209
|
+
CACHE_KEY_NAME: string;
|
|
210
|
+
}
|
|
211
|
+
type Store = {
|
|
212
|
+
user?: {
|
|
213
|
+
userName: string;
|
|
214
|
+
id: number;
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
interface Context {
|
|
218
|
+
[key: string]: any;
|
|
219
|
+
key?: string;
|
|
220
|
+
label?: string;
|
|
221
|
+
value?: any;
|
|
222
|
+
}
|
|
223
|
+
interface ValidationErrorItem {
|
|
224
|
+
message: string;
|
|
225
|
+
path: Array<string | number>;
|
|
226
|
+
type: string;
|
|
227
|
+
context?: Context;
|
|
228
|
+
}
|
|
229
|
+
interface Deps {
|
|
230
|
+
config: Config;
|
|
231
|
+
mapper: Mapper;
|
|
232
|
+
helpers: Helpers;
|
|
233
|
+
logger: winston.Logger;
|
|
234
|
+
cacheAdapter: CacheAdapter;
|
|
235
|
+
requestStorage: AsyncLocalStorage<Store>;
|
|
236
|
+
db: PrismaClient;
|
|
237
|
+
}
|
|
238
|
+
interface CommonServiceResponse {
|
|
239
|
+
search: (searchParams: SearchRequestService<DynamicShortCode>) => Promise<unknown>;
|
|
240
|
+
dropdownSearch: (searchParams: DropdownRequestService<DynamicShortCode>) => Promise<unknown>;
|
|
241
|
+
fixedSearch: (searchParams: NewFixedSearchRequestService<DynamicShortCode>) => Promise<unknown>;
|
|
242
|
+
fixedSearchWoPaginationService: (searchParams: Omit<NewFixedSearchRequestService<DynamicShortCode>, "pageNo" | "pageSize">) => Promise<unknown>;
|
|
243
|
+
commonExcelService: (searchParams: CommonExcelRequest<DynamicShortCode>) => Promise<ExcelJs.Workbook>;
|
|
244
|
+
fetch: (fetchParams: FetchRequestRepository<DynamicShortCode>) => Promise<unknown>;
|
|
245
|
+
commonExcelImport: (searchParams: ImportExcelRequestService<DynamicShortCode>) => Promise<unknown>;
|
|
246
|
+
commonExcelExport: (exportParams: ExportExcelRequestService<DynamicShortCode>) => Promise<ExcelJs.Workbook>;
|
|
247
|
+
delete: (deleteParams: DeleteRequestRepository<DynamicShortCode>) => Promise<void>;
|
|
248
|
+
updateStatus: (updateStatusParams: UpdateStatusRequestRepository<DynamicShortCode>) => Promise<unknown>;
|
|
249
|
+
fetchImageStream: (fileName: string) => Promise<AxiosResponse<Readable>>;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
declare const commonService: (serviceDeps: Deps) => CommonServiceResponse;
|
|
253
|
+
|
|
254
|
+
declare function customOmit<T extends object, K extends keyof T>(obj: T, keys: K[]): {
|
|
255
|
+
rest: Omit<T, K>;
|
|
256
|
+
omitted: Pick<T, K>;
|
|
257
|
+
};
|
|
258
|
+
declare function getDynamicValue(obj: Record<string, any> | null | undefined, accessorKey: string): any | null;
|
|
259
|
+
declare function objectTo2DArray<T>(obj: Record<string, T>, maxCols: number): (string | T)[][];
|
|
260
|
+
declare const toRelativeImageUrl: (absolutePath: string) => string;
|
|
261
|
+
|
|
262
|
+
export { type CacheAdapter, type CalculationRes, type CommonExcelRequest, type CommonFilterRequest, type CommonServiceResponse, type Config, type Context, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, type PaginatedResponse, type SearchRequest, type SearchRequestService, type ToggleActive, type UpdateStatusRequestRepository, type ValidationErrorItem, commonService, customOmit, getDynamicValue, objectTo2DArray, toRelativeImageUrl, type updateStatusParams };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { PrismaClient } from '@prisma/client';
|
|
2
|
+
import winston from 'winston';
|
|
3
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
4
|
+
import { Readable } from 'stream';
|
|
5
|
+
import { JsonValue } from '@prisma/client/runtime/library';
|
|
6
|
+
import ExcelJs from 'exceljs';
|
|
7
|
+
import { AxiosResponse } from 'axios';
|
|
8
|
+
|
|
9
|
+
declare enum ErrorMessageType {
|
|
10
|
+
INVALID_ID = "Invalid id: %1 Numeric value expected.",
|
|
11
|
+
INVALID_STATUS = "Invalid status for %1.",
|
|
12
|
+
INVALID_RANGE = "Invalid range for: %1 and %2.",
|
|
13
|
+
INVALID_FOREIGN_KEY = "Invalid foreign key for %1.",
|
|
14
|
+
DUPLICATE_ITEM = "%1 already exists.",
|
|
15
|
+
NOT_FOUND = "%1 doesn't exist.",
|
|
16
|
+
INVALID_TABLE = "Invalid table name",
|
|
17
|
+
INVALID_VALUE = "%1 is not a valid value",
|
|
18
|
+
INVALID_DATE = "%1 is not a valid date, must be a valid ISO-8601 date",
|
|
19
|
+
INVALID_PARENT_CHILD = "%1 Invalid parent child linking",
|
|
20
|
+
INVALID_FIELD = "%1 is not a valid field",
|
|
21
|
+
FIELD_REQUIRED = "%1 is required",
|
|
22
|
+
VALUE_MISMATCH = "%1 value mismatch",
|
|
23
|
+
ALREADY_VERIFIED = "%1 is already verified.",
|
|
24
|
+
MISMATCH = "%1 and %2 mismatch.",
|
|
25
|
+
INSUFFICIENT_STOCK = "%1 has insufficient stock",
|
|
26
|
+
ACCESS_FAIL = "You are not authorized.",
|
|
27
|
+
NON_RETURNABLE = "%1 is not returnable",
|
|
28
|
+
EXCEL = "No data found to be downloaded"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface ToggleActive {
|
|
32
|
+
id: number;
|
|
33
|
+
action: "ACTIVE" | "IN_ACTIVE";
|
|
34
|
+
}
|
|
35
|
+
interface SearchRequest {
|
|
36
|
+
pageNo: number;
|
|
37
|
+
pageSize: number;
|
|
38
|
+
shortCode: string;
|
|
39
|
+
searchColumns: string[];
|
|
40
|
+
searchText?: string;
|
|
41
|
+
sortBy?: string;
|
|
42
|
+
sortDir?: "ASC" | "DESC";
|
|
43
|
+
includes?: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
interface NewSearchRequest {
|
|
46
|
+
pageNo: number;
|
|
47
|
+
pageSize: number;
|
|
48
|
+
shortCode: string;
|
|
49
|
+
searchColumns: Col[];
|
|
50
|
+
searchText?: string;
|
|
51
|
+
sortBy?: string;
|
|
52
|
+
sortDir?: "ASC" | "DESC";
|
|
53
|
+
includes?: Record<string, unknown>;
|
|
54
|
+
}
|
|
55
|
+
interface CommonFilterRequest {
|
|
56
|
+
pageNo: number;
|
|
57
|
+
pageSize: number;
|
|
58
|
+
sortBy?: string;
|
|
59
|
+
sortDir?: "ASC" | "DESC";
|
|
60
|
+
}
|
|
61
|
+
interface File {
|
|
62
|
+
fieldname: string;
|
|
63
|
+
originalname: string;
|
|
64
|
+
encoding: string;
|
|
65
|
+
mimetype: string;
|
|
66
|
+
size: number;
|
|
67
|
+
stream: Readable;
|
|
68
|
+
destination: string;
|
|
69
|
+
filename: string;
|
|
70
|
+
path: string;
|
|
71
|
+
buffer: Buffer;
|
|
72
|
+
}
|
|
73
|
+
interface ImportExcel {
|
|
74
|
+
shortCode: string;
|
|
75
|
+
file: File;
|
|
76
|
+
}
|
|
77
|
+
type DynamicShortCode = {
|
|
78
|
+
shortCode: string;
|
|
79
|
+
tableName: string;
|
|
80
|
+
isDTO?: boolean;
|
|
81
|
+
isCacheable?: boolean;
|
|
82
|
+
isDropDown?: boolean;
|
|
83
|
+
permission?: string | null;
|
|
84
|
+
whereClause?: JsonValue | null;
|
|
85
|
+
selectClause?: JsonValue | null;
|
|
86
|
+
};
|
|
87
|
+
interface ExportExcel {
|
|
88
|
+
shortCode: string;
|
|
89
|
+
isSample?: boolean;
|
|
90
|
+
}
|
|
91
|
+
interface Col {
|
|
92
|
+
col: string;
|
|
93
|
+
type: "string" | "number";
|
|
94
|
+
}
|
|
95
|
+
interface ColValue {
|
|
96
|
+
value: string[] | number[];
|
|
97
|
+
type: "string" | "number" | "date" | "range" | "gt" | "lt";
|
|
98
|
+
}
|
|
99
|
+
interface NewFixedSearchRequest extends NewSearchRequest {
|
|
100
|
+
fixedSearch?: Record<string, ColValue>;
|
|
101
|
+
fixedNotSearch?: Record<string, ColValue>;
|
|
102
|
+
}
|
|
103
|
+
interface NewFixedSearchRequestService<T extends DynamicShortCode> extends NewFixedSearchRequest {
|
|
104
|
+
shortCodeData: T;
|
|
105
|
+
}
|
|
106
|
+
interface CommonExcelRequest<T extends DynamicShortCode> extends Omit<NewFixedSearchRequestService<T>, "pageNo" | "pageSize"> {
|
|
107
|
+
config: ExcelConfig[];
|
|
108
|
+
sheetName: string;
|
|
109
|
+
type: "NORMAL" | "GROUPED";
|
|
110
|
+
detailedConfig?: ExcelConfig[];
|
|
111
|
+
detailAccessorKey?: string;
|
|
112
|
+
headerAccessorKey?: string;
|
|
113
|
+
}
|
|
114
|
+
interface ExcelConfig {
|
|
115
|
+
label: string;
|
|
116
|
+
accessorKey: string;
|
|
117
|
+
}
|
|
118
|
+
interface FixedSearchRequest extends SearchRequest {
|
|
119
|
+
fixedSearch?: Record<string, unknown[]>;
|
|
120
|
+
fixedNotSearch?: Record<string, unknown[]>;
|
|
121
|
+
}
|
|
122
|
+
interface SearchRequestService<T extends DynamicShortCode> extends SearchRequest {
|
|
123
|
+
shortCodeData: T;
|
|
124
|
+
}
|
|
125
|
+
interface DropdownRequest {
|
|
126
|
+
shortCode: string;
|
|
127
|
+
searchColumns: string[];
|
|
128
|
+
searchText?: string;
|
|
129
|
+
}
|
|
130
|
+
interface DropdownRequestService<T extends DynamicShortCode> extends DropdownRequest {
|
|
131
|
+
shortCodeData: T;
|
|
132
|
+
}
|
|
133
|
+
interface FixedSearchRequestService<T extends DynamicShortCode> extends FixedSearchRequest {
|
|
134
|
+
shortCodeData: T;
|
|
135
|
+
}
|
|
136
|
+
interface FetchRequest {
|
|
137
|
+
shortCode: string;
|
|
138
|
+
id: number;
|
|
139
|
+
}
|
|
140
|
+
interface FetchRequestRepository<T extends DynamicShortCode> extends FetchRequest {
|
|
141
|
+
shortCodeData: T;
|
|
142
|
+
}
|
|
143
|
+
interface ImportExcelRequestService<T extends DynamicShortCode> extends ImportExcel {
|
|
144
|
+
shortCodeData: T;
|
|
145
|
+
data?: unknown[];
|
|
146
|
+
}
|
|
147
|
+
interface ExportExcelRequestService<T extends DynamicShortCode> extends ExportExcel {
|
|
148
|
+
shortCodeData: T;
|
|
149
|
+
isSampleRequest?: boolean;
|
|
150
|
+
}
|
|
151
|
+
interface DeleteParams {
|
|
152
|
+
shortCode: string;
|
|
153
|
+
id: number;
|
|
154
|
+
}
|
|
155
|
+
interface DeleteRequestRepository<T extends DynamicShortCode> extends DeleteParams {
|
|
156
|
+
shortCodeData: T;
|
|
157
|
+
}
|
|
158
|
+
interface updateStatusParams {
|
|
159
|
+
shortCode: string;
|
|
160
|
+
id: number;
|
|
161
|
+
status: string;
|
|
162
|
+
}
|
|
163
|
+
interface UpdateStatusRequestRepository<T extends DynamicShortCode> extends updateStatusParams {
|
|
164
|
+
shortCodeData: T;
|
|
165
|
+
}
|
|
166
|
+
interface PaginatedResponse<T> {
|
|
167
|
+
totalRecords: number;
|
|
168
|
+
currentPageNumber: number;
|
|
169
|
+
lastPageNumber: number;
|
|
170
|
+
pageSize: number;
|
|
171
|
+
data: T[];
|
|
172
|
+
}
|
|
173
|
+
interface CalculationRes {
|
|
174
|
+
netDiscount: number;
|
|
175
|
+
netTax: number;
|
|
176
|
+
totalAmount: number;
|
|
177
|
+
}
|
|
178
|
+
type DtoMappingFunction = (data: unknown) => unknown;
|
|
179
|
+
interface Helpers {
|
|
180
|
+
generateErrorMessage(type: keyof typeof ErrorMessageType, ...variables: string[]): string;
|
|
181
|
+
ErrorHandler: new (status: number, message: string, errors?: ValidationErrorItem[]) => Error;
|
|
182
|
+
}
|
|
183
|
+
type DataType = {
|
|
184
|
+
id: number;
|
|
185
|
+
numCode?: number;
|
|
186
|
+
emailType?: string;
|
|
187
|
+
shortCode?: string;
|
|
188
|
+
};
|
|
189
|
+
interface CacheAdapter {
|
|
190
|
+
getCacheById(key: string, id: number | string): Promise<any | undefined>;
|
|
191
|
+
updateCache(key: string, id: number | string, value: unknown): Promise<void>;
|
|
192
|
+
createCache(table: string, data: DataType[]): Promise<void>;
|
|
193
|
+
deleteCache(key: string, id: number | string): Promise<void>;
|
|
194
|
+
}
|
|
195
|
+
interface Mapper {
|
|
196
|
+
dtoMapping: Record<string, DtoMappingFunction>;
|
|
197
|
+
mappingExport: {
|
|
198
|
+
[key: string]: (record: unknown) => unknown;
|
|
199
|
+
};
|
|
200
|
+
mappingImport: {
|
|
201
|
+
[key: string]: () => {
|
|
202
|
+
mapper: unknown;
|
|
203
|
+
validation?: unknown;
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
interface Config {
|
|
208
|
+
REDIS_PREFIX: string;
|
|
209
|
+
CACHE_KEY_NAME: string;
|
|
210
|
+
}
|
|
211
|
+
type Store = {
|
|
212
|
+
user?: {
|
|
213
|
+
userName: string;
|
|
214
|
+
id: number;
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
interface Context {
|
|
218
|
+
[key: string]: any;
|
|
219
|
+
key?: string;
|
|
220
|
+
label?: string;
|
|
221
|
+
value?: any;
|
|
222
|
+
}
|
|
223
|
+
interface ValidationErrorItem {
|
|
224
|
+
message: string;
|
|
225
|
+
path: Array<string | number>;
|
|
226
|
+
type: string;
|
|
227
|
+
context?: Context;
|
|
228
|
+
}
|
|
229
|
+
interface Deps {
|
|
230
|
+
config: Config;
|
|
231
|
+
mapper: Mapper;
|
|
232
|
+
helpers: Helpers;
|
|
233
|
+
logger: winston.Logger;
|
|
234
|
+
cacheAdapter: CacheAdapter;
|
|
235
|
+
requestStorage: AsyncLocalStorage<Store>;
|
|
236
|
+
db: PrismaClient;
|
|
237
|
+
}
|
|
238
|
+
interface CommonServiceResponse {
|
|
239
|
+
search: (searchParams: SearchRequestService<DynamicShortCode>) => Promise<unknown>;
|
|
240
|
+
dropdownSearch: (searchParams: DropdownRequestService<DynamicShortCode>) => Promise<unknown>;
|
|
241
|
+
fixedSearch: (searchParams: NewFixedSearchRequestService<DynamicShortCode>) => Promise<unknown>;
|
|
242
|
+
fixedSearchWoPaginationService: (searchParams: Omit<NewFixedSearchRequestService<DynamicShortCode>, "pageNo" | "pageSize">) => Promise<unknown>;
|
|
243
|
+
commonExcelService: (searchParams: CommonExcelRequest<DynamicShortCode>) => Promise<ExcelJs.Workbook>;
|
|
244
|
+
fetch: (fetchParams: FetchRequestRepository<DynamicShortCode>) => Promise<unknown>;
|
|
245
|
+
commonExcelImport: (searchParams: ImportExcelRequestService<DynamicShortCode>) => Promise<unknown>;
|
|
246
|
+
commonExcelExport: (exportParams: ExportExcelRequestService<DynamicShortCode>) => Promise<ExcelJs.Workbook>;
|
|
247
|
+
delete: (deleteParams: DeleteRequestRepository<DynamicShortCode>) => Promise<void>;
|
|
248
|
+
updateStatus: (updateStatusParams: UpdateStatusRequestRepository<DynamicShortCode>) => Promise<unknown>;
|
|
249
|
+
fetchImageStream: (fileName: string) => Promise<AxiosResponse<Readable>>;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
declare const commonService: (serviceDeps: Deps) => CommonServiceResponse;
|
|
253
|
+
|
|
254
|
+
declare function customOmit<T extends object, K extends keyof T>(obj: T, keys: K[]): {
|
|
255
|
+
rest: Omit<T, K>;
|
|
256
|
+
omitted: Pick<T, K>;
|
|
257
|
+
};
|
|
258
|
+
declare function getDynamicValue(obj: Record<string, any> | null | undefined, accessorKey: string): any | null;
|
|
259
|
+
declare function objectTo2DArray<T>(obj: Record<string, T>, maxCols: number): (string | T)[][];
|
|
260
|
+
declare const toRelativeImageUrl: (absolutePath: string) => string;
|
|
261
|
+
|
|
262
|
+
export { type CacheAdapter, type CalculationRes, type CommonExcelRequest, type CommonFilterRequest, type CommonServiceResponse, type Config, type Context, type DataType, type DeleteParams, type DeleteRequestRepository, type Deps, type DropdownRequest, type DropdownRequestService, type DynamicShortCode, type ExcelConfig, type ExportExcel, type ExportExcelRequestService, type FetchRequest, type FetchRequestRepository, type FixedSearchRequest, type FixedSearchRequestService, type Helpers, type ImportExcel, type ImportExcelRequestService, type Mapper, type NewFixedSearchRequest, type NewFixedSearchRequestService, type NewSearchRequest, type PaginatedResponse, type SearchRequest, type SearchRequestService, type ToggleActive, type UpdateStatusRequestRepository, type ValidationErrorItem, commonService, customOmit, getDynamicValue, objectTo2DArray, toRelativeImageUrl, type updateStatusParams };
|