@digione/node-custom-api 0.2.0-alpha5 → 0.2.0-alpha6
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.
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Request, Response } from 'express';
|
|
2
2
|
export declare const getAuthParam: (req: Request, res: Response, next: any) => void;
|
|
3
3
|
export declare const getStremParam: (req: Request, res: Response, next: any) => void;
|
|
4
|
-
export declare const getQueryParam: (req: Request, res: Response, next: any) => void
|
|
4
|
+
export declare const getQueryParam: (req: Request, res: Response, next: any) => Promise<void | Response<any, Record<string, any>>>;
|
|
5
5
|
export declare const getQueryParamCUD: (req: Request, res: Response, next: any) => void;
|
|
6
|
-
export declare const getQueryParamFile: (req: Request, res: Response, next: any) => void
|
|
6
|
+
export declare const getQueryParamFile: (req: Request, res: Response, next: any) => Promise<void | Response<any, Record<string, any>>>;
|
|
7
7
|
export declare const changeQueryParam: (value?: {}, { skipSystem }?: {
|
|
8
8
|
skipSystem?: boolean;
|
|
9
9
|
}) => (req: Request, res: Response, next: any) => any;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.changeConfigParam = exports.changeBodyParam = exports.changeOptionParam = exports.changeQueryParam = exports.getQueryParamFile = exports.getQueryParamCUD = exports.getQueryParam = exports.getStremParam = exports.getAuthParam = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const helper_1 = require("../utils/helper");
|
|
6
|
+
const errors_1 = require("../errors");
|
|
5
7
|
const _ = require("lodash");
|
|
6
8
|
const getAuthParam = (req, res, next) => {
|
|
7
9
|
res.locals.option['hostname'] = ((0, helper_1.getENV)('NODE_ENV') == 'development' ? 'http' : 'https') + '://' + req.get('host');
|
|
@@ -77,7 +79,8 @@ const getStremParam = (req, res, next) => {
|
|
|
77
79
|
});
|
|
78
80
|
};
|
|
79
81
|
exports.getStremParam = getStremParam;
|
|
80
|
-
const getQueryParam = (req, res, next) => {
|
|
82
|
+
const getQueryParam = (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
let config = res.locals.config || {};
|
|
81
84
|
res.locals.option = res.locals.option || {};
|
|
82
85
|
res.locals.option['lang_code'] = 'en';
|
|
83
86
|
res.locals.option['currency'] = 'thb';
|
|
@@ -93,8 +96,20 @@ const getQueryParam = (req, res, next) => {
|
|
|
93
96
|
else {
|
|
94
97
|
res.locals.include = {};
|
|
95
98
|
}
|
|
99
|
+
if (config['maxQueryLimit']) {
|
|
100
|
+
req.query.limit = req.query.limit || config['maxQueryLimit'];
|
|
101
|
+
}
|
|
96
102
|
if (req.query.limit) {
|
|
97
103
|
res.locals.option['limit'] = Number(req.query.limit);
|
|
104
|
+
if (config['maxQueryLimit'] && res.locals.option['limit'] > config['maxQueryLimit']) {
|
|
105
|
+
try {
|
|
106
|
+
yield (0, errors_1.paramError)(`"limit" must be less than or equal to ${config['maxQueryLimit']}`, { field: "limit" });
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
let error = new errors_1.CustomError(err);
|
|
110
|
+
return res.status(error.code).send(error);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
98
113
|
}
|
|
99
114
|
if (req.query.offset) {
|
|
100
115
|
res.locals.option['offset'] = Number(req.query.offset);
|
|
@@ -124,7 +139,7 @@ const getQueryParam = (req, res, next) => {
|
|
|
124
139
|
}
|
|
125
140
|
return next();
|
|
126
141
|
});
|
|
127
|
-
};
|
|
142
|
+
});
|
|
128
143
|
exports.getQueryParam = getQueryParam;
|
|
129
144
|
const getQueryParamCUD = (req, res, next) => {
|
|
130
145
|
let config = res.locals.config || {};
|
package/package.json
CHANGED
package/utils/validator.js
CHANGED
|
@@ -104,8 +104,9 @@ const fileService = (setup, { userfiles = false, required = false, fileSize = 0,
|
|
|
104
104
|
}
|
|
105
105
|
let option = setup(validate);
|
|
106
106
|
let upload = userfiles ? option.array("userfiles", maxCount) : option.any();
|
|
107
|
+
let schema = userfiles ? { tags: Joi.array().allow('', null).items(Joi.object().keys({ slug: Joi.string(), type: Joi.string() })) } : { tags: Joi.any() };
|
|
107
108
|
return upload(req, res, (err) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
-
return (0, exports.validateService)(Joi.object().keys(
|
|
109
|
+
return (0, exports.validateService)(Joi.object().keys(schema).unknown(), { field_omit: [] })(req, res, () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
109
110
|
try {
|
|
110
111
|
let field = userfiles ? "userfiles" : undefined;
|
|
111
112
|
if (err) {
|