pangea-server 3.3.31 → 3.3.33
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.
|
@@ -16,7 +16,7 @@ function initDatabase(models, seeds, config = {}) {
|
|
|
16
16
|
username: (0, helpers_1.getEnvStr)('DB_USERNAME'),
|
|
17
17
|
password: (0, helpers_1.getEnvStr)('DB_PASSWORD'),
|
|
18
18
|
database: (0, helpers_1.getEnvStr)('DB_DATABASE'),
|
|
19
|
-
pool: { max: 5, min: 0, acquire: 30000, idle:
|
|
19
|
+
pool: { max: 5, min: 0, acquire: 30000, idle: 9999999 },
|
|
20
20
|
models: Object.values(models),
|
|
21
21
|
logging: config.logging ? logQuery : false,
|
|
22
22
|
benchmark: true,
|
|
@@ -27,7 +27,7 @@ async function uploadImage(image, previousFile, ...folders) {
|
|
|
27
27
|
if (previousFile)
|
|
28
28
|
await deleteFile(previousFile);
|
|
29
29
|
const imageBuffer = typeof image === 'string' ? await promises_1.default.readFile(path_1.default.join(process.cwd(), image)) : image.buffer;
|
|
30
|
-
const maxSizeKb =
|
|
30
|
+
const maxSizeKb = 100;
|
|
31
31
|
const maxSizeBytes = maxSizeKb * 1024;
|
|
32
32
|
const qualityRatio = imageBuffer.length > maxSizeBytes ? maxSizeBytes / imageBuffer.length : 1;
|
|
33
33
|
const qualityMultiplier = 2;
|
|
@@ -14,23 +14,32 @@ const validate_request_1 = require("../validator/validate-request");
|
|
|
14
14
|
function callController(controller, validate, appVersion, authConfig) {
|
|
15
15
|
const { authMap, authCtor, accessToken } = authConfig;
|
|
16
16
|
return async function (req, res) {
|
|
17
|
+
const reqId = (0, helpers_1.getRandomString)(6);
|
|
18
|
+
(0, helpers_1.printInfo)(reqId, 'request started');
|
|
17
19
|
const headers = req.headers;
|
|
18
20
|
if (appVersion !== headers['x-app-version']) {
|
|
19
21
|
helpers_1.AppError.Throw({ statusCodeName: 'BAD_REQUEST', errorCode: 'APP_VERSION_MISMATCH' });
|
|
20
22
|
}
|
|
21
23
|
const inputs = (0, validate_request_1.validateRequest)(validate, req);
|
|
22
24
|
const ctx = { headers, ...inputs, file: req.file, files: req.files };
|
|
25
|
+
(0, helpers_1.printInfo)(reqId, 'request validated');
|
|
23
26
|
const tx = await (0, database_1.getDbClient)().transaction();
|
|
27
|
+
(0, helpers_1.printInfo)(reqId, 'transaction created');
|
|
24
28
|
const db = new database_1.Db(tx);
|
|
25
29
|
let result;
|
|
26
30
|
try {
|
|
27
31
|
const authUsers = await (0, auth_1.getUsersFromToken)(headers.authorization, db, accessToken, authMap);
|
|
28
32
|
const auth = new authCtor(authUsers);
|
|
33
|
+
(0, helpers_1.printInfo)(reqId, 'auth resolved');
|
|
29
34
|
result = await controller(ctx, db, auth);
|
|
35
|
+
(0, helpers_1.printInfo)(reqId, 'controller executed');
|
|
30
36
|
await tx.commit();
|
|
37
|
+
(0, helpers_1.printInfo)(reqId, 'transaction committed');
|
|
31
38
|
}
|
|
32
39
|
catch (err) {
|
|
40
|
+
(0, helpers_1.printInfo)(reqId, 'controller error');
|
|
33
41
|
await tx.rollback();
|
|
42
|
+
(0, helpers_1.printInfo)(reqId, 'transaction rollback completed');
|
|
34
43
|
throw err;
|
|
35
44
|
}
|
|
36
45
|
let data = result;
|
|
@@ -44,7 +53,9 @@ function callController(controller, validate, appVersion, authConfig) {
|
|
|
44
53
|
totalCount: typeof totalCount === 'number' ? totalCount : null,
|
|
45
54
|
successCode: (0, pangea_helpers_1.camelToUpperSnake)(controller.name),
|
|
46
55
|
};
|
|
56
|
+
(0, helpers_1.printInfo)(reqId, 'response ready');
|
|
47
57
|
res.status(http_status_codes_1.StatusCodes.OK).json(jsonBody);
|
|
58
|
+
(0, helpers_1.printInfo)(reqId, 'request finished');
|
|
48
59
|
};
|
|
49
60
|
}
|
|
50
61
|
exports.callController = callController;
|