elseware-nodejs 1.8.4 → 1.8.6
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/index.cjs +28 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -4
- package/dist/index.d.ts +10 -4
- package/dist/index.js +28 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -49,12 +49,17 @@ declare class APIResponse {
|
|
|
49
49
|
success?: boolean;
|
|
50
50
|
message?: string;
|
|
51
51
|
data?: unknown;
|
|
52
|
-
meta?: unknown
|
|
52
|
+
meta?: Record<string, unknown>;
|
|
53
53
|
}): Response<any, Record<string, any>>;
|
|
54
|
-
static ok(res: Response, data
|
|
55
|
-
static created(res: Response, data
|
|
54
|
+
static ok(res: Response, data?: unknown, message?: string, meta?: Record<string, unknown>): Response<any, Record<string, any>>;
|
|
55
|
+
static created(res: Response, data?: unknown, message?: string): Response<any, Record<string, any>>;
|
|
56
56
|
static noContent(res: Response): Response<any, Record<string, any>>;
|
|
57
|
-
static error(res: Response, message?: string, statusCode?: number): Response<any, Record<string, any>>;
|
|
57
|
+
static error(res: Response, message?: string, statusCode?: number, meta?: Record<string, unknown>): Response<any, Record<string, any>>;
|
|
58
|
+
static paginated(res: Response, data: unknown, options: {
|
|
59
|
+
total: number;
|
|
60
|
+
page: number;
|
|
61
|
+
limit: number;
|
|
62
|
+
}, message?: string): Response<any, Record<string, any>>;
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
declare const asyncHandler: (fn: (req: Request, res: Response, next: NextFunction) => Promise<void>) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -1828,6 +1833,7 @@ interface IQueryOptions<T> {
|
|
|
1828
1833
|
sort?: Sort<T>;
|
|
1829
1834
|
limit?: number;
|
|
1830
1835
|
skip?: number;
|
|
1836
|
+
populate?: string | string[];
|
|
1831
1837
|
}
|
|
1832
1838
|
interface IUpdateQueryOptions {
|
|
1833
1839
|
new?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -49,12 +49,17 @@ declare class APIResponse {
|
|
|
49
49
|
success?: boolean;
|
|
50
50
|
message?: string;
|
|
51
51
|
data?: unknown;
|
|
52
|
-
meta?: unknown
|
|
52
|
+
meta?: Record<string, unknown>;
|
|
53
53
|
}): Response<any, Record<string, any>>;
|
|
54
|
-
static ok(res: Response, data
|
|
55
|
-
static created(res: Response, data
|
|
54
|
+
static ok(res: Response, data?: unknown, message?: string, meta?: Record<string, unknown>): Response<any, Record<string, any>>;
|
|
55
|
+
static created(res: Response, data?: unknown, message?: string): Response<any, Record<string, any>>;
|
|
56
56
|
static noContent(res: Response): Response<any, Record<string, any>>;
|
|
57
|
-
static error(res: Response, message?: string, statusCode?: number): Response<any, Record<string, any>>;
|
|
57
|
+
static error(res: Response, message?: string, statusCode?: number, meta?: Record<string, unknown>): Response<any, Record<string, any>>;
|
|
58
|
+
static paginated(res: Response, data: unknown, options: {
|
|
59
|
+
total: number;
|
|
60
|
+
page: number;
|
|
61
|
+
limit: number;
|
|
62
|
+
}, message?: string): Response<any, Record<string, any>>;
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
declare const asyncHandler: (fn: (req: Request, res: Response, next: NextFunction) => Promise<void>) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -1828,6 +1833,7 @@ interface IQueryOptions<T> {
|
|
|
1828
1833
|
sort?: Sort<T>;
|
|
1829
1834
|
limit?: number;
|
|
1830
1835
|
skip?: number;
|
|
1836
|
+
populate?: string | string[];
|
|
1831
1837
|
}
|
|
1832
1838
|
interface IUpdateQueryOptions {
|
|
1833
1839
|
new?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -41,26 +41,37 @@ var APIResponse = class _APIResponse {
|
|
|
41
41
|
if (statusCode === 204) {
|
|
42
42
|
return res.status(204).send();
|
|
43
43
|
}
|
|
44
|
-
const body = {
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
const body = {
|
|
45
|
+
success,
|
|
46
|
+
message,
|
|
47
|
+
...data !== void 0 && { data },
|
|
48
|
+
...meta !== void 0 && { meta }
|
|
49
|
+
};
|
|
47
50
|
return res.status(statusCode).json(body);
|
|
48
51
|
}
|
|
49
|
-
static ok(res, data, message, meta) {
|
|
52
|
+
static ok(res, data, message = "Success", meta) {
|
|
50
53
|
return _APIResponse.send(res, { statusCode: 200, data, message, meta });
|
|
51
54
|
}
|
|
52
|
-
static created(res, data, message) {
|
|
55
|
+
static created(res, data, message = "Resource created successfully") {
|
|
53
56
|
return _APIResponse.send(res, { statusCode: 201, data, message });
|
|
54
57
|
}
|
|
55
58
|
static noContent(res) {
|
|
56
59
|
return _APIResponse.send(res, { statusCode: 204 });
|
|
57
60
|
}
|
|
58
|
-
|
|
59
|
-
static error(res, message, statusCode = 500) {
|
|
61
|
+
static error(res, message = "Internal Server Error", statusCode = 500, meta) {
|
|
60
62
|
return _APIResponse.send(res, {
|
|
61
63
|
success: false,
|
|
62
64
|
statusCode,
|
|
63
|
-
message
|
|
65
|
+
message,
|
|
66
|
+
meta
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
static paginated(res, data, options, message = "Data fetched successfully") {
|
|
70
|
+
return _APIResponse.ok(res, data, message, {
|
|
71
|
+
total: options.total,
|
|
72
|
+
page: options.page,
|
|
73
|
+
limit: options.limit,
|
|
74
|
+
totalPages: Math.ceil(options.total / options.limit)
|
|
64
75
|
});
|
|
65
76
|
}
|
|
66
77
|
};
|
|
@@ -5179,6 +5190,15 @@ var BaseMongoRepository = class {
|
|
|
5179
5190
|
if (options.sort) query = query.sort(options.sort);
|
|
5180
5191
|
if (options.limit) query = query.limit(options.limit);
|
|
5181
5192
|
if (options.skip) query = query.skip(options.skip);
|
|
5193
|
+
if (options.populate) {
|
|
5194
|
+
if (Array.isArray(options.populate)) {
|
|
5195
|
+
options.populate.forEach((p) => {
|
|
5196
|
+
query = query.populate(p);
|
|
5197
|
+
});
|
|
5198
|
+
} else {
|
|
5199
|
+
query = query.populate(options.populate);
|
|
5200
|
+
}
|
|
5201
|
+
}
|
|
5182
5202
|
return query;
|
|
5183
5203
|
}
|
|
5184
5204
|
toPlain(doc) {
|