@goweekdays/core 1.1.6 → 1.1.8
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +33 -70
- package/dist/index.js +1167 -326
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1300 -448
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -297,9 +297,9 @@ var require_combined_stream = __commonJS({
|
|
|
297
297
|
}
|
|
298
298
|
});
|
|
299
299
|
|
|
300
|
-
// node_modules/mime-db/db.json
|
|
300
|
+
// node_modules/form-data/node_modules/mime-db/db.json
|
|
301
301
|
var require_db = __commonJS({
|
|
302
|
-
"node_modules/mime-db/db.json"(exports, module) {
|
|
302
|
+
"node_modules/form-data/node_modules/mime-db/db.json"(exports, module) {
|
|
303
303
|
module.exports = {
|
|
304
304
|
"application/1d-interleaved-parityfec": {
|
|
305
305
|
source: "iana"
|
|
@@ -8822,16 +8822,16 @@ var require_db = __commonJS({
|
|
|
8822
8822
|
}
|
|
8823
8823
|
});
|
|
8824
8824
|
|
|
8825
|
-
// node_modules/mime-db/index.js
|
|
8825
|
+
// node_modules/form-data/node_modules/mime-db/index.js
|
|
8826
8826
|
var require_mime_db = __commonJS({
|
|
8827
|
-
"node_modules/mime-db/index.js"(exports, module) {
|
|
8827
|
+
"node_modules/form-data/node_modules/mime-db/index.js"(exports, module) {
|
|
8828
8828
|
module.exports = require_db();
|
|
8829
8829
|
}
|
|
8830
8830
|
});
|
|
8831
8831
|
|
|
8832
|
-
// node_modules/mime-types/index.js
|
|
8832
|
+
// node_modules/form-data/node_modules/mime-types/index.js
|
|
8833
8833
|
var require_mime_types = __commonJS({
|
|
8834
|
-
"node_modules/mime-types/index.js"(exports) {
|
|
8834
|
+
"node_modules/form-data/node_modules/mime-types/index.js"(exports) {
|
|
8835
8835
|
"use strict";
|
|
8836
8836
|
var db = require_mime_db();
|
|
8837
8837
|
var extname = __require("path").extname;
|
|
@@ -9978,6 +9978,7 @@ var require_es_set_tostringtag = __commonJS({
|
|
|
9978
9978
|
// node_modules/form-data/lib/populate.js
|
|
9979
9979
|
var require_populate = __commonJS({
|
|
9980
9980
|
"node_modules/form-data/lib/populate.js"(exports, module) {
|
|
9981
|
+
"use strict";
|
|
9981
9982
|
module.exports = function(dst, src) {
|
|
9982
9983
|
Object.keys(src).forEach(function(prop) {
|
|
9983
9984
|
dst[prop] = dst[prop] || src[prop];
|
|
@@ -9990,6 +9991,7 @@ var require_populate = __commonJS({
|
|
|
9990
9991
|
// node_modules/form-data/lib/form_data.js
|
|
9991
9992
|
var require_form_data = __commonJS({
|
|
9992
9993
|
"node_modules/form-data/lib/form_data.js"(exports, module) {
|
|
9994
|
+
"use strict";
|
|
9993
9995
|
var CombinedStream = require_combined_stream();
|
|
9994
9996
|
var util3 = __require("util");
|
|
9995
9997
|
var path = __require("path");
|
|
@@ -10001,9 +10003,8 @@ var require_form_data = __commonJS({
|
|
|
10001
10003
|
var mime = require_mime_types();
|
|
10002
10004
|
var asynckit = require_asynckit();
|
|
10003
10005
|
var setToStringTag = require_es_set_tostringtag();
|
|
10006
|
+
var hasOwn = require_hasown();
|
|
10004
10007
|
var populate = require_populate();
|
|
10005
|
-
module.exports = FormData3;
|
|
10006
|
-
util3.inherits(FormData3, CombinedStream);
|
|
10007
10008
|
function FormData3(options) {
|
|
10008
10009
|
if (!(this instanceof FormData3)) {
|
|
10009
10010
|
return new FormData3(options);
|
|
@@ -10017,16 +10018,17 @@ var require_form_data = __commonJS({
|
|
|
10017
10018
|
this[option] = options[option];
|
|
10018
10019
|
}
|
|
10019
10020
|
}
|
|
10021
|
+
util3.inherits(FormData3, CombinedStream);
|
|
10020
10022
|
FormData3.LINE_BREAK = "\r\n";
|
|
10021
10023
|
FormData3.DEFAULT_CONTENT_TYPE = "application/octet-stream";
|
|
10022
10024
|
FormData3.prototype.append = function(field, value, options) {
|
|
10023
10025
|
options = options || {};
|
|
10024
|
-
if (typeof options
|
|
10026
|
+
if (typeof options === "string") {
|
|
10025
10027
|
options = { filename: options };
|
|
10026
10028
|
}
|
|
10027
10029
|
var append2 = CombinedStream.prototype.append.bind(this);
|
|
10028
|
-
if (typeof value
|
|
10029
|
-
value =
|
|
10030
|
+
if (typeof value === "number" || value == null) {
|
|
10031
|
+
value = String(value);
|
|
10030
10032
|
}
|
|
10031
10033
|
if (Array.isArray(value)) {
|
|
10032
10034
|
this._error(new Error("Arrays are not supported."));
|
|
@@ -10042,7 +10044,7 @@ var require_form_data = __commonJS({
|
|
|
10042
10044
|
FormData3.prototype._trackLength = function(header, value, options) {
|
|
10043
10045
|
var valueLength = 0;
|
|
10044
10046
|
if (options.knownLength != null) {
|
|
10045
|
-
valueLength +=
|
|
10047
|
+
valueLength += Number(options.knownLength);
|
|
10046
10048
|
} else if (Buffer.isBuffer(value)) {
|
|
10047
10049
|
valueLength = value.length;
|
|
10048
10050
|
} else if (typeof value === "string") {
|
|
@@ -10050,7 +10052,7 @@ var require_form_data = __commonJS({
|
|
|
10050
10052
|
}
|
|
10051
10053
|
this._valueLength += valueLength;
|
|
10052
10054
|
this._overheadLength += Buffer.byteLength(header) + FormData3.LINE_BREAK.length;
|
|
10053
|
-
if (!value || !value.path && !(value.readable &&
|
|
10055
|
+
if (!value || !value.path && !(value.readable && hasOwn(value, "httpVersion")) && !(value instanceof Stream)) {
|
|
10054
10056
|
return;
|
|
10055
10057
|
}
|
|
10056
10058
|
if (!options.knownLength) {
|
|
@@ -10058,26 +10060,25 @@ var require_form_data = __commonJS({
|
|
|
10058
10060
|
}
|
|
10059
10061
|
};
|
|
10060
10062
|
FormData3.prototype._lengthRetriever = function(value, callback) {
|
|
10061
|
-
if (
|
|
10063
|
+
if (hasOwn(value, "fd")) {
|
|
10062
10064
|
if (value.end != void 0 && value.end != Infinity && value.start != void 0) {
|
|
10063
10065
|
callback(null, value.end + 1 - (value.start ? value.start : 0));
|
|
10064
10066
|
} else {
|
|
10065
10067
|
fs.stat(value.path, function(err, stat) {
|
|
10066
|
-
var fileSize;
|
|
10067
10068
|
if (err) {
|
|
10068
10069
|
callback(err);
|
|
10069
10070
|
return;
|
|
10070
10071
|
}
|
|
10071
|
-
fileSize = stat.size - (value.start ? value.start : 0);
|
|
10072
|
+
var fileSize = stat.size - (value.start ? value.start : 0);
|
|
10072
10073
|
callback(null, fileSize);
|
|
10073
10074
|
});
|
|
10074
10075
|
}
|
|
10075
|
-
} else if (
|
|
10076
|
-
callback(null,
|
|
10077
|
-
} else if (
|
|
10076
|
+
} else if (hasOwn(value, "httpVersion")) {
|
|
10077
|
+
callback(null, Number(value.headers["content-length"]));
|
|
10078
|
+
} else if (hasOwn(value, "httpModule")) {
|
|
10078
10079
|
value.on("response", function(response) {
|
|
10079
10080
|
value.pause();
|
|
10080
|
-
callback(null,
|
|
10081
|
+
callback(null, Number(response.headers["content-length"]));
|
|
10081
10082
|
});
|
|
10082
10083
|
value.resume();
|
|
10083
10084
|
} else {
|
|
@@ -10085,7 +10086,7 @@ var require_form_data = __commonJS({
|
|
|
10085
10086
|
}
|
|
10086
10087
|
};
|
|
10087
10088
|
FormData3.prototype._multiPartHeader = function(field, value, options) {
|
|
10088
|
-
if (typeof options.header
|
|
10089
|
+
if (typeof options.header === "string") {
|
|
10089
10090
|
return options.header;
|
|
10090
10091
|
}
|
|
10091
10092
|
var contentDisposition = this._getContentDisposition(value, options);
|
|
@@ -10097,12 +10098,12 @@ var require_form_data = __commonJS({
|
|
|
10097
10098
|
// if no content type. allow it to be empty array
|
|
10098
10099
|
"Content-Type": [].concat(contentType || [])
|
|
10099
10100
|
};
|
|
10100
|
-
if (typeof options.header
|
|
10101
|
+
if (typeof options.header === "object") {
|
|
10101
10102
|
populate(headers, options.header);
|
|
10102
10103
|
}
|
|
10103
10104
|
var header;
|
|
10104
10105
|
for (var prop in headers) {
|
|
10105
|
-
if (
|
|
10106
|
+
if (hasOwn(headers, prop)) {
|
|
10106
10107
|
header = headers[prop];
|
|
10107
10108
|
if (header == null) {
|
|
10108
10109
|
continue;
|
|
@@ -10118,34 +10119,33 @@ var require_form_data = __commonJS({
|
|
|
10118
10119
|
return "--" + this.getBoundary() + FormData3.LINE_BREAK + contents + FormData3.LINE_BREAK;
|
|
10119
10120
|
};
|
|
10120
10121
|
FormData3.prototype._getContentDisposition = function(value, options) {
|
|
10121
|
-
var filename
|
|
10122
|
+
var filename;
|
|
10122
10123
|
if (typeof options.filepath === "string") {
|
|
10123
10124
|
filename = path.normalize(options.filepath).replace(/\\/g, "/");
|
|
10124
|
-
} else if (options.filename || value.name || value.path) {
|
|
10125
|
-
filename = path.basename(options.filename || value.name || value.path);
|
|
10126
|
-
} else if (value.readable &&
|
|
10125
|
+
} else if (options.filename || value && (value.name || value.path)) {
|
|
10126
|
+
filename = path.basename(options.filename || value && (value.name || value.path));
|
|
10127
|
+
} else if (value && value.readable && hasOwn(value, "httpVersion")) {
|
|
10127
10128
|
filename = path.basename(value.client._httpMessage.path || "");
|
|
10128
10129
|
}
|
|
10129
10130
|
if (filename) {
|
|
10130
|
-
|
|
10131
|
+
return 'filename="' + filename + '"';
|
|
10131
10132
|
}
|
|
10132
|
-
return contentDisposition;
|
|
10133
10133
|
};
|
|
10134
10134
|
FormData3.prototype._getContentType = function(value, options) {
|
|
10135
10135
|
var contentType = options.contentType;
|
|
10136
|
-
if (!contentType && value.name) {
|
|
10136
|
+
if (!contentType && value && value.name) {
|
|
10137
10137
|
contentType = mime.lookup(value.name);
|
|
10138
10138
|
}
|
|
10139
|
-
if (!contentType && value.path) {
|
|
10139
|
+
if (!contentType && value && value.path) {
|
|
10140
10140
|
contentType = mime.lookup(value.path);
|
|
10141
10141
|
}
|
|
10142
|
-
if (!contentType && value.readable &&
|
|
10142
|
+
if (!contentType && value && value.readable && hasOwn(value, "httpVersion")) {
|
|
10143
10143
|
contentType = value.headers["content-type"];
|
|
10144
10144
|
}
|
|
10145
10145
|
if (!contentType && (options.filepath || options.filename)) {
|
|
10146
10146
|
contentType = mime.lookup(options.filepath || options.filename);
|
|
10147
10147
|
}
|
|
10148
|
-
if (!contentType && typeof value
|
|
10148
|
+
if (!contentType && value && typeof value === "object") {
|
|
10149
10149
|
contentType = FormData3.DEFAULT_CONTENT_TYPE;
|
|
10150
10150
|
}
|
|
10151
10151
|
return contentType;
|
|
@@ -10169,13 +10169,16 @@ var require_form_data = __commonJS({
|
|
|
10169
10169
|
"content-type": "multipart/form-data; boundary=" + this.getBoundary()
|
|
10170
10170
|
};
|
|
10171
10171
|
for (header in userHeaders) {
|
|
10172
|
-
if (
|
|
10172
|
+
if (hasOwn(userHeaders, header)) {
|
|
10173
10173
|
formHeaders[header.toLowerCase()] = userHeaders[header];
|
|
10174
10174
|
}
|
|
10175
10175
|
}
|
|
10176
10176
|
return formHeaders;
|
|
10177
10177
|
};
|
|
10178
10178
|
FormData3.prototype.setBoundary = function(boundary) {
|
|
10179
|
+
if (typeof boundary !== "string") {
|
|
10180
|
+
throw new TypeError("FormData boundary must be a string");
|
|
10181
|
+
}
|
|
10179
10182
|
this._boundary = boundary;
|
|
10180
10183
|
};
|
|
10181
10184
|
FormData3.prototype.getBoundary = function() {
|
|
@@ -10246,8 +10249,10 @@ var require_form_data = __commonJS({
|
|
|
10246
10249
|
});
|
|
10247
10250
|
};
|
|
10248
10251
|
FormData3.prototype.submit = function(params, cb) {
|
|
10249
|
-
var request
|
|
10250
|
-
|
|
10252
|
+
var request;
|
|
10253
|
+
var options;
|
|
10254
|
+
var defaults2 = { method: "post" };
|
|
10255
|
+
if (typeof params === "string") {
|
|
10251
10256
|
params = parseUrl(params);
|
|
10252
10257
|
options = populate({
|
|
10253
10258
|
port: params.port,
|
|
@@ -10258,11 +10263,11 @@ var require_form_data = __commonJS({
|
|
|
10258
10263
|
} else {
|
|
10259
10264
|
options = populate(params, defaults2);
|
|
10260
10265
|
if (!options.port) {
|
|
10261
|
-
options.port = options.protocol
|
|
10266
|
+
options.port = options.protocol === "https:" ? 443 : 80;
|
|
10262
10267
|
}
|
|
10263
10268
|
}
|
|
10264
10269
|
options.headers = this.getHeaders(params.headers);
|
|
10265
|
-
if (options.protocol
|
|
10270
|
+
if (options.protocol === "https:") {
|
|
10266
10271
|
request = https2.request(options);
|
|
10267
10272
|
} else {
|
|
10268
10273
|
request = http2.request(options);
|
|
@@ -10301,6 +10306,7 @@ var require_form_data = __commonJS({
|
|
|
10301
10306
|
return "[object FormData]";
|
|
10302
10307
|
};
|
|
10303
10308
|
setToStringTag(FormData3, "FormData");
|
|
10309
|
+
module.exports = FormData3;
|
|
10304
10310
|
}
|
|
10305
10311
|
});
|
|
10306
10312
|
|
|
@@ -10374,20 +10380,21 @@ var require_proxy_from_env = __commonJS({
|
|
|
10374
10380
|
}
|
|
10375
10381
|
});
|
|
10376
10382
|
|
|
10377
|
-
// node_modules/
|
|
10383
|
+
// node_modules/ms/index.js
|
|
10378
10384
|
var require_ms = __commonJS({
|
|
10379
|
-
"node_modules/
|
|
10385
|
+
"node_modules/ms/index.js"(exports, module) {
|
|
10380
10386
|
var s = 1e3;
|
|
10381
10387
|
var m = s * 60;
|
|
10382
10388
|
var h = m * 60;
|
|
10383
10389
|
var d = h * 24;
|
|
10390
|
+
var w = d * 7;
|
|
10384
10391
|
var y = d * 365.25;
|
|
10385
10392
|
module.exports = function(val, options) {
|
|
10386
10393
|
options = options || {};
|
|
10387
10394
|
var type = typeof val;
|
|
10388
10395
|
if (type === "string" && val.length > 0) {
|
|
10389
10396
|
return parse(val);
|
|
10390
|
-
} else if (type === "number" &&
|
|
10397
|
+
} else if (type === "number" && isFinite(val)) {
|
|
10391
10398
|
return options.long ? fmtLong(val) : fmtShort(val);
|
|
10392
10399
|
}
|
|
10393
10400
|
throw new Error(
|
|
@@ -10399,7 +10406,7 @@ var require_ms = __commonJS({
|
|
|
10399
10406
|
if (str.length > 100) {
|
|
10400
10407
|
return;
|
|
10401
10408
|
}
|
|
10402
|
-
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(
|
|
10409
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
10403
10410
|
str
|
|
10404
10411
|
);
|
|
10405
10412
|
if (!match) {
|
|
@@ -10414,6 +10421,10 @@ var require_ms = __commonJS({
|
|
|
10414
10421
|
case "yr":
|
|
10415
10422
|
case "y":
|
|
10416
10423
|
return n * y;
|
|
10424
|
+
case "weeks":
|
|
10425
|
+
case "week":
|
|
10426
|
+
case "w":
|
|
10427
|
+
return n * w;
|
|
10417
10428
|
case "days":
|
|
10418
10429
|
case "day":
|
|
10419
10430
|
case "d":
|
|
@@ -10447,229 +10458,388 @@ var require_ms = __commonJS({
|
|
|
10447
10458
|
}
|
|
10448
10459
|
}
|
|
10449
10460
|
function fmtShort(ms) {
|
|
10450
|
-
|
|
10461
|
+
var msAbs = Math.abs(ms);
|
|
10462
|
+
if (msAbs >= d) {
|
|
10451
10463
|
return Math.round(ms / d) + "d";
|
|
10452
10464
|
}
|
|
10453
|
-
if (
|
|
10465
|
+
if (msAbs >= h) {
|
|
10454
10466
|
return Math.round(ms / h) + "h";
|
|
10455
10467
|
}
|
|
10456
|
-
if (
|
|
10468
|
+
if (msAbs >= m) {
|
|
10457
10469
|
return Math.round(ms / m) + "m";
|
|
10458
10470
|
}
|
|
10459
|
-
if (
|
|
10471
|
+
if (msAbs >= s) {
|
|
10460
10472
|
return Math.round(ms / s) + "s";
|
|
10461
10473
|
}
|
|
10462
10474
|
return ms + "ms";
|
|
10463
10475
|
}
|
|
10464
10476
|
function fmtLong(ms) {
|
|
10465
|
-
|
|
10466
|
-
|
|
10467
|
-
|
|
10468
|
-
|
|
10469
|
-
|
|
10477
|
+
var msAbs = Math.abs(ms);
|
|
10478
|
+
if (msAbs >= d) {
|
|
10479
|
+
return plural(ms, msAbs, d, "day");
|
|
10480
|
+
}
|
|
10481
|
+
if (msAbs >= h) {
|
|
10482
|
+
return plural(ms, msAbs, h, "hour");
|
|
10483
|
+
}
|
|
10484
|
+
if (msAbs >= m) {
|
|
10485
|
+
return plural(ms, msAbs, m, "minute");
|
|
10470
10486
|
}
|
|
10471
|
-
if (
|
|
10472
|
-
return
|
|
10487
|
+
if (msAbs >= s) {
|
|
10488
|
+
return plural(ms, msAbs, s, "second");
|
|
10473
10489
|
}
|
|
10474
|
-
return
|
|
10490
|
+
return ms + " ms";
|
|
10491
|
+
}
|
|
10492
|
+
function plural(ms, msAbs, n, name) {
|
|
10493
|
+
var isPlural = msAbs >= n * 1.5;
|
|
10494
|
+
return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
|
|
10475
10495
|
}
|
|
10476
10496
|
}
|
|
10477
10497
|
});
|
|
10478
10498
|
|
|
10479
|
-
// node_modules/debug/src/
|
|
10480
|
-
var
|
|
10481
|
-
"node_modules/debug/src/
|
|
10482
|
-
|
|
10483
|
-
|
|
10484
|
-
|
|
10485
|
-
|
|
10486
|
-
|
|
10487
|
-
|
|
10488
|
-
|
|
10489
|
-
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
|
|
10493
|
-
|
|
10494
|
-
|
|
10495
|
-
|
|
10496
|
-
|
|
10497
|
-
|
|
10498
|
-
|
|
10499
|
-
|
|
10500
|
-
|
|
10501
|
-
|
|
10502
|
-
if (!debug.enabled)
|
|
10503
|
-
return;
|
|
10504
|
-
var self2 = debug;
|
|
10505
|
-
var curr = +/* @__PURE__ */ new Date();
|
|
10506
|
-
var ms = curr - (prevTime || curr);
|
|
10507
|
-
self2.diff = ms;
|
|
10508
|
-
self2.prev = prevTime;
|
|
10509
|
-
self2.curr = curr;
|
|
10510
|
-
prevTime = curr;
|
|
10511
|
-
var args = new Array(arguments.length);
|
|
10512
|
-
for (var i = 0; i < args.length; i++) {
|
|
10513
|
-
args[i] = arguments[i];
|
|
10514
|
-
}
|
|
10515
|
-
args[0] = exports.coerce(args[0]);
|
|
10516
|
-
if ("string" !== typeof args[0]) {
|
|
10517
|
-
args.unshift("%O");
|
|
10499
|
+
// node_modules/debug/src/common.js
|
|
10500
|
+
var require_common = __commonJS({
|
|
10501
|
+
"node_modules/debug/src/common.js"(exports, module) {
|
|
10502
|
+
function setup(env) {
|
|
10503
|
+
createDebug.debug = createDebug;
|
|
10504
|
+
createDebug.default = createDebug;
|
|
10505
|
+
createDebug.coerce = coerce;
|
|
10506
|
+
createDebug.disable = disable;
|
|
10507
|
+
createDebug.enable = enable;
|
|
10508
|
+
createDebug.enabled = enabled;
|
|
10509
|
+
createDebug.humanize = require_ms();
|
|
10510
|
+
createDebug.destroy = destroy;
|
|
10511
|
+
Object.keys(env).forEach((key) => {
|
|
10512
|
+
createDebug[key] = env[key];
|
|
10513
|
+
});
|
|
10514
|
+
createDebug.names = [];
|
|
10515
|
+
createDebug.skips = [];
|
|
10516
|
+
createDebug.formatters = {};
|
|
10517
|
+
function selectColor(namespace) {
|
|
10518
|
+
let hash = 0;
|
|
10519
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
10520
|
+
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
10521
|
+
hash |= 0;
|
|
10518
10522
|
}
|
|
10519
|
-
|
|
10520
|
-
|
|
10521
|
-
|
|
10523
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
10524
|
+
}
|
|
10525
|
+
createDebug.selectColor = selectColor;
|
|
10526
|
+
function createDebug(namespace) {
|
|
10527
|
+
let prevTime;
|
|
10528
|
+
let enableOverride = null;
|
|
10529
|
+
let namespacesCache;
|
|
10530
|
+
let enabledCache;
|
|
10531
|
+
function debug(...args) {
|
|
10532
|
+
if (!debug.enabled) {
|
|
10533
|
+
return;
|
|
10534
|
+
}
|
|
10535
|
+
const self2 = debug;
|
|
10536
|
+
const curr = Number(/* @__PURE__ */ new Date());
|
|
10537
|
+
const ms = curr - (prevTime || curr);
|
|
10538
|
+
self2.diff = ms;
|
|
10539
|
+
self2.prev = prevTime;
|
|
10540
|
+
self2.curr = curr;
|
|
10541
|
+
prevTime = curr;
|
|
10542
|
+
args[0] = createDebug.coerce(args[0]);
|
|
10543
|
+
if (typeof args[0] !== "string") {
|
|
10544
|
+
args.unshift("%O");
|
|
10545
|
+
}
|
|
10546
|
+
let index = 0;
|
|
10547
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
10548
|
+
if (match === "%%") {
|
|
10549
|
+
return "%";
|
|
10550
|
+
}
|
|
10551
|
+
index++;
|
|
10552
|
+
const formatter = createDebug.formatters[format];
|
|
10553
|
+
if (typeof formatter === "function") {
|
|
10554
|
+
const val = args[index];
|
|
10555
|
+
match = formatter.call(self2, val);
|
|
10556
|
+
args.splice(index, 1);
|
|
10557
|
+
index--;
|
|
10558
|
+
}
|
|
10522
10559
|
return match;
|
|
10523
|
-
|
|
10524
|
-
|
|
10525
|
-
|
|
10526
|
-
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
|
|
10560
|
+
});
|
|
10561
|
+
createDebug.formatArgs.call(self2, args);
|
|
10562
|
+
const logFn = self2.log || createDebug.log;
|
|
10563
|
+
logFn.apply(self2, args);
|
|
10564
|
+
}
|
|
10565
|
+
debug.namespace = namespace;
|
|
10566
|
+
debug.useColors = createDebug.useColors();
|
|
10567
|
+
debug.color = createDebug.selectColor(namespace);
|
|
10568
|
+
debug.extend = extend2;
|
|
10569
|
+
debug.destroy = createDebug.destroy;
|
|
10570
|
+
Object.defineProperty(debug, "enabled", {
|
|
10571
|
+
enumerable: true,
|
|
10572
|
+
configurable: false,
|
|
10573
|
+
get: () => {
|
|
10574
|
+
if (enableOverride !== null) {
|
|
10575
|
+
return enableOverride;
|
|
10576
|
+
}
|
|
10577
|
+
if (namespacesCache !== createDebug.namespaces) {
|
|
10578
|
+
namespacesCache = createDebug.namespaces;
|
|
10579
|
+
enabledCache = createDebug.enabled(namespace);
|
|
10580
|
+
}
|
|
10581
|
+
return enabledCache;
|
|
10582
|
+
},
|
|
10583
|
+
set: (v) => {
|
|
10584
|
+
enableOverride = v;
|
|
10530
10585
|
}
|
|
10531
|
-
return match;
|
|
10532
10586
|
});
|
|
10533
|
-
|
|
10534
|
-
|
|
10535
|
-
|
|
10536
|
-
|
|
10537
|
-
|
|
10538
|
-
|
|
10539
|
-
|
|
10540
|
-
|
|
10541
|
-
|
|
10542
|
-
|
|
10543
|
-
|
|
10544
|
-
|
|
10545
|
-
|
|
10546
|
-
|
|
10547
|
-
|
|
10548
|
-
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
|
|
10554
|
-
|
|
10555
|
-
namespaces = split[i].replace(/\*/g, ".*?");
|
|
10556
|
-
if (namespaces[0] === "-") {
|
|
10557
|
-
exports.skips.push(new RegExp("^" + namespaces.substr(1) + "$"));
|
|
10558
|
-
} else {
|
|
10559
|
-
exports.names.push(new RegExp("^" + namespaces + "$"));
|
|
10587
|
+
if (typeof createDebug.init === "function") {
|
|
10588
|
+
createDebug.init(debug);
|
|
10589
|
+
}
|
|
10590
|
+
return debug;
|
|
10591
|
+
}
|
|
10592
|
+
function extend2(namespace, delimiter) {
|
|
10593
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
|
|
10594
|
+
newDebug.log = this.log;
|
|
10595
|
+
return newDebug;
|
|
10596
|
+
}
|
|
10597
|
+
function enable(namespaces) {
|
|
10598
|
+
createDebug.save(namespaces);
|
|
10599
|
+
createDebug.namespaces = namespaces;
|
|
10600
|
+
createDebug.names = [];
|
|
10601
|
+
createDebug.skips = [];
|
|
10602
|
+
const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
|
|
10603
|
+
for (const ns of split) {
|
|
10604
|
+
if (ns[0] === "-") {
|
|
10605
|
+
createDebug.skips.push(ns.slice(1));
|
|
10606
|
+
} else {
|
|
10607
|
+
createDebug.names.push(ns);
|
|
10608
|
+
}
|
|
10560
10609
|
}
|
|
10561
10610
|
}
|
|
10562
|
-
|
|
10563
|
-
|
|
10564
|
-
|
|
10565
|
-
|
|
10566
|
-
|
|
10567
|
-
|
|
10568
|
-
|
|
10569
|
-
|
|
10570
|
-
|
|
10611
|
+
function matchesTemplate(search, template) {
|
|
10612
|
+
let searchIndex = 0;
|
|
10613
|
+
let templateIndex = 0;
|
|
10614
|
+
let starIndex = -1;
|
|
10615
|
+
let matchIndex = 0;
|
|
10616
|
+
while (searchIndex < search.length) {
|
|
10617
|
+
if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
|
|
10618
|
+
if (template[templateIndex] === "*") {
|
|
10619
|
+
starIndex = templateIndex;
|
|
10620
|
+
matchIndex = searchIndex;
|
|
10621
|
+
templateIndex++;
|
|
10622
|
+
} else {
|
|
10623
|
+
searchIndex++;
|
|
10624
|
+
templateIndex++;
|
|
10625
|
+
}
|
|
10626
|
+
} else if (starIndex !== -1) {
|
|
10627
|
+
templateIndex = starIndex + 1;
|
|
10628
|
+
matchIndex++;
|
|
10629
|
+
searchIndex = matchIndex;
|
|
10630
|
+
} else {
|
|
10631
|
+
return false;
|
|
10632
|
+
}
|
|
10633
|
+
}
|
|
10634
|
+
while (templateIndex < template.length && template[templateIndex] === "*") {
|
|
10635
|
+
templateIndex++;
|
|
10636
|
+
}
|
|
10637
|
+
return templateIndex === template.length;
|
|
10638
|
+
}
|
|
10639
|
+
function disable() {
|
|
10640
|
+
const namespaces = [
|
|
10641
|
+
...createDebug.names,
|
|
10642
|
+
...createDebug.skips.map((namespace) => "-" + namespace)
|
|
10643
|
+
].join(",");
|
|
10644
|
+
createDebug.enable("");
|
|
10645
|
+
return namespaces;
|
|
10646
|
+
}
|
|
10647
|
+
function enabled(name) {
|
|
10648
|
+
for (const skip of createDebug.skips) {
|
|
10649
|
+
if (matchesTemplate(name, skip)) {
|
|
10650
|
+
return false;
|
|
10651
|
+
}
|
|
10652
|
+
}
|
|
10653
|
+
for (const ns of createDebug.names) {
|
|
10654
|
+
if (matchesTemplate(name, ns)) {
|
|
10655
|
+
return true;
|
|
10656
|
+
}
|
|
10571
10657
|
}
|
|
10658
|
+
return false;
|
|
10572
10659
|
}
|
|
10573
|
-
|
|
10574
|
-
if (
|
|
10575
|
-
return
|
|
10660
|
+
function coerce(val) {
|
|
10661
|
+
if (val instanceof Error) {
|
|
10662
|
+
return val.stack || val.message;
|
|
10576
10663
|
}
|
|
10664
|
+
return val;
|
|
10577
10665
|
}
|
|
10578
|
-
|
|
10579
|
-
|
|
10580
|
-
|
|
10581
|
-
|
|
10582
|
-
|
|
10583
|
-
return val;
|
|
10666
|
+
function destroy() {
|
|
10667
|
+
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
10668
|
+
}
|
|
10669
|
+
createDebug.enable(createDebug.load());
|
|
10670
|
+
return createDebug;
|
|
10584
10671
|
}
|
|
10672
|
+
module.exports = setup;
|
|
10585
10673
|
}
|
|
10586
10674
|
});
|
|
10587
10675
|
|
|
10588
10676
|
// node_modules/debug/src/browser.js
|
|
10589
10677
|
var require_browser = __commonJS({
|
|
10590
10678
|
"node_modules/debug/src/browser.js"(exports, module) {
|
|
10591
|
-
exports = module.exports = require_debug();
|
|
10592
|
-
exports.log = log;
|
|
10593
10679
|
exports.formatArgs = formatArgs;
|
|
10594
10680
|
exports.save = save;
|
|
10595
10681
|
exports.load = load;
|
|
10596
10682
|
exports.useColors = useColors;
|
|
10597
|
-
exports.storage =
|
|
10683
|
+
exports.storage = localstorage();
|
|
10684
|
+
exports.destroy = (() => {
|
|
10685
|
+
let warned = false;
|
|
10686
|
+
return () => {
|
|
10687
|
+
if (!warned) {
|
|
10688
|
+
warned = true;
|
|
10689
|
+
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
10690
|
+
}
|
|
10691
|
+
};
|
|
10692
|
+
})();
|
|
10598
10693
|
exports.colors = [
|
|
10599
|
-
"
|
|
10600
|
-
"
|
|
10601
|
-
"
|
|
10602
|
-
"
|
|
10603
|
-
"
|
|
10604
|
-
"
|
|
10694
|
+
"#0000CC",
|
|
10695
|
+
"#0000FF",
|
|
10696
|
+
"#0033CC",
|
|
10697
|
+
"#0033FF",
|
|
10698
|
+
"#0066CC",
|
|
10699
|
+
"#0066FF",
|
|
10700
|
+
"#0099CC",
|
|
10701
|
+
"#0099FF",
|
|
10702
|
+
"#00CC00",
|
|
10703
|
+
"#00CC33",
|
|
10704
|
+
"#00CC66",
|
|
10705
|
+
"#00CC99",
|
|
10706
|
+
"#00CCCC",
|
|
10707
|
+
"#00CCFF",
|
|
10708
|
+
"#3300CC",
|
|
10709
|
+
"#3300FF",
|
|
10710
|
+
"#3333CC",
|
|
10711
|
+
"#3333FF",
|
|
10712
|
+
"#3366CC",
|
|
10713
|
+
"#3366FF",
|
|
10714
|
+
"#3399CC",
|
|
10715
|
+
"#3399FF",
|
|
10716
|
+
"#33CC00",
|
|
10717
|
+
"#33CC33",
|
|
10718
|
+
"#33CC66",
|
|
10719
|
+
"#33CC99",
|
|
10720
|
+
"#33CCCC",
|
|
10721
|
+
"#33CCFF",
|
|
10722
|
+
"#6600CC",
|
|
10723
|
+
"#6600FF",
|
|
10724
|
+
"#6633CC",
|
|
10725
|
+
"#6633FF",
|
|
10726
|
+
"#66CC00",
|
|
10727
|
+
"#66CC33",
|
|
10728
|
+
"#9900CC",
|
|
10729
|
+
"#9900FF",
|
|
10730
|
+
"#9933CC",
|
|
10731
|
+
"#9933FF",
|
|
10732
|
+
"#99CC00",
|
|
10733
|
+
"#99CC33",
|
|
10734
|
+
"#CC0000",
|
|
10735
|
+
"#CC0033",
|
|
10736
|
+
"#CC0066",
|
|
10737
|
+
"#CC0099",
|
|
10738
|
+
"#CC00CC",
|
|
10739
|
+
"#CC00FF",
|
|
10740
|
+
"#CC3300",
|
|
10741
|
+
"#CC3333",
|
|
10742
|
+
"#CC3366",
|
|
10743
|
+
"#CC3399",
|
|
10744
|
+
"#CC33CC",
|
|
10745
|
+
"#CC33FF",
|
|
10746
|
+
"#CC6600",
|
|
10747
|
+
"#CC6633",
|
|
10748
|
+
"#CC9900",
|
|
10749
|
+
"#CC9933",
|
|
10750
|
+
"#CCCC00",
|
|
10751
|
+
"#CCCC33",
|
|
10752
|
+
"#FF0000",
|
|
10753
|
+
"#FF0033",
|
|
10754
|
+
"#FF0066",
|
|
10755
|
+
"#FF0099",
|
|
10756
|
+
"#FF00CC",
|
|
10757
|
+
"#FF00FF",
|
|
10758
|
+
"#FF3300",
|
|
10759
|
+
"#FF3333",
|
|
10760
|
+
"#FF3366",
|
|
10761
|
+
"#FF3399",
|
|
10762
|
+
"#FF33CC",
|
|
10763
|
+
"#FF33FF",
|
|
10764
|
+
"#FF6600",
|
|
10765
|
+
"#FF6633",
|
|
10766
|
+
"#FF9900",
|
|
10767
|
+
"#FF9933",
|
|
10768
|
+
"#FFCC00",
|
|
10769
|
+
"#FFCC33"
|
|
10605
10770
|
];
|
|
10606
10771
|
function useColors() {
|
|
10607
|
-
if (typeof window !== "undefined" && window.process && window.process.type === "renderer") {
|
|
10772
|
+
if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
|
|
10608
10773
|
return true;
|
|
10609
10774
|
}
|
|
10610
|
-
|
|
10611
|
-
|
|
10775
|
+
if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
10776
|
+
return false;
|
|
10777
|
+
}
|
|
10778
|
+
let m;
|
|
10779
|
+
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
|
|
10780
|
+
typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
|
|
10612
10781
|
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
10613
|
-
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(
|
|
10782
|
+
typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
|
|
10614
10783
|
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
10615
10784
|
}
|
|
10616
|
-
exports.formatters.j = function(v) {
|
|
10617
|
-
try {
|
|
10618
|
-
return JSON.stringify(v);
|
|
10619
|
-
} catch (err) {
|
|
10620
|
-
return "[UnexpectedJSONParseError]: " + err.message;
|
|
10621
|
-
}
|
|
10622
|
-
};
|
|
10623
10785
|
function formatArgs(args) {
|
|
10624
|
-
|
|
10625
|
-
|
|
10626
|
-
if (!useColors2)
|
|
10786
|
+
args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
|
|
10787
|
+
if (!this.useColors) {
|
|
10627
10788
|
return;
|
|
10628
|
-
|
|
10789
|
+
}
|
|
10790
|
+
const c = "color: " + this.color;
|
|
10629
10791
|
args.splice(1, 0, c, "color: inherit");
|
|
10630
|
-
|
|
10631
|
-
|
|
10632
|
-
args[0].replace(/%[a-zA-Z%]/g,
|
|
10633
|
-
if ("%%"
|
|
10792
|
+
let index = 0;
|
|
10793
|
+
let lastC = 0;
|
|
10794
|
+
args[0].replace(/%[a-zA-Z%]/g, (match) => {
|
|
10795
|
+
if (match === "%%") {
|
|
10634
10796
|
return;
|
|
10797
|
+
}
|
|
10635
10798
|
index++;
|
|
10636
|
-
if ("%c"
|
|
10799
|
+
if (match === "%c") {
|
|
10637
10800
|
lastC = index;
|
|
10638
10801
|
}
|
|
10639
10802
|
});
|
|
10640
10803
|
args.splice(lastC, 0, c);
|
|
10641
10804
|
}
|
|
10642
|
-
|
|
10643
|
-
|
|
10644
|
-
}
|
|
10805
|
+
exports.log = console.debug || console.log || (() => {
|
|
10806
|
+
});
|
|
10645
10807
|
function save(namespaces) {
|
|
10646
10808
|
try {
|
|
10647
|
-
if (
|
|
10648
|
-
exports.storage.
|
|
10809
|
+
if (namespaces) {
|
|
10810
|
+
exports.storage.setItem("debug", namespaces);
|
|
10649
10811
|
} else {
|
|
10650
|
-
exports.storage.debug
|
|
10812
|
+
exports.storage.removeItem("debug");
|
|
10651
10813
|
}
|
|
10652
|
-
} catch (
|
|
10814
|
+
} catch (error) {
|
|
10653
10815
|
}
|
|
10654
10816
|
}
|
|
10655
10817
|
function load() {
|
|
10656
|
-
|
|
10818
|
+
let r;
|
|
10657
10819
|
try {
|
|
10658
|
-
r = exports.storage.debug;
|
|
10659
|
-
} catch (
|
|
10820
|
+
r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG");
|
|
10821
|
+
} catch (error) {
|
|
10660
10822
|
}
|
|
10661
10823
|
if (!r && typeof process !== "undefined" && "env" in process) {
|
|
10662
10824
|
r = process.env.DEBUG;
|
|
10663
10825
|
}
|
|
10664
10826
|
return r;
|
|
10665
10827
|
}
|
|
10666
|
-
exports.enable(load());
|
|
10667
10828
|
function localstorage() {
|
|
10668
10829
|
try {
|
|
10669
|
-
return
|
|
10670
|
-
} catch (
|
|
10830
|
+
return localStorage;
|
|
10831
|
+
} catch (error) {
|
|
10671
10832
|
}
|
|
10672
10833
|
}
|
|
10834
|
+
module.exports = require_common()(exports);
|
|
10835
|
+
var { formatters } = module.exports;
|
|
10836
|
+
formatters.j = function(v) {
|
|
10837
|
+
try {
|
|
10838
|
+
return JSON.stringify(v);
|
|
10839
|
+
} catch (error) {
|
|
10840
|
+
return "[UnexpectedJSONParseError]: " + error.message;
|
|
10841
|
+
}
|
|
10842
|
+
};
|
|
10673
10843
|
}
|
|
10674
10844
|
});
|
|
10675
10845
|
|
|
@@ -10678,129 +10848,179 @@ var require_node = __commonJS({
|
|
|
10678
10848
|
"node_modules/debug/src/node.js"(exports, module) {
|
|
10679
10849
|
var tty = __require("tty");
|
|
10680
10850
|
var util3 = __require("util");
|
|
10681
|
-
exports = module.exports = require_debug();
|
|
10682
10851
|
exports.init = init;
|
|
10683
10852
|
exports.log = log;
|
|
10684
10853
|
exports.formatArgs = formatArgs;
|
|
10685
10854
|
exports.save = save;
|
|
10686
10855
|
exports.load = load;
|
|
10687
10856
|
exports.useColors = useColors;
|
|
10857
|
+
exports.destroy = util3.deprecate(
|
|
10858
|
+
() => {
|
|
10859
|
+
},
|
|
10860
|
+
"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."
|
|
10861
|
+
);
|
|
10688
10862
|
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
10689
|
-
|
|
10863
|
+
try {
|
|
10864
|
+
const supportsColor = __require("supports-color");
|
|
10865
|
+
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
|
10866
|
+
exports.colors = [
|
|
10867
|
+
20,
|
|
10868
|
+
21,
|
|
10869
|
+
26,
|
|
10870
|
+
27,
|
|
10871
|
+
32,
|
|
10872
|
+
33,
|
|
10873
|
+
38,
|
|
10874
|
+
39,
|
|
10875
|
+
40,
|
|
10876
|
+
41,
|
|
10877
|
+
42,
|
|
10878
|
+
43,
|
|
10879
|
+
44,
|
|
10880
|
+
45,
|
|
10881
|
+
56,
|
|
10882
|
+
57,
|
|
10883
|
+
62,
|
|
10884
|
+
63,
|
|
10885
|
+
68,
|
|
10886
|
+
69,
|
|
10887
|
+
74,
|
|
10888
|
+
75,
|
|
10889
|
+
76,
|
|
10890
|
+
77,
|
|
10891
|
+
78,
|
|
10892
|
+
79,
|
|
10893
|
+
80,
|
|
10894
|
+
81,
|
|
10895
|
+
92,
|
|
10896
|
+
93,
|
|
10897
|
+
98,
|
|
10898
|
+
99,
|
|
10899
|
+
112,
|
|
10900
|
+
113,
|
|
10901
|
+
128,
|
|
10902
|
+
129,
|
|
10903
|
+
134,
|
|
10904
|
+
135,
|
|
10905
|
+
148,
|
|
10906
|
+
149,
|
|
10907
|
+
160,
|
|
10908
|
+
161,
|
|
10909
|
+
162,
|
|
10910
|
+
163,
|
|
10911
|
+
164,
|
|
10912
|
+
165,
|
|
10913
|
+
166,
|
|
10914
|
+
167,
|
|
10915
|
+
168,
|
|
10916
|
+
169,
|
|
10917
|
+
170,
|
|
10918
|
+
171,
|
|
10919
|
+
172,
|
|
10920
|
+
173,
|
|
10921
|
+
178,
|
|
10922
|
+
179,
|
|
10923
|
+
184,
|
|
10924
|
+
185,
|
|
10925
|
+
196,
|
|
10926
|
+
197,
|
|
10927
|
+
198,
|
|
10928
|
+
199,
|
|
10929
|
+
200,
|
|
10930
|
+
201,
|
|
10931
|
+
202,
|
|
10932
|
+
203,
|
|
10933
|
+
204,
|
|
10934
|
+
205,
|
|
10935
|
+
206,
|
|
10936
|
+
207,
|
|
10937
|
+
208,
|
|
10938
|
+
209,
|
|
10939
|
+
214,
|
|
10940
|
+
215,
|
|
10941
|
+
220,
|
|
10942
|
+
221
|
|
10943
|
+
];
|
|
10944
|
+
}
|
|
10945
|
+
} catch (error) {
|
|
10946
|
+
}
|
|
10947
|
+
exports.inspectOpts = Object.keys(process.env).filter((key) => {
|
|
10690
10948
|
return /^debug_/i.test(key);
|
|
10691
|
-
}).reduce(
|
|
10692
|
-
|
|
10949
|
+
}).reduce((obj, key) => {
|
|
10950
|
+
const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
|
|
10693
10951
|
return k.toUpperCase();
|
|
10694
10952
|
});
|
|
10695
|
-
|
|
10696
|
-
if (/^(yes|on|true|enabled)$/i.test(val))
|
|
10953
|
+
let val = process.env[key];
|
|
10954
|
+
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
|
10697
10955
|
val = true;
|
|
10698
|
-
else if (/^(no|off|false|disabled)$/i.test(val))
|
|
10956
|
+
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
|
10699
10957
|
val = false;
|
|
10700
|
-
else if (val === "null")
|
|
10958
|
+
} else if (val === "null") {
|
|
10701
10959
|
val = null;
|
|
10702
|
-
else
|
|
10960
|
+
} else {
|
|
10703
10961
|
val = Number(val);
|
|
10962
|
+
}
|
|
10704
10963
|
obj[prop] = val;
|
|
10705
10964
|
return obj;
|
|
10706
10965
|
}, {});
|
|
10707
|
-
var fd = parseInt(process.env.DEBUG_FD, 10) || 2;
|
|
10708
|
-
if (1 !== fd && 2 !== fd) {
|
|
10709
|
-
util3.deprecate(function() {
|
|
10710
|
-
}, "except for stderr(2) and stdout(1), any other usage of DEBUG_FD is deprecated. Override debug.log if you want to use a different log function (https://git.io/debug_fd)")();
|
|
10711
|
-
}
|
|
10712
|
-
var stream4 = 1 === fd ? process.stdout : 2 === fd ? process.stderr : createWritableStdioStream(fd);
|
|
10713
10966
|
function useColors() {
|
|
10714
|
-
return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(fd);
|
|
10967
|
+
return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(process.stderr.fd);
|
|
10715
10968
|
}
|
|
10716
|
-
exports.formatters.o = function(v) {
|
|
10717
|
-
this.inspectOpts.colors = this.useColors;
|
|
10718
|
-
return util3.inspect(v, this.inspectOpts).split("\n").map(function(str) {
|
|
10719
|
-
return str.trim();
|
|
10720
|
-
}).join(" ");
|
|
10721
|
-
};
|
|
10722
|
-
exports.formatters.O = function(v) {
|
|
10723
|
-
this.inspectOpts.colors = this.useColors;
|
|
10724
|
-
return util3.inspect(v, this.inspectOpts);
|
|
10725
|
-
};
|
|
10726
10969
|
function formatArgs(args) {
|
|
10727
|
-
|
|
10728
|
-
var useColors2 = this.useColors;
|
|
10970
|
+
const { namespace: name, useColors: useColors2 } = this;
|
|
10729
10971
|
if (useColors2) {
|
|
10730
|
-
|
|
10731
|
-
|
|
10972
|
+
const c = this.color;
|
|
10973
|
+
const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
|
|
10974
|
+
const prefix = ` ${colorCode};1m${name} \x1B[0m`;
|
|
10732
10975
|
args[0] = prefix + args[0].split("\n").join("\n" + prefix);
|
|
10733
|
-
args.push(
|
|
10976
|
+
args.push(colorCode + "m+" + module.exports.humanize(this.diff) + "\x1B[0m");
|
|
10734
10977
|
} else {
|
|
10735
|
-
args[0] = (
|
|
10978
|
+
args[0] = getDate() + name + " " + args[0];
|
|
10979
|
+
}
|
|
10980
|
+
}
|
|
10981
|
+
function getDate() {
|
|
10982
|
+
if (exports.inspectOpts.hideDate) {
|
|
10983
|
+
return "";
|
|
10736
10984
|
}
|
|
10985
|
+
return (/* @__PURE__ */ new Date()).toISOString() + " ";
|
|
10737
10986
|
}
|
|
10738
|
-
function log() {
|
|
10739
|
-
return
|
|
10987
|
+
function log(...args) {
|
|
10988
|
+
return process.stderr.write(util3.formatWithOptions(exports.inspectOpts, ...args) + "\n");
|
|
10740
10989
|
}
|
|
10741
10990
|
function save(namespaces) {
|
|
10742
|
-
if (
|
|
10743
|
-
delete process.env.DEBUG;
|
|
10744
|
-
} else {
|
|
10991
|
+
if (namespaces) {
|
|
10745
10992
|
process.env.DEBUG = namespaces;
|
|
10993
|
+
} else {
|
|
10994
|
+
delete process.env.DEBUG;
|
|
10746
10995
|
}
|
|
10747
10996
|
}
|
|
10748
10997
|
function load() {
|
|
10749
10998
|
return process.env.DEBUG;
|
|
10750
10999
|
}
|
|
10751
|
-
function createWritableStdioStream(fd2) {
|
|
10752
|
-
var stream5;
|
|
10753
|
-
var tty_wrap = process.binding("tty_wrap");
|
|
10754
|
-
switch (tty_wrap.guessHandleType(fd2)) {
|
|
10755
|
-
case "TTY":
|
|
10756
|
-
stream5 = new tty.WriteStream(fd2);
|
|
10757
|
-
stream5._type = "tty";
|
|
10758
|
-
if (stream5._handle && stream5._handle.unref) {
|
|
10759
|
-
stream5._handle.unref();
|
|
10760
|
-
}
|
|
10761
|
-
break;
|
|
10762
|
-
case "FILE":
|
|
10763
|
-
var fs = __require("fs");
|
|
10764
|
-
stream5 = new fs.SyncWriteStream(fd2, { autoClose: false });
|
|
10765
|
-
stream5._type = "fs";
|
|
10766
|
-
break;
|
|
10767
|
-
case "PIPE":
|
|
10768
|
-
case "TCP":
|
|
10769
|
-
var net = __require("net");
|
|
10770
|
-
stream5 = new net.Socket({
|
|
10771
|
-
fd: fd2,
|
|
10772
|
-
readable: false,
|
|
10773
|
-
writable: true
|
|
10774
|
-
});
|
|
10775
|
-
stream5.readable = false;
|
|
10776
|
-
stream5.read = null;
|
|
10777
|
-
stream5._type = "pipe";
|
|
10778
|
-
if (stream5._handle && stream5._handle.unref) {
|
|
10779
|
-
stream5._handle.unref();
|
|
10780
|
-
}
|
|
10781
|
-
break;
|
|
10782
|
-
default:
|
|
10783
|
-
throw new Error("Implement me. Unknown stream file type!");
|
|
10784
|
-
}
|
|
10785
|
-
stream5.fd = fd2;
|
|
10786
|
-
stream5._isStdio = true;
|
|
10787
|
-
return stream5;
|
|
10788
|
-
}
|
|
10789
11000
|
function init(debug) {
|
|
10790
11001
|
debug.inspectOpts = {};
|
|
10791
|
-
|
|
10792
|
-
for (
|
|
11002
|
+
const keys = Object.keys(exports.inspectOpts);
|
|
11003
|
+
for (let i = 0; i < keys.length; i++) {
|
|
10793
11004
|
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
10794
11005
|
}
|
|
10795
11006
|
}
|
|
10796
|
-
exports
|
|
11007
|
+
module.exports = require_common()(exports);
|
|
11008
|
+
var { formatters } = module.exports;
|
|
11009
|
+
formatters.o = function(v) {
|
|
11010
|
+
this.inspectOpts.colors = this.useColors;
|
|
11011
|
+
return util3.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
|
|
11012
|
+
};
|
|
11013
|
+
formatters.O = function(v) {
|
|
11014
|
+
this.inspectOpts.colors = this.useColors;
|
|
11015
|
+
return util3.inspect(v, this.inspectOpts);
|
|
11016
|
+
};
|
|
10797
11017
|
}
|
|
10798
11018
|
});
|
|
10799
11019
|
|
|
10800
11020
|
// node_modules/debug/src/index.js
|
|
10801
11021
|
var require_src = __commonJS({
|
|
10802
11022
|
"node_modules/debug/src/index.js"(exports, module) {
|
|
10803
|
-
if (typeof process
|
|
11023
|
+
if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
|
|
10804
11024
|
module.exports = require_browser();
|
|
10805
11025
|
} else {
|
|
10806
11026
|
module.exports = require_node();
|
|
@@ -10809,7 +11029,7 @@ var require_src = __commonJS({
|
|
|
10809
11029
|
});
|
|
10810
11030
|
|
|
10811
11031
|
// node_modules/follow-redirects/debug.js
|
|
10812
|
-
var
|
|
11032
|
+
var require_debug = __commonJS({
|
|
10813
11033
|
"node_modules/follow-redirects/debug.js"(exports, module) {
|
|
10814
11034
|
var debug;
|
|
10815
11035
|
module.exports = function() {
|
|
@@ -10837,7 +11057,7 @@ var require_follow_redirects = __commonJS({
|
|
|
10837
11057
|
var https2 = __require("https");
|
|
10838
11058
|
var Writable = __require("stream").Writable;
|
|
10839
11059
|
var assert = __require("assert");
|
|
10840
|
-
var debug =
|
|
11060
|
+
var debug = require_debug();
|
|
10841
11061
|
(function detectUnsupportedEnvironment() {
|
|
10842
11062
|
var looksLikeNode = typeof process !== "undefined";
|
|
10843
11063
|
var looksLikeBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
@@ -11352,8 +11572,10 @@ import {
|
|
|
11352
11572
|
BadRequestError as BadRequestError2,
|
|
11353
11573
|
InternalServerError,
|
|
11354
11574
|
logger,
|
|
11575
|
+
makeCacheKey,
|
|
11355
11576
|
paginate,
|
|
11356
|
-
useAtlas
|
|
11577
|
+
useAtlas,
|
|
11578
|
+
useCache
|
|
11357
11579
|
} from "@goweekdays/utils";
|
|
11358
11580
|
import { ObjectId as ObjectId2 } from "mongodb";
|
|
11359
11581
|
function useVerificationRepo() {
|
|
@@ -11361,7 +11583,22 @@ function useVerificationRepo() {
|
|
|
11361
11583
|
if (!db) {
|
|
11362
11584
|
throw new InternalServerError("Unable to connect to server.");
|
|
11363
11585
|
}
|
|
11364
|
-
const
|
|
11586
|
+
const namespace_collection = "verifications";
|
|
11587
|
+
const collection = db.collection(namespace_collection);
|
|
11588
|
+
const { getCache, setCache, delNamespace } = useCache();
|
|
11589
|
+
function delCachedData() {
|
|
11590
|
+
delNamespace(namespace_collection).then(() => {
|
|
11591
|
+
logger.log({
|
|
11592
|
+
level: "info",
|
|
11593
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
11594
|
+
});
|
|
11595
|
+
}).catch((err) => {
|
|
11596
|
+
logger.log({
|
|
11597
|
+
level: "error",
|
|
11598
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
11599
|
+
});
|
|
11600
|
+
});
|
|
11601
|
+
}
|
|
11365
11602
|
async function createIndex() {
|
|
11366
11603
|
try {
|
|
11367
11604
|
await collection.createIndex([
|
|
@@ -11403,6 +11640,7 @@ function useVerificationRepo() {
|
|
|
11403
11640
|
value = new MVerification(value);
|
|
11404
11641
|
try {
|
|
11405
11642
|
const res = await collection.insertOne(value, { session });
|
|
11643
|
+
delCachedData();
|
|
11406
11644
|
return res.insertedId;
|
|
11407
11645
|
} catch (error) {
|
|
11408
11646
|
logger.log({ level: "error", message: `${error}` });
|
|
@@ -11425,7 +11663,30 @@ function useVerificationRepo() {
|
|
|
11425
11663
|
throw new BadRequestError2("Invalid ID.");
|
|
11426
11664
|
}
|
|
11427
11665
|
try {
|
|
11428
|
-
|
|
11666
|
+
const cacheKey = makeCacheKey(namespace_collection, {
|
|
11667
|
+
id: _id.toString()
|
|
11668
|
+
});
|
|
11669
|
+
const cached = await getCache(cacheKey);
|
|
11670
|
+
if (cached) {
|
|
11671
|
+
logger.log({
|
|
11672
|
+
level: "info",
|
|
11673
|
+
message: `Cache hit for getById verification: ${cacheKey}`
|
|
11674
|
+
});
|
|
11675
|
+
return cached;
|
|
11676
|
+
}
|
|
11677
|
+
const data = await collection.findOne({ _id });
|
|
11678
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
11679
|
+
logger.log({
|
|
11680
|
+
level: "info",
|
|
11681
|
+
message: `Cache set for verification by id: ${cacheKey}`
|
|
11682
|
+
});
|
|
11683
|
+
}).catch((err) => {
|
|
11684
|
+
logger.log({
|
|
11685
|
+
level: "error",
|
|
11686
|
+
message: `Failed to set cache for verification by id: ${err.message}`
|
|
11687
|
+
});
|
|
11688
|
+
});
|
|
11689
|
+
return data;
|
|
11429
11690
|
} catch (error) {
|
|
11430
11691
|
throw new InternalServerError(
|
|
11431
11692
|
"Internal server error, failed to retrieve verification."
|
|
@@ -11444,20 +11705,36 @@ function useVerificationRepo() {
|
|
|
11444
11705
|
} = {}) {
|
|
11445
11706
|
page = page > 0 ? page - 1 : 0;
|
|
11446
11707
|
const query = { status };
|
|
11708
|
+
const cacheKeyOptions = { status, limit, page };
|
|
11447
11709
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
11710
|
+
cacheKeyOptions.sort = JSON.stringify(sort);
|
|
11448
11711
|
if (app) {
|
|
11449
11712
|
query["metadata.app"] = app;
|
|
11713
|
+
cacheKeyOptions.app = app;
|
|
11450
11714
|
}
|
|
11451
11715
|
if (search) {
|
|
11452
11716
|
query.$text = { $search: search };
|
|
11717
|
+
cacheKeyOptions.search = search;
|
|
11453
11718
|
}
|
|
11454
11719
|
if (Array.isArray(type)) {
|
|
11455
11720
|
query.type = { $in: type };
|
|
11721
|
+
cacheKeyOptions.type = JSON.stringify(type);
|
|
11456
11722
|
} else if (type) {
|
|
11457
11723
|
query.type = type;
|
|
11724
|
+
cacheKeyOptions.type = type;
|
|
11458
11725
|
}
|
|
11459
11726
|
if (email) {
|
|
11460
11727
|
query.email = email;
|
|
11728
|
+
cacheKeyOptions.email = email;
|
|
11729
|
+
}
|
|
11730
|
+
const cacheKey = makeCacheKey(namespace_collection, cacheKeyOptions);
|
|
11731
|
+
const cached = await getCache(cacheKey);
|
|
11732
|
+
if (cached) {
|
|
11733
|
+
logger.log({
|
|
11734
|
+
level: "info",
|
|
11735
|
+
message: `Cache hit for getVerifications: ${cacheKey}`
|
|
11736
|
+
});
|
|
11737
|
+
return cached;
|
|
11461
11738
|
}
|
|
11462
11739
|
try {
|
|
11463
11740
|
const items = await collection.aggregate([
|
|
@@ -11477,7 +11754,19 @@ function useVerificationRepo() {
|
|
|
11477
11754
|
}
|
|
11478
11755
|
]).toArray();
|
|
11479
11756
|
const length = await collection.countDocuments(query);
|
|
11480
|
-
|
|
11757
|
+
const data = paginate(items, page, limit, length);
|
|
11758
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
11759
|
+
logger.log({
|
|
11760
|
+
level: "info",
|
|
11761
|
+
message: `Cache set for getVerifications: ${cacheKey}`
|
|
11762
|
+
});
|
|
11763
|
+
}).catch((err) => {
|
|
11764
|
+
logger.log({
|
|
11765
|
+
level: "error",
|
|
11766
|
+
message: `Failed to set cache for getVerifications: ${err.message}`
|
|
11767
|
+
});
|
|
11768
|
+
});
|
|
11769
|
+
return data;
|
|
11481
11770
|
} catch (error) {
|
|
11482
11771
|
logger.log({ level: "error", message: `${error}` });
|
|
11483
11772
|
throw error;
|
|
@@ -11485,7 +11774,30 @@ function useVerificationRepo() {
|
|
|
11485
11774
|
}
|
|
11486
11775
|
async function getByIdByType(type) {
|
|
11487
11776
|
try {
|
|
11488
|
-
|
|
11777
|
+
const cacheKey = makeCacheKey(namespace_collection, {
|
|
11778
|
+
type
|
|
11779
|
+
});
|
|
11780
|
+
const cached = await getCache(cacheKey);
|
|
11781
|
+
if (cached) {
|
|
11782
|
+
logger.log({
|
|
11783
|
+
level: "info",
|
|
11784
|
+
message: `Cache hit for getByIdByType verification: ${cacheKey}`
|
|
11785
|
+
});
|
|
11786
|
+
return cached;
|
|
11787
|
+
}
|
|
11788
|
+
const data = await collection.find({ type }).toArray();
|
|
11789
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
11790
|
+
logger.log({
|
|
11791
|
+
level: "info",
|
|
11792
|
+
message: `Cache set for verification by type: ${cacheKey}`
|
|
11793
|
+
});
|
|
11794
|
+
}).catch((err) => {
|
|
11795
|
+
logger.log({
|
|
11796
|
+
level: "error",
|
|
11797
|
+
message: `Failed to set cache for verification by type: ${err.message}`
|
|
11798
|
+
});
|
|
11799
|
+
});
|
|
11800
|
+
return data;
|
|
11489
11801
|
} catch (error) {
|
|
11490
11802
|
return Promise.reject(error);
|
|
11491
11803
|
}
|
|
@@ -11497,11 +11809,13 @@ function useVerificationRepo() {
|
|
|
11497
11809
|
throw new BadRequestError2("Invalid ID.");
|
|
11498
11810
|
}
|
|
11499
11811
|
try {
|
|
11500
|
-
|
|
11812
|
+
const result = await collection.updateOne(
|
|
11501
11813
|
{ _id },
|
|
11502
11814
|
{ $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
11503
11815
|
{ session }
|
|
11504
11816
|
);
|
|
11817
|
+
delCachedData();
|
|
11818
|
+
return result;
|
|
11505
11819
|
} catch (error) {
|
|
11506
11820
|
throw new InternalServerError("Error updating verification status.");
|
|
11507
11821
|
}
|
|
@@ -11622,8 +11936,8 @@ import {
|
|
|
11622
11936
|
logger as logger2,
|
|
11623
11937
|
BadRequestError as BadRequestError3,
|
|
11624
11938
|
paginate as paginate2,
|
|
11625
|
-
useCache,
|
|
11626
|
-
makeCacheKey
|
|
11939
|
+
useCache as useCache2,
|
|
11940
|
+
makeCacheKey as makeCacheKey2
|
|
11627
11941
|
} from "@goweekdays/utils";
|
|
11628
11942
|
function useUserRepo() {
|
|
11629
11943
|
const db = useAtlas2.getDb();
|
|
@@ -11632,7 +11946,7 @@ function useUserRepo() {
|
|
|
11632
11946
|
}
|
|
11633
11947
|
const namespace_collection = "users";
|
|
11634
11948
|
const collection = db.collection(namespace_collection);
|
|
11635
|
-
const { getCache, setCache, delNamespace } =
|
|
11949
|
+
const { getCache, setCache, delNamespace } = useCache2();
|
|
11636
11950
|
function delCachedData() {
|
|
11637
11951
|
delNamespace(namespace_collection).then(() => {
|
|
11638
11952
|
logger2.log({
|
|
@@ -11684,7 +11998,7 @@ function useUserRepo() {
|
|
|
11684
11998
|
}
|
|
11685
11999
|
}
|
|
11686
12000
|
async function getUserByEmail(email) {
|
|
11687
|
-
const cacheKey =
|
|
12001
|
+
const cacheKey = makeCacheKey2(namespace_collection, { email });
|
|
11688
12002
|
try {
|
|
11689
12003
|
const cached = await getCache(cacheKey);
|
|
11690
12004
|
if (cached) {
|
|
@@ -11696,7 +12010,7 @@ function useUserRepo() {
|
|
|
11696
12010
|
}
|
|
11697
12011
|
const result = await collection.findOne({ email });
|
|
11698
12012
|
if (result) {
|
|
11699
|
-
setCache(cacheKey, result).then(() => {
|
|
12013
|
+
setCache(cacheKey, result, 300, namespace_collection).then(() => {
|
|
11700
12014
|
logger2.log({
|
|
11701
12015
|
level: "info",
|
|
11702
12016
|
message: `Cache set for user by email: ${cacheKey}`
|
|
@@ -11714,7 +12028,7 @@ function useUserRepo() {
|
|
|
11714
12028
|
}
|
|
11715
12029
|
}
|
|
11716
12030
|
async function getUserByReferralCode(referralCode) {
|
|
11717
|
-
const cacheKey =
|
|
12031
|
+
const cacheKey = makeCacheKey2(namespace_collection, { referralCode });
|
|
11718
12032
|
try {
|
|
11719
12033
|
const cached = await getCache(cacheKey);
|
|
11720
12034
|
if (cached) {
|
|
@@ -11726,7 +12040,7 @@ function useUserRepo() {
|
|
|
11726
12040
|
}
|
|
11727
12041
|
const result = await collection.findOne({ referralCode });
|
|
11728
12042
|
if (result) {
|
|
11729
|
-
setCache(cacheKey, result).then(() => {
|
|
12043
|
+
setCache(cacheKey, result, 300, namespace_collection).then(() => {
|
|
11730
12044
|
logger2.log({
|
|
11731
12045
|
level: "info",
|
|
11732
12046
|
message: `Cache set for user by referral code: ${cacheKey}`
|
|
@@ -11749,7 +12063,7 @@ function useUserRepo() {
|
|
|
11749
12063
|
} catch (error) {
|
|
11750
12064
|
throw new Error("Invalid user ID.");
|
|
11751
12065
|
}
|
|
11752
|
-
const cacheKey =
|
|
12066
|
+
const cacheKey = makeCacheKey2(namespace_collection, { _id: String(_id) });
|
|
11753
12067
|
try {
|
|
11754
12068
|
const cached = await getCache(cacheKey);
|
|
11755
12069
|
if (cached) {
|
|
@@ -11761,7 +12075,7 @@ function useUserRepo() {
|
|
|
11761
12075
|
}
|
|
11762
12076
|
const result = await collection.findOne({ _id });
|
|
11763
12077
|
if (result) {
|
|
11764
|
-
setCache(cacheKey, result).then(() => {
|
|
12078
|
+
setCache(cacheKey, result, 300, namespace_collection).then(() => {
|
|
11765
12079
|
logger2.log({
|
|
11766
12080
|
level: "info",
|
|
11767
12081
|
message: `Cache set for user by id: ${cacheKey}`
|
|
@@ -11795,7 +12109,7 @@ function useUserRepo() {
|
|
|
11795
12109
|
if (type) {
|
|
11796
12110
|
query.type = type;
|
|
11797
12111
|
}
|
|
11798
|
-
const cacheKey =
|
|
12112
|
+
const cacheKey = makeCacheKey2(namespace_collection, {
|
|
11799
12113
|
search,
|
|
11800
12114
|
page,
|
|
11801
12115
|
limit,
|
|
@@ -11835,7 +12149,7 @@ function useUserRepo() {
|
|
|
11835
12149
|
]).toArray();
|
|
11836
12150
|
const length = await collection.countDocuments(query);
|
|
11837
12151
|
const data = paginate2(items, page, limit, length);
|
|
11838
|
-
setCache(cacheKey, data).then(() => {
|
|
12152
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
11839
12153
|
logger2.log({
|
|
11840
12154
|
level: "info",
|
|
11841
12155
|
message: `Cache set for getUsers: ${cacheKey}`
|
|
@@ -11983,10 +12297,10 @@ import {
|
|
|
11983
12297
|
BadRequestError as BadRequestError5,
|
|
11984
12298
|
InternalServerError as InternalServerError3,
|
|
11985
12299
|
logger as logger3,
|
|
11986
|
-
makeCacheKey as
|
|
12300
|
+
makeCacheKey as makeCacheKey3,
|
|
11987
12301
|
paginate as paginate3,
|
|
11988
12302
|
useAtlas as useAtlas3,
|
|
11989
|
-
useCache as
|
|
12303
|
+
useCache as useCache3
|
|
11990
12304
|
} from "@goweekdays/utils";
|
|
11991
12305
|
|
|
11992
12306
|
// src/models/member.model.ts
|
|
@@ -12058,7 +12372,7 @@ function useMemberRepo() {
|
|
|
12058
12372
|
}
|
|
12059
12373
|
const namespace_collection = "members";
|
|
12060
12374
|
const collection = db.collection(namespace_collection);
|
|
12061
|
-
const { getCache, setCache, delNamespace } =
|
|
12375
|
+
const { getCache, setCache, delNamespace } = useCache3();
|
|
12062
12376
|
function delCachedData() {
|
|
12063
12377
|
delNamespace(namespace_collection).then(() => {
|
|
12064
12378
|
logger3.log({
|
|
@@ -12134,7 +12448,7 @@ function useMemberRepo() {
|
|
|
12134
12448
|
throw new BadRequestError5("Invalid ID.");
|
|
12135
12449
|
}
|
|
12136
12450
|
try {
|
|
12137
|
-
const cacheKey =
|
|
12451
|
+
const cacheKey = makeCacheKey3(namespace_collection, {
|
|
12138
12452
|
id: _id.toString()
|
|
12139
12453
|
});
|
|
12140
12454
|
const cached = await getCache(cacheKey);
|
|
@@ -12146,7 +12460,7 @@ function useMemberRepo() {
|
|
|
12146
12460
|
return cached;
|
|
12147
12461
|
}
|
|
12148
12462
|
const data = await collection.findOne({ _id });
|
|
12149
|
-
setCache(cacheKey, data).then(() => {
|
|
12463
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
12150
12464
|
logger3.log({
|
|
12151
12465
|
level: "info",
|
|
12152
12466
|
message: `Cache set for member by id: ${cacheKey}`
|
|
@@ -12171,7 +12485,7 @@ function useMemberRepo() {
|
|
|
12171
12485
|
throw new BadRequestError5("Invalid ID.");
|
|
12172
12486
|
}
|
|
12173
12487
|
try {
|
|
12174
|
-
const cacheKey =
|
|
12488
|
+
const cacheKey = makeCacheKey3(namespace_collection, {
|
|
12175
12489
|
user: String(user)
|
|
12176
12490
|
});
|
|
12177
12491
|
const cached = await getCache(cacheKey);
|
|
@@ -12183,7 +12497,7 @@ function useMemberRepo() {
|
|
|
12183
12497
|
return cached;
|
|
12184
12498
|
}
|
|
12185
12499
|
const data = await collection.findOne({ user });
|
|
12186
|
-
setCache(cacheKey, data).then(() => {
|
|
12500
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
12187
12501
|
logger3.log({
|
|
12188
12502
|
level: "info",
|
|
12189
12503
|
message: `Cache set for member by user ID: ${cacheKey}`
|
|
@@ -12225,8 +12539,8 @@ function useMemberRepo() {
|
|
|
12225
12539
|
limit = limit > 0 ? limit : 10;
|
|
12226
12540
|
search = search || "";
|
|
12227
12541
|
page = page > 0 ? page - 1 : 0;
|
|
12228
|
-
const query = { type, status
|
|
12229
|
-
const cacheKeyOptions = { type, status };
|
|
12542
|
+
const query = { type, status };
|
|
12543
|
+
const cacheKeyOptions = { type, status, limit, page };
|
|
12230
12544
|
if (user) {
|
|
12231
12545
|
cacheKeyOptions.user = String(user);
|
|
12232
12546
|
try {
|
|
@@ -12247,13 +12561,13 @@ function useMemberRepo() {
|
|
|
12247
12561
|
cacheKeyOptions.search = search;
|
|
12248
12562
|
query.$text = { $search: search };
|
|
12249
12563
|
}
|
|
12250
|
-
const cacheKey =
|
|
12564
|
+
const cacheKey = makeCacheKey3(namespace_collection, cacheKeyOptions);
|
|
12251
12565
|
logger3.log({
|
|
12252
12566
|
level: "info",
|
|
12253
12567
|
message: `Cache key for getAll members: ${cacheKey}`
|
|
12254
12568
|
});
|
|
12255
12569
|
const cached = await getCache(cacheKey);
|
|
12256
|
-
if (cached) {
|
|
12570
|
+
if (cached && cached.items.length) {
|
|
12257
12571
|
logger3.log({
|
|
12258
12572
|
level: "info",
|
|
12259
12573
|
message: `Cache hit for getAll members: ${cacheKey}`
|
|
@@ -12287,7 +12601,7 @@ function useMemberRepo() {
|
|
|
12287
12601
|
]).toArray();
|
|
12288
12602
|
const length = await collection.countDocuments(query);
|
|
12289
12603
|
const data = paginate3(items, page, limit, length);
|
|
12290
|
-
setCache(cacheKey, data).then(() => {
|
|
12604
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
12291
12605
|
logger3.log({
|
|
12292
12606
|
level: "info",
|
|
12293
12607
|
message: `Cache set for getAll members: ${cacheKey}`
|
|
@@ -12312,7 +12626,7 @@ function useMemberRepo() {
|
|
|
12312
12626
|
throw new BadRequestError5("Invalid organization ID.");
|
|
12313
12627
|
}
|
|
12314
12628
|
try {
|
|
12315
|
-
const cacheKey =
|
|
12629
|
+
const cacheKey = makeCacheKey3(namespace_collection, { org: String(org) });
|
|
12316
12630
|
const cached = await getCache(cacheKey);
|
|
12317
12631
|
if (cached) {
|
|
12318
12632
|
logger3.log({
|
|
@@ -12322,7 +12636,7 @@ function useMemberRepo() {
|
|
|
12322
12636
|
return cached;
|
|
12323
12637
|
}
|
|
12324
12638
|
const data = await collection.countDocuments({ org, status: "active" });
|
|
12325
|
-
setCache(cacheKey, data).then(() => {
|
|
12639
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
12326
12640
|
logger3.log({
|
|
12327
12641
|
level: "info",
|
|
12328
12642
|
message: `Cache set for countByOrg members: ${cacheKey}`
|
|
@@ -12347,7 +12661,7 @@ function useMemberRepo() {
|
|
|
12347
12661
|
throw new BadRequestError5("Invalid user ID.");
|
|
12348
12662
|
}
|
|
12349
12663
|
try {
|
|
12350
|
-
const cacheKey =
|
|
12664
|
+
const cacheKey = makeCacheKey3(namespace_collection, {
|
|
12351
12665
|
user: String(user)
|
|
12352
12666
|
});
|
|
12353
12667
|
const cached = await getCache(cacheKey);
|
|
@@ -12359,7 +12673,7 @@ function useMemberRepo() {
|
|
|
12359
12673
|
return cached;
|
|
12360
12674
|
}
|
|
12361
12675
|
const data = await collection.countDocuments({ user, status: "active" });
|
|
12362
|
-
setCache(cacheKey, data).then(() => {
|
|
12676
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
12363
12677
|
logger3.log({
|
|
12364
12678
|
level: "info",
|
|
12365
12679
|
message: `Cache set for countByUser members: ${cacheKey}`
|
|
@@ -12398,7 +12712,7 @@ function useMemberRepo() {
|
|
|
12398
12712
|
query.$text = { $search: search };
|
|
12399
12713
|
}
|
|
12400
12714
|
try {
|
|
12401
|
-
const cacheKey =
|
|
12715
|
+
const cacheKey = makeCacheKey3(namespace_collection, cacheKeyOptions);
|
|
12402
12716
|
const cached = await getCache(
|
|
12403
12717
|
cacheKey
|
|
12404
12718
|
);
|
|
@@ -12429,7 +12743,7 @@ function useMemberRepo() {
|
|
|
12429
12743
|
]).toArray();
|
|
12430
12744
|
const length = await collection.countDocuments(query);
|
|
12431
12745
|
const data = paginate3(items, page, limit, length);
|
|
12432
|
-
setCache(cacheKey, data).then(() => {
|
|
12746
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
12433
12747
|
logger3.log({
|
|
12434
12748
|
level: "info",
|
|
12435
12749
|
message: `Cache set for getOrgsByMembership members: ${cacheKey}`
|
|
@@ -12475,7 +12789,7 @@ function useMemberRepo() {
|
|
|
12475
12789
|
query.$text = { $search: search };
|
|
12476
12790
|
}
|
|
12477
12791
|
try {
|
|
12478
|
-
const cacheKey =
|
|
12792
|
+
const cacheKey = makeCacheKey3(namespace_collection, cacheKeyOptions);
|
|
12479
12793
|
const cached = await getCache(
|
|
12480
12794
|
cacheKey
|
|
12481
12795
|
);
|
|
@@ -12507,7 +12821,7 @@ function useMemberRepo() {
|
|
|
12507
12821
|
]).toArray();
|
|
12508
12822
|
const length = await collection.countDocuments(query);
|
|
12509
12823
|
const data = paginate3(items, page, limit, length);
|
|
12510
|
-
setCache(cacheKey, data).then(() => {
|
|
12824
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
12511
12825
|
logger3.log({
|
|
12512
12826
|
level: "info",
|
|
12513
12827
|
message: `Cache set for getOrgsByUserId members: ${cacheKey}`
|
|
@@ -13072,14 +13386,29 @@ var MToken = class {
|
|
|
13072
13386
|
};
|
|
13073
13387
|
|
|
13074
13388
|
// src/repositories/token.repository.ts
|
|
13075
|
-
import { InternalServerError as InternalServerError6, useAtlas as useAtlas5 } from "@goweekdays/utils";
|
|
13389
|
+
import { InternalServerError as InternalServerError6, logger as logger5, makeCacheKey as makeCacheKey4, useAtlas as useAtlas5, useCache as useCache4 } from "@goweekdays/utils";
|
|
13076
13390
|
import { ObjectId as ObjectId8 } from "mongodb";
|
|
13077
13391
|
function useTokenRepo() {
|
|
13078
13392
|
const db = useAtlas5.getDb();
|
|
13079
13393
|
if (!db) {
|
|
13080
13394
|
throw new InternalServerError6("Unable to connect to server.");
|
|
13081
13395
|
}
|
|
13082
|
-
const
|
|
13396
|
+
const namespace_collection = "tokens";
|
|
13397
|
+
const collection = db.collection(namespace_collection);
|
|
13398
|
+
const { getCache, setCache, delNamespace } = useCache4();
|
|
13399
|
+
function delCachedData() {
|
|
13400
|
+
delNamespace(namespace_collection).then(() => {
|
|
13401
|
+
logger5.log({
|
|
13402
|
+
level: "info",
|
|
13403
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
13404
|
+
});
|
|
13405
|
+
}).catch((err) => {
|
|
13406
|
+
logger5.log({
|
|
13407
|
+
level: "error",
|
|
13408
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
13409
|
+
});
|
|
13410
|
+
});
|
|
13411
|
+
}
|
|
13083
13412
|
async function createToken({ token, user } = {}) {
|
|
13084
13413
|
try {
|
|
13085
13414
|
user = new ObjectId8(user);
|
|
@@ -13088,21 +13417,47 @@ function useTokenRepo() {
|
|
|
13088
13417
|
}
|
|
13089
13418
|
try {
|
|
13090
13419
|
await collection.insertOne({ token, user });
|
|
13420
|
+
delCachedData();
|
|
13091
13421
|
return "Token created";
|
|
13092
13422
|
} catch (error) {
|
|
13093
13423
|
return Promise.reject(error);
|
|
13094
13424
|
}
|
|
13095
13425
|
}
|
|
13096
13426
|
async function getToken(token) {
|
|
13427
|
+
const cacheKey = makeCacheKey4(namespace_collection, { token });
|
|
13097
13428
|
try {
|
|
13098
|
-
|
|
13429
|
+
const cached = await getCache(cacheKey);
|
|
13430
|
+
if (cached) {
|
|
13431
|
+
logger5.log({
|
|
13432
|
+
level: "info",
|
|
13433
|
+
message: `Cache hit for getToken: ${cacheKey}`
|
|
13434
|
+
});
|
|
13435
|
+
return cached;
|
|
13436
|
+
}
|
|
13437
|
+
const data = await collection.findOne({ token });
|
|
13438
|
+
if (data) {
|
|
13439
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
13440
|
+
logger5.log({
|
|
13441
|
+
level: "info",
|
|
13442
|
+
message: `Cache set for token: ${cacheKey}`
|
|
13443
|
+
});
|
|
13444
|
+
}).catch((err) => {
|
|
13445
|
+
logger5.log({
|
|
13446
|
+
level: "error",
|
|
13447
|
+
message: `Failed to set cache for token: ${err.message}`
|
|
13448
|
+
});
|
|
13449
|
+
});
|
|
13450
|
+
}
|
|
13451
|
+
return data;
|
|
13099
13452
|
} catch (error) {
|
|
13100
13453
|
return Promise.reject(error);
|
|
13101
13454
|
}
|
|
13102
13455
|
}
|
|
13103
13456
|
async function deleteToken(token) {
|
|
13104
13457
|
try {
|
|
13105
|
-
|
|
13458
|
+
const result = await collection.deleteOne({ token });
|
|
13459
|
+
delCachedData();
|
|
13460
|
+
return result;
|
|
13106
13461
|
} catch (error) {
|
|
13107
13462
|
return Promise.reject(error);
|
|
13108
13463
|
}
|
|
@@ -13120,10 +13475,10 @@ import {
|
|
|
13120
13475
|
InternalServerError as InternalServerError9,
|
|
13121
13476
|
NotFoundError as NotFoundError2,
|
|
13122
13477
|
hashPassword,
|
|
13123
|
-
logger as
|
|
13124
|
-
makeCacheKey as
|
|
13478
|
+
logger as logger9,
|
|
13479
|
+
makeCacheKey as makeCacheKey7,
|
|
13125
13480
|
useAtlas as useAtlas8,
|
|
13126
|
-
useCache as
|
|
13481
|
+
useCache as useCache7,
|
|
13127
13482
|
useS3
|
|
13128
13483
|
} from "@goweekdays/utils";
|
|
13129
13484
|
|
|
@@ -13131,7 +13486,10 @@ import {
|
|
|
13131
13486
|
import {
|
|
13132
13487
|
BadRequestError as BadRequestError8,
|
|
13133
13488
|
InternalServerError as InternalServerError7,
|
|
13134
|
-
|
|
13489
|
+
logger as logger6,
|
|
13490
|
+
makeCacheKey as makeCacheKey5,
|
|
13491
|
+
useAtlas as useAtlas6,
|
|
13492
|
+
useCache as useCache5
|
|
13135
13493
|
} from "@goweekdays/utils";
|
|
13136
13494
|
|
|
13137
13495
|
// src/models/file.model.ts
|
|
@@ -13152,11 +13510,27 @@ function useFileRepo() {
|
|
|
13152
13510
|
if (!db) {
|
|
13153
13511
|
throw new InternalServerError7("Unable to connect to server.");
|
|
13154
13512
|
}
|
|
13155
|
-
const
|
|
13513
|
+
const namespace_collection = "files";
|
|
13514
|
+
const collection = db.collection(namespace_collection);
|
|
13515
|
+
const { getCache, setCache, delNamespace } = useCache5();
|
|
13516
|
+
function delCachedData() {
|
|
13517
|
+
delNamespace(namespace_collection).then(() => {
|
|
13518
|
+
logger6.log({
|
|
13519
|
+
level: "info",
|
|
13520
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
13521
|
+
});
|
|
13522
|
+
}).catch((err) => {
|
|
13523
|
+
logger6.log({
|
|
13524
|
+
level: "error",
|
|
13525
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
13526
|
+
});
|
|
13527
|
+
});
|
|
13528
|
+
}
|
|
13156
13529
|
async function createFile(value, session) {
|
|
13157
13530
|
try {
|
|
13158
13531
|
value = new MFile(value);
|
|
13159
13532
|
const res = await collection.insertOne(value, { session });
|
|
13533
|
+
delCachedData();
|
|
13160
13534
|
return res.insertedId.toString();
|
|
13161
13535
|
} catch (error) {
|
|
13162
13536
|
throw new InternalServerError7("Failed to create file.");
|
|
@@ -13170,14 +13544,36 @@ function useFileRepo() {
|
|
|
13170
13544
|
}
|
|
13171
13545
|
try {
|
|
13172
13546
|
await collection.deleteOne({ _id }, { session });
|
|
13547
|
+
delCachedData();
|
|
13173
13548
|
return "File deleted successfully";
|
|
13174
13549
|
} catch (error) {
|
|
13175
13550
|
throw new InternalServerError7("Failed to delete file.");
|
|
13176
13551
|
}
|
|
13177
13552
|
}
|
|
13178
13553
|
async function getAllDraftedFiles() {
|
|
13554
|
+
const cacheKey = makeCacheKey5(namespace_collection, { status: "draft" });
|
|
13179
13555
|
try {
|
|
13180
|
-
|
|
13556
|
+
const cached = await getCache(cacheKey);
|
|
13557
|
+
if (cached) {
|
|
13558
|
+
logger6.log({
|
|
13559
|
+
level: "info",
|
|
13560
|
+
message: `Cache hit for getAllDraftedFiles: ${cacheKey}`
|
|
13561
|
+
});
|
|
13562
|
+
return cached;
|
|
13563
|
+
}
|
|
13564
|
+
const data = await collection.find({ $and: [{ status: "draft" }, { status: null }] }).toArray();
|
|
13565
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
13566
|
+
logger6.log({
|
|
13567
|
+
level: "info",
|
|
13568
|
+
message: `Cache set for getAllDraftedFiles: ${cacheKey}`
|
|
13569
|
+
});
|
|
13570
|
+
}).catch((err) => {
|
|
13571
|
+
logger6.log({
|
|
13572
|
+
level: "error",
|
|
13573
|
+
message: `Failed to set cache for getAllDraftedFiles: ${err.message}`
|
|
13574
|
+
});
|
|
13575
|
+
});
|
|
13576
|
+
return data;
|
|
13181
13577
|
} catch (error) {
|
|
13182
13578
|
throw new InternalServerError7("Failed to get drafted files.");
|
|
13183
13579
|
}
|
|
@@ -13697,6 +14093,9 @@ function toFormData(obj, formData, options) {
|
|
|
13697
14093
|
if (utils_default.isDate(value)) {
|
|
13698
14094
|
return value.toISOString();
|
|
13699
14095
|
}
|
|
14096
|
+
if (utils_default.isBoolean(value)) {
|
|
14097
|
+
return value.toString();
|
|
14098
|
+
}
|
|
13700
14099
|
if (!useBlob && utils_default.isBlob(value)) {
|
|
13701
14100
|
throw new AxiosError_default("Blob is not supported. Use a Buffer instead.");
|
|
13702
14101
|
}
|
|
@@ -14483,7 +14882,7 @@ import util2 from "util";
|
|
|
14483
14882
|
import zlib from "zlib";
|
|
14484
14883
|
|
|
14485
14884
|
// node_modules/axios/lib/env/data.js
|
|
14486
|
-
var VERSION = "1.
|
|
14885
|
+
var VERSION = "1.10.0";
|
|
14487
14886
|
|
|
14488
14887
|
// node_modules/axios/lib/helpers/parseProtocol.js
|
|
14489
14888
|
function parseProtocol(url2) {
|
|
@@ -15898,7 +16297,7 @@ var fetch_default = isFetchSupported && (async (config2) => {
|
|
|
15898
16297
|
duplex: "half",
|
|
15899
16298
|
credentials: isCredentialsSupported ? withCredentials : void 0
|
|
15900
16299
|
});
|
|
15901
|
-
let response = await fetch(request);
|
|
16300
|
+
let response = await fetch(request, fetchOptions);
|
|
15902
16301
|
const isStreamResponse = supportsResponseStream && (responseType === "stream" || responseType === "response");
|
|
15903
16302
|
if (supportsResponseStream && (onDownloadProgress || isStreamResponse && unsubscribe)) {
|
|
15904
16303
|
const options = {};
|
|
@@ -16517,7 +16916,7 @@ var {
|
|
|
16517
16916
|
} = axios_default;
|
|
16518
16917
|
|
|
16519
16918
|
// src/services/xendit.service.ts
|
|
16520
|
-
import { AppError as AppError3, BadRequestError as BadRequestError9, logger as
|
|
16919
|
+
import { AppError as AppError3, BadRequestError as BadRequestError9, logger as logger7 } from "@goweekdays/utils";
|
|
16521
16920
|
import { ObjectId as ObjectId11 } from "mongodb";
|
|
16522
16921
|
import Joi3 from "joi";
|
|
16523
16922
|
|
|
@@ -16858,7 +17257,7 @@ function useXenditService() {
|
|
|
16858
17257
|
});
|
|
16859
17258
|
return res.data;
|
|
16860
17259
|
} catch (error) {
|
|
16861
|
-
|
|
17260
|
+
logger7.error(error.response.data.message);
|
|
16862
17261
|
throw new BadRequestError9(error.response.data.message);
|
|
16863
17262
|
}
|
|
16864
17263
|
}
|
|
@@ -17025,7 +17424,7 @@ function useXenditService() {
|
|
|
17025
17424
|
});
|
|
17026
17425
|
return res.data;
|
|
17027
17426
|
} catch (error) {
|
|
17028
|
-
|
|
17427
|
+
logger7.log({
|
|
17029
17428
|
level: "error",
|
|
17030
17429
|
message: `${error}`
|
|
17031
17430
|
});
|
|
@@ -17143,9 +17542,9 @@ import {
|
|
|
17143
17542
|
InternalServerError as InternalServerError8,
|
|
17144
17543
|
useAtlas as useAtlas7,
|
|
17145
17544
|
paginate as paginate4,
|
|
17146
|
-
logger as
|
|
17147
|
-
makeCacheKey as
|
|
17148
|
-
useCache as
|
|
17545
|
+
logger as logger8,
|
|
17546
|
+
makeCacheKey as makeCacheKey6,
|
|
17547
|
+
useCache as useCache6
|
|
17149
17548
|
} from "@goweekdays/utils";
|
|
17150
17549
|
|
|
17151
17550
|
// src/models/role.model.ts
|
|
@@ -17197,15 +17596,15 @@ function useRoleRepo() {
|
|
|
17197
17596
|
}
|
|
17198
17597
|
const namespace_collection = "roles";
|
|
17199
17598
|
const collection = db.collection(namespace_collection);
|
|
17200
|
-
const { getCache, setCache, delNamespace } =
|
|
17599
|
+
const { getCache, setCache, delNamespace } = useCache6();
|
|
17201
17600
|
function delCachedData() {
|
|
17202
17601
|
delNamespace(namespace_collection).then(() => {
|
|
17203
|
-
|
|
17602
|
+
logger8.log({
|
|
17204
17603
|
level: "info",
|
|
17205
17604
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
17206
17605
|
});
|
|
17207
17606
|
}).catch((err) => {
|
|
17208
|
-
|
|
17607
|
+
logger8.log({
|
|
17209
17608
|
level: "error",
|
|
17210
17609
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
17211
17610
|
});
|
|
@@ -17244,7 +17643,7 @@ function useRoleRepo() {
|
|
|
17244
17643
|
delCachedData();
|
|
17245
17644
|
return res.insertedId;
|
|
17246
17645
|
} catch (error) {
|
|
17247
|
-
|
|
17646
|
+
logger8.log({ level: "error", message: `${error}` });
|
|
17248
17647
|
const isDuplicated = error.message.includes("duplicate");
|
|
17249
17648
|
if (isDuplicated) {
|
|
17250
17649
|
throw new BadRequestError10("Role already exists");
|
|
@@ -17259,25 +17658,25 @@ function useRoleRepo() {
|
|
|
17259
17658
|
throw new BadRequestError10("Invalid user ID.");
|
|
17260
17659
|
}
|
|
17261
17660
|
try {
|
|
17262
|
-
const cacheKey =
|
|
17661
|
+
const cacheKey = makeCacheKey6(namespace_collection, {
|
|
17263
17662
|
user: String(value)
|
|
17264
17663
|
});
|
|
17265
17664
|
const cached = await getCache(cacheKey);
|
|
17266
17665
|
if (cached) {
|
|
17267
|
-
|
|
17666
|
+
logger8.log({
|
|
17268
17667
|
level: "info",
|
|
17269
17668
|
message: `Cache hit for getRoleByUserId role: ${cacheKey}`
|
|
17270
17669
|
});
|
|
17271
17670
|
return cached;
|
|
17272
17671
|
}
|
|
17273
17672
|
const data = await collection.findOne({ user: value });
|
|
17274
|
-
setCache(cacheKey, data).then(() => {
|
|
17275
|
-
|
|
17673
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
17674
|
+
logger8.log({
|
|
17276
17675
|
level: "info",
|
|
17277
17676
|
message: `Cache set for role by user ID: ${cacheKey}`
|
|
17278
17677
|
});
|
|
17279
17678
|
}).catch((err) => {
|
|
17280
|
-
|
|
17679
|
+
logger8.log({
|
|
17281
17680
|
level: "error",
|
|
17282
17681
|
message: `Failed to set cache for role by user ID: ${err.message}`
|
|
17283
17682
|
});
|
|
@@ -17294,25 +17693,25 @@ function useRoleRepo() {
|
|
|
17294
17693
|
throw new BadRequestError10("Invalid ID.");
|
|
17295
17694
|
}
|
|
17296
17695
|
try {
|
|
17297
|
-
const cacheKey =
|
|
17696
|
+
const cacheKey = makeCacheKey6(namespace_collection, {
|
|
17298
17697
|
id: _id.toString()
|
|
17299
17698
|
});
|
|
17300
17699
|
const cached = await getCache(cacheKey);
|
|
17301
17700
|
if (cached) {
|
|
17302
|
-
|
|
17701
|
+
logger8.log({
|
|
17303
17702
|
level: "info",
|
|
17304
17703
|
message: `Cache hit for getRoleById role: ${cacheKey}`
|
|
17305
17704
|
});
|
|
17306
17705
|
return cached;
|
|
17307
17706
|
}
|
|
17308
17707
|
const data = await collection.findOne({ _id });
|
|
17309
|
-
setCache(cacheKey, data).then(() => {
|
|
17310
|
-
|
|
17708
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
17709
|
+
logger8.log({
|
|
17311
17710
|
level: "info",
|
|
17312
17711
|
message: `Cache set for role by id: ${cacheKey}`
|
|
17313
17712
|
});
|
|
17314
17713
|
}).catch((err) => {
|
|
17315
|
-
|
|
17714
|
+
logger8.log({
|
|
17316
17715
|
level: "error",
|
|
17317
17716
|
message: `Failed to set cache for role by id: ${err.message}`
|
|
17318
17717
|
});
|
|
@@ -17327,25 +17726,25 @@ function useRoleRepo() {
|
|
|
17327
17726
|
throw new BadRequestError10("Role name is required.");
|
|
17328
17727
|
}
|
|
17329
17728
|
try {
|
|
17330
|
-
const cacheKey =
|
|
17729
|
+
const cacheKey = makeCacheKey6(namespace_collection, {
|
|
17331
17730
|
name
|
|
17332
17731
|
});
|
|
17333
17732
|
const cached = await getCache(cacheKey);
|
|
17334
17733
|
if (cached) {
|
|
17335
|
-
|
|
17734
|
+
logger8.log({
|
|
17336
17735
|
level: "info",
|
|
17337
17736
|
message: `Cache hit for getRoleByName role: ${cacheKey}`
|
|
17338
17737
|
});
|
|
17339
17738
|
return cached;
|
|
17340
17739
|
}
|
|
17341
17740
|
const data = await collection.findOne({ name });
|
|
17342
|
-
setCache(cacheKey, data).then(() => {
|
|
17343
|
-
|
|
17741
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
17742
|
+
logger8.log({
|
|
17344
17743
|
level: "info",
|
|
17345
17744
|
message: `Cache set for role by name: ${cacheKey}`
|
|
17346
17745
|
});
|
|
17347
17746
|
}).catch((err) => {
|
|
17348
|
-
|
|
17747
|
+
logger8.log({
|
|
17349
17748
|
level: "error",
|
|
17350
17749
|
message: `Failed to set cache for role by name: ${err.message}`
|
|
17351
17750
|
});
|
|
@@ -17388,10 +17787,10 @@ function useRoleRepo() {
|
|
|
17388
17787
|
}
|
|
17389
17788
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
17390
17789
|
cacheKeyOptions.sort = JSON.stringify(sort);
|
|
17391
|
-
const cacheKey =
|
|
17790
|
+
const cacheKey = makeCacheKey6(namespace_collection, cacheKeyOptions);
|
|
17392
17791
|
const cached = await getCache(cacheKey);
|
|
17393
17792
|
if (cached) {
|
|
17394
|
-
|
|
17793
|
+
logger8.log({
|
|
17395
17794
|
level: "info",
|
|
17396
17795
|
message: `Cache hit for getRoles: ${cacheKey}`
|
|
17397
17796
|
});
|
|
@@ -17406,20 +17805,20 @@ function useRoleRepo() {
|
|
|
17406
17805
|
]).toArray();
|
|
17407
17806
|
const length = await collection.countDocuments(query);
|
|
17408
17807
|
const data = paginate4(items, page, limit, length);
|
|
17409
|
-
setCache(cacheKey, data).then(() => {
|
|
17410
|
-
|
|
17808
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
17809
|
+
logger8.log({
|
|
17411
17810
|
level: "info",
|
|
17412
17811
|
message: `Cache set for getRoles: ${cacheKey}`
|
|
17413
17812
|
});
|
|
17414
17813
|
}).catch((err) => {
|
|
17415
|
-
|
|
17814
|
+
logger8.log({
|
|
17416
17815
|
level: "error",
|
|
17417
17816
|
message: `Failed to set cache for getRoles: ${err.message}`
|
|
17418
17817
|
});
|
|
17419
17818
|
});
|
|
17420
17819
|
return data;
|
|
17421
17820
|
} catch (error) {
|
|
17422
|
-
|
|
17821
|
+
logger8.log({ level: "error", message: `${error}` });
|
|
17423
17822
|
throw error;
|
|
17424
17823
|
}
|
|
17425
17824
|
}
|
|
@@ -17807,12 +18206,12 @@ function useUserService() {
|
|
|
17807
18206
|
}
|
|
17808
18207
|
const session = useAtlas8.getClient()?.startSession();
|
|
17809
18208
|
session?.startTransaction();
|
|
17810
|
-
const cacheKey =
|
|
18209
|
+
const cacheKey = makeCacheKey7("users", { user: _id });
|
|
17811
18210
|
try {
|
|
17812
|
-
|
|
17813
|
-
|
|
18211
|
+
useCache7().delCache(cacheKey).then(() => {
|
|
18212
|
+
logger9.info(`Cache cleared for user: ${_id}`);
|
|
17814
18213
|
}).catch((error) => {
|
|
17815
|
-
|
|
18214
|
+
logger9.error(`Failed to clear cache for user: ${_id}`, error);
|
|
17816
18215
|
});
|
|
17817
18216
|
await _updateName({ _id, firstName, lastName }, session);
|
|
17818
18217
|
await updateMemberName(
|
|
@@ -18378,7 +18777,7 @@ function useAuthController() {
|
|
|
18378
18777
|
}
|
|
18379
18778
|
|
|
18380
18779
|
// src/services/file.service.ts
|
|
18381
|
-
import { logger as
|
|
18780
|
+
import { logger as logger10, useS3 as useS32, useAtlas as useAtlas9 } from "@goweekdays/utils";
|
|
18382
18781
|
import cron from "node-cron";
|
|
18383
18782
|
function useFileService() {
|
|
18384
18783
|
const {
|
|
@@ -18439,12 +18838,12 @@ function useFileService() {
|
|
|
18439
18838
|
const file = files[index];
|
|
18440
18839
|
try {
|
|
18441
18840
|
await deleteFile(file._id.toString());
|
|
18442
|
-
await
|
|
18841
|
+
await logger10.log({
|
|
18443
18842
|
level: "info",
|
|
18444
18843
|
message: "Successfully deleted draft files."
|
|
18445
18844
|
});
|
|
18446
18845
|
} catch (error) {
|
|
18447
|
-
|
|
18846
|
+
logger10.log({
|
|
18448
18847
|
level: "info",
|
|
18449
18848
|
message: "Successfully deleted draft files."
|
|
18450
18849
|
});
|
|
@@ -18698,16 +19097,33 @@ import { ObjectId as ObjectId16 } from "mongodb";
|
|
|
18698
19097
|
import {
|
|
18699
19098
|
BadRequestError as BadRequestError17,
|
|
18700
19099
|
InternalServerError as InternalServerError15,
|
|
18701
|
-
logger as
|
|
19100
|
+
logger as logger11,
|
|
19101
|
+
makeCacheKey as makeCacheKey8,
|
|
18702
19102
|
paginate as paginate5,
|
|
18703
|
-
useAtlas as useAtlas10
|
|
19103
|
+
useAtlas as useAtlas10,
|
|
19104
|
+
useCache as useCache8
|
|
18704
19105
|
} from "@goweekdays/utils";
|
|
18705
19106
|
function useEntityRepo() {
|
|
18706
19107
|
const db = useAtlas10.getDb();
|
|
18707
19108
|
if (!db) {
|
|
18708
19109
|
throw new InternalServerError15("Unable to connect to server.");
|
|
18709
19110
|
}
|
|
18710
|
-
const
|
|
19111
|
+
const namespace_collection = "entities";
|
|
19112
|
+
const collection = db.collection(namespace_collection);
|
|
19113
|
+
const { getCache, setCache, delNamespace } = useCache8();
|
|
19114
|
+
function delCachedData() {
|
|
19115
|
+
delNamespace(namespace_collection).then(() => {
|
|
19116
|
+
logger11.log({
|
|
19117
|
+
level: "info",
|
|
19118
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
19119
|
+
});
|
|
19120
|
+
}).catch((err) => {
|
|
19121
|
+
logger11.log({
|
|
19122
|
+
level: "error",
|
|
19123
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
19124
|
+
});
|
|
19125
|
+
});
|
|
19126
|
+
}
|
|
18711
19127
|
async function createIndex() {
|
|
18712
19128
|
try {
|
|
18713
19129
|
await collection.createIndex({ name: 1 });
|
|
@@ -18729,9 +19145,10 @@ function useEntityRepo() {
|
|
|
18729
19145
|
const res = await collection.insertOne(value, {
|
|
18730
19146
|
session
|
|
18731
19147
|
});
|
|
19148
|
+
delCachedData();
|
|
18732
19149
|
return res.insertedId.toString();
|
|
18733
19150
|
} catch (error) {
|
|
18734
|
-
|
|
19151
|
+
logger11.log({ level: "error", message: `${error}` });
|
|
18735
19152
|
const isDuplicated = error.message.includes("duplicate");
|
|
18736
19153
|
if (isDuplicated) {
|
|
18737
19154
|
throw new BadRequestError17("Entity name already exists.");
|
|
@@ -18751,7 +19168,22 @@ function useEntityRepo() {
|
|
|
18751
19168
|
if (search) {
|
|
18752
19169
|
query.$text = { $search: search };
|
|
18753
19170
|
}
|
|
19171
|
+
const cacheKey = makeCacheKey8(namespace_collection, {
|
|
19172
|
+
search,
|
|
19173
|
+
page,
|
|
19174
|
+
limit,
|
|
19175
|
+
sort: JSON.stringify(sort),
|
|
19176
|
+
status: "active"
|
|
19177
|
+
});
|
|
18754
19178
|
try {
|
|
19179
|
+
const cached = await getCache(cacheKey);
|
|
19180
|
+
if (cached) {
|
|
19181
|
+
logger11.log({
|
|
19182
|
+
level: "info",
|
|
19183
|
+
message: `Cache hit for getEntities: ${cacheKey}`
|
|
19184
|
+
});
|
|
19185
|
+
return cached;
|
|
19186
|
+
}
|
|
18755
19187
|
const items = await collection.aggregate([
|
|
18756
19188
|
{ $match: query },
|
|
18757
19189
|
{ $sort: sort },
|
|
@@ -18759,9 +19191,21 @@ function useEntityRepo() {
|
|
|
18759
19191
|
{ $limit: limit }
|
|
18760
19192
|
]).toArray();
|
|
18761
19193
|
const length = await collection.countDocuments(query);
|
|
18762
|
-
|
|
19194
|
+
const data = paginate5(items, page, limit, length);
|
|
19195
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
19196
|
+
logger11.log({
|
|
19197
|
+
level: "info",
|
|
19198
|
+
message: `Cache set for getEntities: ${cacheKey}`
|
|
19199
|
+
});
|
|
19200
|
+
}).catch((err) => {
|
|
19201
|
+
logger11.log({
|
|
19202
|
+
level: "error",
|
|
19203
|
+
message: `Failed to set cache for getEntities: ${err.message}`
|
|
19204
|
+
});
|
|
19205
|
+
});
|
|
19206
|
+
return data;
|
|
18763
19207
|
} catch (error) {
|
|
18764
|
-
|
|
19208
|
+
logger11.log({ level: "error", message: `${error}` });
|
|
18765
19209
|
throw error;
|
|
18766
19210
|
}
|
|
18767
19211
|
}
|
|
@@ -18784,6 +19228,7 @@ function useEntityRepo() {
|
|
|
18784
19228
|
// Dynamically set the field
|
|
18785
19229
|
{ session }
|
|
18786
19230
|
);
|
|
19231
|
+
delCachedData();
|
|
18787
19232
|
return `Successfully updated entity ${field}.`;
|
|
18788
19233
|
} catch (error) {
|
|
18789
19234
|
throw new InternalServerError15(`Failed to update entity ${field}.`);
|
|
@@ -18796,10 +19241,12 @@ function useEntityRepo() {
|
|
|
18796
19241
|
throw new BadRequestError17("Invalid entity ID.");
|
|
18797
19242
|
}
|
|
18798
19243
|
try {
|
|
18799
|
-
|
|
19244
|
+
const result = await collection.updateOne(
|
|
18800
19245
|
{ _id },
|
|
18801
19246
|
{ $set: { status: "deleted", deletedAt: (/* @__PURE__ */ new Date()).toISOString() } }
|
|
18802
19247
|
);
|
|
19248
|
+
delCachedData();
|
|
19249
|
+
return result;
|
|
18803
19250
|
} catch (error) {
|
|
18804
19251
|
return Promise.reject(error);
|
|
18805
19252
|
}
|
|
@@ -19012,7 +19459,7 @@ function MSubscription(value) {
|
|
|
19012
19459
|
}
|
|
19013
19460
|
|
|
19014
19461
|
// src/repositories/subscription.repository.ts
|
|
19015
|
-
import { BadRequestError as BadRequestError20, logger as
|
|
19462
|
+
import { BadRequestError as BadRequestError20, logger as logger12, makeCacheKey as makeCacheKey9, paginate as paginate6, useAtlas as useAtlas11, useCache as useCache9 } from "@goweekdays/utils";
|
|
19016
19463
|
import { ObjectId as ObjectId18 } from "mongodb";
|
|
19017
19464
|
import Joi10 from "joi";
|
|
19018
19465
|
function useSubscriptionRepo() {
|
|
@@ -19020,7 +19467,22 @@ function useSubscriptionRepo() {
|
|
|
19020
19467
|
if (!db) {
|
|
19021
19468
|
throw new BadRequestError20("Unable to connect to server.");
|
|
19022
19469
|
}
|
|
19023
|
-
const
|
|
19470
|
+
const namespace_collection = "subscriptions";
|
|
19471
|
+
const collection = db.collection(namespace_collection);
|
|
19472
|
+
const { getCache, setCache, delNamespace } = useCache9();
|
|
19473
|
+
function delCachedData() {
|
|
19474
|
+
delNamespace(namespace_collection).then(() => {
|
|
19475
|
+
logger12.log({
|
|
19476
|
+
level: "info",
|
|
19477
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
19478
|
+
});
|
|
19479
|
+
}).catch((err) => {
|
|
19480
|
+
logger12.log({
|
|
19481
|
+
level: "error",
|
|
19482
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
19483
|
+
});
|
|
19484
|
+
});
|
|
19485
|
+
}
|
|
19024
19486
|
async function createIndex() {
|
|
19025
19487
|
try {
|
|
19026
19488
|
await collection.createIndexes([
|
|
@@ -19051,6 +19513,7 @@ function useSubscriptionRepo() {
|
|
|
19051
19513
|
try {
|
|
19052
19514
|
value = MSubscription(value);
|
|
19053
19515
|
const res = await collection.insertOne(value, { session });
|
|
19516
|
+
delCachedData();
|
|
19054
19517
|
return res.insertedId;
|
|
19055
19518
|
} catch (error) {
|
|
19056
19519
|
throw new BadRequestError20("Failed to create subscription.");
|
|
@@ -19062,8 +19525,31 @@ function useSubscriptionRepo() {
|
|
|
19062
19525
|
} catch (error) {
|
|
19063
19526
|
throw new BadRequestError20("Invalid ID.");
|
|
19064
19527
|
}
|
|
19528
|
+
const cacheKey = makeCacheKey9(namespace_collection, { _id: String(_id) });
|
|
19065
19529
|
try {
|
|
19066
|
-
|
|
19530
|
+
const cached = await getCache(cacheKey);
|
|
19531
|
+
if (cached) {
|
|
19532
|
+
logger12.log({
|
|
19533
|
+
level: "info",
|
|
19534
|
+
message: `Cache hit for getById subscription: ${cacheKey}`
|
|
19535
|
+
});
|
|
19536
|
+
return cached;
|
|
19537
|
+
}
|
|
19538
|
+
const data = await collection.findOne({ _id });
|
|
19539
|
+
if (data) {
|
|
19540
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
19541
|
+
logger12.log({
|
|
19542
|
+
level: "info",
|
|
19543
|
+
message: `Cache set for subscription by ID: ${cacheKey}`
|
|
19544
|
+
});
|
|
19545
|
+
}).catch((err) => {
|
|
19546
|
+
logger12.log({
|
|
19547
|
+
level: "error",
|
|
19548
|
+
message: `Failed to set cache for subscription by ID: ${err.message}`
|
|
19549
|
+
});
|
|
19550
|
+
});
|
|
19551
|
+
}
|
|
19552
|
+
return data;
|
|
19067
19553
|
} catch (error) {
|
|
19068
19554
|
throw new BadRequestError20("Failed to get subscription by ID.");
|
|
19069
19555
|
}
|
|
@@ -19074,8 +19560,31 @@ function useSubscriptionRepo() {
|
|
|
19074
19560
|
} catch (error) {
|
|
19075
19561
|
throw new BadRequestError20("Invalid user ID.");
|
|
19076
19562
|
}
|
|
19563
|
+
const cacheKey = makeCacheKey9(namespace_collection, { user: String(user) });
|
|
19077
19564
|
try {
|
|
19078
|
-
|
|
19565
|
+
const cached = await getCache(cacheKey);
|
|
19566
|
+
if (cached) {
|
|
19567
|
+
logger12.log({
|
|
19568
|
+
level: "info",
|
|
19569
|
+
message: `Cache hit for getByUserId subscription: ${cacheKey}`
|
|
19570
|
+
});
|
|
19571
|
+
return cached;
|
|
19572
|
+
}
|
|
19573
|
+
const data = await collection.findOne({ user });
|
|
19574
|
+
if (data) {
|
|
19575
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
19576
|
+
logger12.log({
|
|
19577
|
+
level: "info",
|
|
19578
|
+
message: `Cache set for subscription by user ID: ${cacheKey}`
|
|
19579
|
+
});
|
|
19580
|
+
}).catch((err) => {
|
|
19581
|
+
logger12.log({
|
|
19582
|
+
level: "error",
|
|
19583
|
+
message: `Failed to set cache for subscription by user ID: ${err.message}`
|
|
19584
|
+
});
|
|
19585
|
+
});
|
|
19586
|
+
}
|
|
19587
|
+
return data;
|
|
19079
19588
|
} catch (error) {
|
|
19080
19589
|
throw new BadRequestError20("Failed to get subscription by ID.");
|
|
19081
19590
|
}
|
|
@@ -19111,8 +19620,31 @@ function useSubscriptionRepo() {
|
|
|
19111
19620
|
}
|
|
19112
19621
|
}
|
|
19113
19622
|
async function getBySubscriptionId(subscriptionId) {
|
|
19623
|
+
const cacheKey = makeCacheKey9(namespace_collection, { subscriptionId });
|
|
19114
19624
|
try {
|
|
19115
|
-
|
|
19625
|
+
const cached = await getCache(cacheKey);
|
|
19626
|
+
if (cached) {
|
|
19627
|
+
logger12.log({
|
|
19628
|
+
level: "info",
|
|
19629
|
+
message: `Cache hit for getBySubscriptionId: ${cacheKey}`
|
|
19630
|
+
});
|
|
19631
|
+
return cached;
|
|
19632
|
+
}
|
|
19633
|
+
const data = await collection.findOne({ subscriptionId });
|
|
19634
|
+
if (data) {
|
|
19635
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
19636
|
+
logger12.log({
|
|
19637
|
+
level: "info",
|
|
19638
|
+
message: `Cache set for subscription by subscription ID: ${cacheKey}`
|
|
19639
|
+
});
|
|
19640
|
+
}).catch((err) => {
|
|
19641
|
+
logger12.log({
|
|
19642
|
+
level: "error",
|
|
19643
|
+
message: `Failed to set cache for subscription by subscription ID: ${err.message}`
|
|
19644
|
+
});
|
|
19645
|
+
});
|
|
19646
|
+
}
|
|
19647
|
+
return data;
|
|
19116
19648
|
} catch (error) {
|
|
19117
19649
|
throw new BadRequestError20(
|
|
19118
19650
|
"Failed to get subscription by subscription ID."
|
|
@@ -19132,7 +19664,22 @@ function useSubscriptionRepo() {
|
|
|
19132
19664
|
if (search) {
|
|
19133
19665
|
query.$text = { $search: search };
|
|
19134
19666
|
}
|
|
19667
|
+
const cacheKey = makeCacheKey9(namespace_collection, {
|
|
19668
|
+
search,
|
|
19669
|
+
page,
|
|
19670
|
+
limit,
|
|
19671
|
+
sort: JSON.stringify(sort),
|
|
19672
|
+
status
|
|
19673
|
+
});
|
|
19135
19674
|
try {
|
|
19675
|
+
const cached = await getCache(cacheKey);
|
|
19676
|
+
if (cached) {
|
|
19677
|
+
logger12.log({
|
|
19678
|
+
level: "info",
|
|
19679
|
+
message: `Cache hit for getSubscriptions: ${cacheKey}`
|
|
19680
|
+
});
|
|
19681
|
+
return cached;
|
|
19682
|
+
}
|
|
19136
19683
|
const items = await collection.aggregate([
|
|
19137
19684
|
{ $match: query },
|
|
19138
19685
|
{ $sort: sort },
|
|
@@ -19140,9 +19687,21 @@ function useSubscriptionRepo() {
|
|
|
19140
19687
|
{ $limit: limit }
|
|
19141
19688
|
]).toArray();
|
|
19142
19689
|
const length = await collection.countDocuments(query);
|
|
19143
|
-
|
|
19690
|
+
const data = paginate6(items, page, limit, length);
|
|
19691
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
19692
|
+
logger12.log({
|
|
19693
|
+
level: "info",
|
|
19694
|
+
message: `Cache set for getSubscriptions: ${cacheKey}`
|
|
19695
|
+
});
|
|
19696
|
+
}).catch((err) => {
|
|
19697
|
+
logger12.log({
|
|
19698
|
+
level: "error",
|
|
19699
|
+
message: `Failed to set cache for getSubscriptions: ${err.message}`
|
|
19700
|
+
});
|
|
19701
|
+
});
|
|
19702
|
+
return data;
|
|
19144
19703
|
} catch (error) {
|
|
19145
|
-
|
|
19704
|
+
logger12.log({ level: "error", message: `${error}` });
|
|
19146
19705
|
throw error;
|
|
19147
19706
|
}
|
|
19148
19707
|
}
|
|
@@ -19289,10 +19848,10 @@ function useSubscriptionRepo() {
|
|
|
19289
19848
|
},
|
|
19290
19849
|
{ session }
|
|
19291
19850
|
);
|
|
19292
|
-
|
|
19851
|
+
logger12.info(`${res.modifiedCount} subscription updated.`);
|
|
19293
19852
|
return "Successfully updated subscription.";
|
|
19294
19853
|
} catch (error2) {
|
|
19295
|
-
|
|
19854
|
+
logger12.error(`${error2}`);
|
|
19296
19855
|
throw new BadRequestError20("Failed to update subscription.");
|
|
19297
19856
|
}
|
|
19298
19857
|
}
|
|
@@ -19541,18 +20100,18 @@ function useSubscriptionRepo() {
|
|
|
19541
20100
|
}
|
|
19542
20101
|
|
|
19543
20102
|
// src/services/subscription.service.ts
|
|
19544
|
-
import { AppError as AppError9, BadRequestError as BadRequestError33, logger as
|
|
20103
|
+
import { AppError as AppError9, BadRequestError as BadRequestError33, logger as logger20, useAtlas as useAtlas19 } from "@goweekdays/utils";
|
|
19545
20104
|
|
|
19546
20105
|
// src/repositories/organization.repository.ts
|
|
19547
20106
|
import {
|
|
19548
20107
|
AppError as AppError8,
|
|
19549
20108
|
BadRequestError as BadRequestError22,
|
|
19550
20109
|
InternalServerError as InternalServerError16,
|
|
19551
|
-
logger as
|
|
19552
|
-
makeCacheKey as
|
|
20110
|
+
logger as logger13,
|
|
20111
|
+
makeCacheKey as makeCacheKey10,
|
|
19553
20112
|
paginate as paginate7,
|
|
19554
20113
|
useAtlas as useAtlas12,
|
|
19555
|
-
useCache as
|
|
20114
|
+
useCache as useCache10
|
|
19556
20115
|
} from "@goweekdays/utils";
|
|
19557
20116
|
|
|
19558
20117
|
// src/models/organization.model.ts
|
|
@@ -19607,7 +20166,7 @@ function useOrgRepo() {
|
|
|
19607
20166
|
}
|
|
19608
20167
|
const namespace_collection = "organizations";
|
|
19609
20168
|
const collection = db.collection(namespace_collection);
|
|
19610
|
-
const { getCache, setCache, delNamespace } =
|
|
20169
|
+
const { getCache, setCache, delNamespace } = useCache10();
|
|
19611
20170
|
async function createIndex() {
|
|
19612
20171
|
try {
|
|
19613
20172
|
await collection.createIndex([
|
|
@@ -19643,12 +20202,12 @@ function useOrgRepo() {
|
|
|
19643
20202
|
}
|
|
19644
20203
|
function delCachedData() {
|
|
19645
20204
|
delNamespace(namespace_collection).then(() => {
|
|
19646
|
-
|
|
20205
|
+
logger13.log({
|
|
19647
20206
|
level: "info",
|
|
19648
20207
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
19649
20208
|
});
|
|
19650
20209
|
}).catch((err) => {
|
|
19651
|
-
|
|
20210
|
+
logger13.log({
|
|
19652
20211
|
level: "error",
|
|
19653
20212
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
19654
20213
|
});
|
|
@@ -19661,7 +20220,7 @@ function useOrgRepo() {
|
|
|
19661
20220
|
delCachedData();
|
|
19662
20221
|
return res.insertedId;
|
|
19663
20222
|
} catch (error) {
|
|
19664
|
-
|
|
20223
|
+
logger13.log({
|
|
19665
20224
|
level: "error",
|
|
19666
20225
|
message: error.message
|
|
19667
20226
|
});
|
|
@@ -19689,21 +20248,21 @@ function useOrgRepo() {
|
|
|
19689
20248
|
if (search) {
|
|
19690
20249
|
query.$text = { $search: search };
|
|
19691
20250
|
}
|
|
19692
|
-
const cacheKey =
|
|
20251
|
+
const cacheKey = makeCacheKey10(namespace_collection, {
|
|
19693
20252
|
search,
|
|
19694
20253
|
page,
|
|
19695
20254
|
limit,
|
|
19696
20255
|
sort: JSON.stringify(sort),
|
|
19697
20256
|
status
|
|
19698
20257
|
});
|
|
19699
|
-
|
|
20258
|
+
logger13.log({
|
|
19700
20259
|
level: "info",
|
|
19701
20260
|
message: `Cache key for getAll organizations: ${cacheKey}`
|
|
19702
20261
|
});
|
|
19703
20262
|
try {
|
|
19704
20263
|
const cached = await getCache(cacheKey);
|
|
19705
20264
|
if (cached) {
|
|
19706
|
-
|
|
20265
|
+
logger13.log({
|
|
19707
20266
|
level: "info",
|
|
19708
20267
|
message: `Cache hit for getAll organizations: ${cacheKey}`
|
|
19709
20268
|
});
|
|
@@ -19726,20 +20285,20 @@ function useOrgRepo() {
|
|
|
19726
20285
|
]).toArray();
|
|
19727
20286
|
const length = await collection.countDocuments(query);
|
|
19728
20287
|
const data = paginate7(items, page, limit, length);
|
|
19729
|
-
setCache(cacheKey, data).then(() => {
|
|
19730
|
-
|
|
20288
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
20289
|
+
logger13.log({
|
|
19731
20290
|
level: "info",
|
|
19732
20291
|
message: `Cache set for getAll organizations: ${cacheKey}`
|
|
19733
20292
|
});
|
|
19734
20293
|
}).catch((err) => {
|
|
19735
|
-
|
|
20294
|
+
logger13.log({
|
|
19736
20295
|
level: "error",
|
|
19737
20296
|
message: `Failed to set cache for getAll organizations: ${err.message}`
|
|
19738
20297
|
});
|
|
19739
20298
|
});
|
|
19740
20299
|
return data;
|
|
19741
20300
|
} catch (error) {
|
|
19742
|
-
|
|
20301
|
+
logger13.log({ level: "error", message: `${error}` });
|
|
19743
20302
|
throw error;
|
|
19744
20303
|
}
|
|
19745
20304
|
}
|
|
@@ -19749,11 +20308,11 @@ function useOrgRepo() {
|
|
|
19749
20308
|
} catch (error) {
|
|
19750
20309
|
throw new BadRequestError22("Invalid ID.");
|
|
19751
20310
|
}
|
|
19752
|
-
const cacheKey =
|
|
20311
|
+
const cacheKey = makeCacheKey10(namespace_collection, { _id: String(_id) });
|
|
19753
20312
|
try {
|
|
19754
20313
|
const cached = await getCache(cacheKey);
|
|
19755
20314
|
if (cached) {
|
|
19756
|
-
|
|
20315
|
+
logger13.log({
|
|
19757
20316
|
level: "info",
|
|
19758
20317
|
message: `Cache hit for getById organization: ${cacheKey}`
|
|
19759
20318
|
});
|
|
@@ -19763,13 +20322,13 @@ function useOrgRepo() {
|
|
|
19763
20322
|
if (!result) {
|
|
19764
20323
|
throw new BadRequestError22("Organization not found.");
|
|
19765
20324
|
}
|
|
19766
|
-
setCache(cacheKey, result).then(() => {
|
|
19767
|
-
|
|
20325
|
+
setCache(cacheKey, result, 300, namespace_collection).then(() => {
|
|
20326
|
+
logger13.log({
|
|
19768
20327
|
level: "info",
|
|
19769
20328
|
message: `Cache set for organization by id: ${cacheKey}`
|
|
19770
20329
|
});
|
|
19771
20330
|
}).catch((err) => {
|
|
19772
|
-
|
|
20331
|
+
logger13.log({
|
|
19773
20332
|
level: "error",
|
|
19774
20333
|
message: `Failed to set cache for organization by id: ${err.message}`
|
|
19775
20334
|
});
|
|
@@ -19784,11 +20343,11 @@ function useOrgRepo() {
|
|
|
19784
20343
|
}
|
|
19785
20344
|
}
|
|
19786
20345
|
async function getByName(name) {
|
|
19787
|
-
const cacheKey =
|
|
20346
|
+
const cacheKey = makeCacheKey10(namespace_collection, { name });
|
|
19788
20347
|
try {
|
|
19789
20348
|
const cached = await getCache(cacheKey);
|
|
19790
20349
|
if (cached) {
|
|
19791
|
-
|
|
20350
|
+
logger13.log({
|
|
19792
20351
|
level: "info",
|
|
19793
20352
|
message: `Cache hit for getByName organization: ${cacheKey}`
|
|
19794
20353
|
});
|
|
@@ -19798,13 +20357,13 @@ function useOrgRepo() {
|
|
|
19798
20357
|
if (!result) {
|
|
19799
20358
|
throw new BadRequestError22("Organization not found.");
|
|
19800
20359
|
}
|
|
19801
|
-
setCache(cacheKey, result).then(() => {
|
|
19802
|
-
|
|
20360
|
+
setCache(cacheKey, result, 300, namespace_collection).then(() => {
|
|
20361
|
+
logger13.log({
|
|
19803
20362
|
level: "info",
|
|
19804
20363
|
message: `Cache set for organization by name: ${cacheKey}`
|
|
19805
20364
|
});
|
|
19806
20365
|
}).catch((err) => {
|
|
19807
|
-
|
|
20366
|
+
logger13.log({
|
|
19808
20367
|
level: "error",
|
|
19809
20368
|
message: `Failed to set cache for organization by name: ${err.message}`
|
|
19810
20369
|
});
|
|
@@ -19874,7 +20433,7 @@ function useOrgRepo() {
|
|
|
19874
20433
|
}
|
|
19875
20434
|
|
|
19876
20435
|
// src/repositories/address.repository.ts
|
|
19877
|
-
import { BadRequestError as BadRequestError24, useAtlas as useAtlas13 } from "@goweekdays/utils";
|
|
20436
|
+
import { BadRequestError as BadRequestError24, useAtlas as useAtlas13, useCache as useCache11, makeCacheKey as makeCacheKey11, logger as logger14 } from "@goweekdays/utils";
|
|
19878
20437
|
|
|
19879
20438
|
// src/models/address.model.ts
|
|
19880
20439
|
import { BadRequestError as BadRequestError23 } from "@goweekdays/utils";
|
|
@@ -19928,7 +20487,22 @@ function useAddressRepo() {
|
|
|
19928
20487
|
if (!db) {
|
|
19929
20488
|
throw new BadRequestError24("Unable to connect to server.");
|
|
19930
20489
|
}
|
|
19931
|
-
const
|
|
20490
|
+
const namespace_collection = "addresses";
|
|
20491
|
+
const collection = db.collection(namespace_collection);
|
|
20492
|
+
const { getCache, setCache, delNamespace } = useCache11();
|
|
20493
|
+
function delCachedData() {
|
|
20494
|
+
delNamespace(namespace_collection).then(() => {
|
|
20495
|
+
logger14.log({
|
|
20496
|
+
level: "info",
|
|
20497
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
20498
|
+
});
|
|
20499
|
+
}).catch((err) => {
|
|
20500
|
+
logger14.log({
|
|
20501
|
+
level: "error",
|
|
20502
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
20503
|
+
});
|
|
20504
|
+
});
|
|
20505
|
+
}
|
|
19932
20506
|
async function createIndex() {
|
|
19933
20507
|
try {
|
|
19934
20508
|
await collection.createIndexes([
|
|
@@ -19944,6 +20518,7 @@ function useAddressRepo() {
|
|
|
19944
20518
|
try {
|
|
19945
20519
|
value = MAddress(value);
|
|
19946
20520
|
const res = await collection.insertOne(value, { session });
|
|
20521
|
+
delCachedData();
|
|
19947
20522
|
return res.insertedId;
|
|
19948
20523
|
} catch (error) {
|
|
19949
20524
|
throw new BadRequestError24("Failed to create address.");
|
|
@@ -19968,6 +20543,7 @@ function useAddressRepo() {
|
|
|
19968
20543
|
{ $set: value },
|
|
19969
20544
|
{ session, upsert: true }
|
|
19970
20545
|
);
|
|
20546
|
+
delCachedData();
|
|
19971
20547
|
return "Successfully updated address.";
|
|
19972
20548
|
} catch (error) {
|
|
19973
20549
|
throw new BadRequestError24("Failed to update address.");
|
|
@@ -19979,8 +20555,31 @@ function useAddressRepo() {
|
|
|
19979
20555
|
} catch (error) {
|
|
19980
20556
|
throw new BadRequestError24("Invalid user ID.");
|
|
19981
20557
|
}
|
|
20558
|
+
const cacheKey = makeCacheKey11(namespace_collection, { user: String(user) });
|
|
19982
20559
|
try {
|
|
19983
|
-
|
|
20560
|
+
const cached = await getCache(cacheKey);
|
|
20561
|
+
if (cached) {
|
|
20562
|
+
logger14.log({
|
|
20563
|
+
level: "info",
|
|
20564
|
+
message: `Cache hit for getByUserId address: ${cacheKey}`
|
|
20565
|
+
});
|
|
20566
|
+
return cached;
|
|
20567
|
+
}
|
|
20568
|
+
const data = await collection.findOne({ user });
|
|
20569
|
+
if (data) {
|
|
20570
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
20571
|
+
logger14.log({
|
|
20572
|
+
level: "info",
|
|
20573
|
+
message: `Cache set for address by user ID: ${cacheKey}`
|
|
20574
|
+
});
|
|
20575
|
+
}).catch((err) => {
|
|
20576
|
+
logger14.log({
|
|
20577
|
+
level: "error",
|
|
20578
|
+
message: `Failed to set cache for address by user ID: ${err.message}`
|
|
20579
|
+
});
|
|
20580
|
+
});
|
|
20581
|
+
}
|
|
20582
|
+
return data;
|
|
19984
20583
|
} catch (error) {
|
|
19985
20584
|
throw new BadRequestError24("Failed to get address by ID.");
|
|
19986
20585
|
}
|
|
@@ -19991,8 +20590,31 @@ function useAddressRepo() {
|
|
|
19991
20590
|
} catch (error) {
|
|
19992
20591
|
throw new BadRequestError24("Invalid orgId.");
|
|
19993
20592
|
}
|
|
20593
|
+
const cacheKey = makeCacheKey11(namespace_collection, { org: String(org) });
|
|
19994
20594
|
try {
|
|
19995
|
-
|
|
20595
|
+
const cached = await getCache(cacheKey);
|
|
20596
|
+
if (cached) {
|
|
20597
|
+
logger14.log({
|
|
20598
|
+
level: "info",
|
|
20599
|
+
message: `Cache hit for getByOrgId address: ${cacheKey}`
|
|
20600
|
+
});
|
|
20601
|
+
return cached;
|
|
20602
|
+
}
|
|
20603
|
+
const data = await collection.findOne({ org });
|
|
20604
|
+
if (data) {
|
|
20605
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
20606
|
+
logger14.log({
|
|
20607
|
+
level: "info",
|
|
20608
|
+
message: `Cache set for address by org ID: ${cacheKey}`
|
|
20609
|
+
});
|
|
20610
|
+
}).catch((err) => {
|
|
20611
|
+
logger14.log({
|
|
20612
|
+
level: "error",
|
|
20613
|
+
message: `Failed to set cache for address by org ID: ${err.message}`
|
|
20614
|
+
});
|
|
20615
|
+
});
|
|
20616
|
+
}
|
|
20617
|
+
return data;
|
|
19996
20618
|
} catch (error) {
|
|
19997
20619
|
throw new BadRequestError24("Failed to get address by orgId.");
|
|
19998
20620
|
}
|
|
@@ -20010,9 +20632,11 @@ function useAddressRepo() {
|
|
|
20010
20632
|
import {
|
|
20011
20633
|
BadRequestError as BadRequestError26,
|
|
20012
20634
|
InternalServerError as InternalServerError17,
|
|
20013
|
-
logger as
|
|
20635
|
+
logger as logger15,
|
|
20636
|
+
makeCacheKey as makeCacheKey12,
|
|
20014
20637
|
paginate as paginate8,
|
|
20015
|
-
useAtlas as useAtlas14
|
|
20638
|
+
useAtlas as useAtlas14,
|
|
20639
|
+
useCache as useCache12
|
|
20016
20640
|
} from "@goweekdays/utils";
|
|
20017
20641
|
|
|
20018
20642
|
// src/validations/promo-code.schema.ts
|
|
@@ -20070,7 +20694,22 @@ function usePromoCodeRepo() {
|
|
|
20070
20694
|
if (!db) {
|
|
20071
20695
|
throw new InternalServerError17("Unable to connect to server.");
|
|
20072
20696
|
}
|
|
20073
|
-
const
|
|
20697
|
+
const namespace_collection = "promo-codes";
|
|
20698
|
+
const collection = db.collection(namespace_collection);
|
|
20699
|
+
const { getCache, setCache, delNamespace } = useCache12();
|
|
20700
|
+
function delCachedData() {
|
|
20701
|
+
delNamespace(namespace_collection).then(() => {
|
|
20702
|
+
logger15.log({
|
|
20703
|
+
level: "info",
|
|
20704
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
20705
|
+
});
|
|
20706
|
+
}).catch((err) => {
|
|
20707
|
+
logger15.log({
|
|
20708
|
+
level: "error",
|
|
20709
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
20710
|
+
});
|
|
20711
|
+
});
|
|
20712
|
+
}
|
|
20074
20713
|
async function createIndex() {
|
|
20075
20714
|
try {
|
|
20076
20715
|
await collection.createIndexes([
|
|
@@ -20096,8 +20735,9 @@ function usePromoCodeRepo() {
|
|
|
20096
20735
|
try {
|
|
20097
20736
|
value = MPromoCode(value);
|
|
20098
20737
|
await collection.insertOne(value);
|
|
20738
|
+
delCachedData();
|
|
20099
20739
|
} catch (error) {
|
|
20100
|
-
|
|
20740
|
+
logger15.log({ level: "error", message: `${error}` });
|
|
20101
20741
|
const isDuplicated = error.message.includes("duplicate");
|
|
20102
20742
|
if (isDuplicated) {
|
|
20103
20743
|
throw new BadRequestError26("Promo code already exists.");
|
|
@@ -20122,8 +20762,31 @@ function usePromoCodeRepo() {
|
|
|
20122
20762
|
} else if (assigned === false) {
|
|
20123
20763
|
query.assignedTo = { $in: [null, ""] };
|
|
20124
20764
|
}
|
|
20765
|
+
const cacheKey = makeCacheKey12(namespace_collection, { code, type: type || "default", assigned: assigned?.toString() || "any" });
|
|
20125
20766
|
try {
|
|
20126
|
-
|
|
20767
|
+
const cached = await getCache(cacheKey);
|
|
20768
|
+
if (cached) {
|
|
20769
|
+
logger15.log({
|
|
20770
|
+
level: "info",
|
|
20771
|
+
message: `Cache hit for getByCode promo code: ${cacheKey}`
|
|
20772
|
+
});
|
|
20773
|
+
return cached;
|
|
20774
|
+
}
|
|
20775
|
+
const data = await collection.findOne(query);
|
|
20776
|
+
if (data) {
|
|
20777
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
20778
|
+
logger15.log({
|
|
20779
|
+
level: "info",
|
|
20780
|
+
message: `Cache set for promo code by code: ${cacheKey}`
|
|
20781
|
+
});
|
|
20782
|
+
}).catch((err) => {
|
|
20783
|
+
logger15.log({
|
|
20784
|
+
level: "error",
|
|
20785
|
+
message: `Failed to set cache for promo code by code: ${err.message}`
|
|
20786
|
+
});
|
|
20787
|
+
});
|
|
20788
|
+
}
|
|
20789
|
+
return data;
|
|
20127
20790
|
} catch (error2) {
|
|
20128
20791
|
throw new InternalServerError17("Internal server error.");
|
|
20129
20792
|
}
|
|
@@ -20141,8 +20804,31 @@ function usePromoCodeRepo() {
|
|
|
20141
20804
|
} catch (error2) {
|
|
20142
20805
|
throw new BadRequestError26("Invalid ID.");
|
|
20143
20806
|
}
|
|
20807
|
+
const cacheKey = makeCacheKey12(namespace_collection, { _id: String(_id) });
|
|
20144
20808
|
try {
|
|
20145
|
-
|
|
20809
|
+
const cached = await getCache(cacheKey);
|
|
20810
|
+
if (cached) {
|
|
20811
|
+
logger15.log({
|
|
20812
|
+
level: "info",
|
|
20813
|
+
message: `Cache hit for getById promo code: ${cacheKey}`
|
|
20814
|
+
});
|
|
20815
|
+
return cached;
|
|
20816
|
+
}
|
|
20817
|
+
const data = await collection.findOne({ _id });
|
|
20818
|
+
if (data) {
|
|
20819
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
20820
|
+
logger15.log({
|
|
20821
|
+
level: "info",
|
|
20822
|
+
message: `Cache set for promo code by ID: ${cacheKey}`
|
|
20823
|
+
});
|
|
20824
|
+
}).catch((err) => {
|
|
20825
|
+
logger15.log({
|
|
20826
|
+
level: "error",
|
|
20827
|
+
message: `Failed to set cache for promo code by ID: ${err.message}`
|
|
20828
|
+
});
|
|
20829
|
+
});
|
|
20830
|
+
}
|
|
20831
|
+
return data;
|
|
20146
20832
|
} catch (error2) {
|
|
20147
20833
|
throw new InternalServerError17("Internal server error.");
|
|
20148
20834
|
}
|
|
@@ -20164,7 +20850,23 @@ function usePromoCodeRepo() {
|
|
|
20164
20850
|
if (type) {
|
|
20165
20851
|
query.type = type;
|
|
20166
20852
|
}
|
|
20853
|
+
const cacheKey = makeCacheKey12(namespace_collection, {
|
|
20854
|
+
search,
|
|
20855
|
+
page,
|
|
20856
|
+
limit,
|
|
20857
|
+
sort: JSON.stringify(sort),
|
|
20858
|
+
status,
|
|
20859
|
+
type
|
|
20860
|
+
});
|
|
20167
20861
|
try {
|
|
20862
|
+
const cached = await getCache(cacheKey);
|
|
20863
|
+
if (cached) {
|
|
20864
|
+
logger15.log({
|
|
20865
|
+
level: "info",
|
|
20866
|
+
message: `Cache hit for getPromoCodes: ${cacheKey}`
|
|
20867
|
+
});
|
|
20868
|
+
return cached;
|
|
20869
|
+
}
|
|
20168
20870
|
const items = await collection.aggregate([
|
|
20169
20871
|
{ $match: query },
|
|
20170
20872
|
{ $sort: sort },
|
|
@@ -20172,9 +20874,21 @@ function usePromoCodeRepo() {
|
|
|
20172
20874
|
{ $limit: limit }
|
|
20173
20875
|
]).toArray();
|
|
20174
20876
|
const length = await collection.countDocuments(query);
|
|
20175
|
-
|
|
20877
|
+
const data = paginate8(items, page, limit, length);
|
|
20878
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
20879
|
+
logger15.log({
|
|
20880
|
+
level: "info",
|
|
20881
|
+
message: `Cache set for getPromoCodes: ${cacheKey}`
|
|
20882
|
+
});
|
|
20883
|
+
}).catch((err) => {
|
|
20884
|
+
logger15.log({
|
|
20885
|
+
level: "error",
|
|
20886
|
+
message: `Failed to set cache for getPromoCodes: ${err.message}`
|
|
20887
|
+
});
|
|
20888
|
+
});
|
|
20889
|
+
return data;
|
|
20176
20890
|
} catch (error) {
|
|
20177
|
-
|
|
20891
|
+
logger15.log({ level: "error", message: `${error}` });
|
|
20178
20892
|
throw new InternalServerError17("Internal server error.");
|
|
20179
20893
|
}
|
|
20180
20894
|
}
|
|
@@ -20198,6 +20912,7 @@ function usePromoCodeRepo() {
|
|
|
20198
20912
|
{ $set: { assignedTo: user } },
|
|
20199
20913
|
{ session }
|
|
20200
20914
|
);
|
|
20915
|
+
delCachedData();
|
|
20201
20916
|
} catch (error2) {
|
|
20202
20917
|
throw new InternalServerError17("Internal server error.");
|
|
20203
20918
|
}
|
|
@@ -20220,7 +20935,7 @@ import Joi15 from "joi";
|
|
|
20220
20935
|
import {
|
|
20221
20936
|
BadRequestError as BadRequestError28,
|
|
20222
20937
|
InternalServerError as InternalServerError18,
|
|
20223
|
-
logger as
|
|
20938
|
+
logger as logger16,
|
|
20224
20939
|
paginate as paginate9,
|
|
20225
20940
|
useAtlas as useAtlas15
|
|
20226
20941
|
} from "@goweekdays/utils";
|
|
@@ -20355,7 +21070,7 @@ function useInvoiceRepo() {
|
|
|
20355
21070
|
value = createInvoice(value);
|
|
20356
21071
|
await collection.insertOne(value, { session });
|
|
20357
21072
|
} catch (error) {
|
|
20358
|
-
|
|
21073
|
+
logger16.log({ level: "error", message: `${error}` });
|
|
20359
21074
|
const isDuplicated = error.message.includes("duplicate");
|
|
20360
21075
|
if (isDuplicated) {
|
|
20361
21076
|
throw new BadRequestError28("Invoice already exists.");
|
|
@@ -20488,7 +21203,7 @@ function useInvoiceRepo() {
|
|
|
20488
21203
|
}
|
|
20489
21204
|
|
|
20490
21205
|
// src/repositories/counter.repository.ts
|
|
20491
|
-
import { useAtlas as useAtlas16 } from "@goweekdays/utils";
|
|
21206
|
+
import { useAtlas as useAtlas16, useCache as useCache13, makeCacheKey as makeCacheKey13, logger as logger17 } from "@goweekdays/utils";
|
|
20492
21207
|
|
|
20493
21208
|
// src/models/counter.model.ts
|
|
20494
21209
|
import { BadRequestError as BadRequestError29 } from "@goweekdays/utils";
|
|
@@ -20530,7 +21245,22 @@ function useCounterRepo() {
|
|
|
20530
21245
|
if (!db) {
|
|
20531
21246
|
throw new Error("Unable to connect to server.");
|
|
20532
21247
|
}
|
|
21248
|
+
const namespace_collection = "counters";
|
|
20533
21249
|
const { collection, createCounter } = useCounterModel(db);
|
|
21250
|
+
const { getCache, setCache, delNamespace } = useCache13();
|
|
21251
|
+
function delCachedData() {
|
|
21252
|
+
delNamespace(namespace_collection).then(() => {
|
|
21253
|
+
logger17.log({
|
|
21254
|
+
level: "info",
|
|
21255
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
21256
|
+
});
|
|
21257
|
+
}).catch((err) => {
|
|
21258
|
+
logger17.log({
|
|
21259
|
+
level: "error",
|
|
21260
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
21261
|
+
});
|
|
21262
|
+
});
|
|
21263
|
+
}
|
|
20534
21264
|
async function createIndex() {
|
|
20535
21265
|
try {
|
|
20536
21266
|
await collection.createIndexes([
|
|
@@ -20559,6 +21289,7 @@ function useCounterRepo() {
|
|
|
20559
21289
|
try {
|
|
20560
21290
|
const value = createCounter({ type });
|
|
20561
21291
|
await collection.insertOne(value);
|
|
21292
|
+
delCachedData();
|
|
20562
21293
|
} catch (error) {
|
|
20563
21294
|
throw new Error("Failed to add counter.");
|
|
20564
21295
|
}
|
|
@@ -20570,13 +21301,37 @@ function useCounterRepo() {
|
|
|
20570
21301
|
{ $inc: { count: 1 } },
|
|
20571
21302
|
{ session }
|
|
20572
21303
|
);
|
|
21304
|
+
delCachedData();
|
|
20573
21305
|
} catch (error) {
|
|
20574
21306
|
throw new Error(`Failed to increment ${type} counter.`);
|
|
20575
21307
|
}
|
|
20576
21308
|
}
|
|
20577
21309
|
async function getByType(type) {
|
|
21310
|
+
const cacheKey = makeCacheKey13(namespace_collection, { type });
|
|
20578
21311
|
try {
|
|
20579
|
-
|
|
21312
|
+
const cached = await getCache(cacheKey);
|
|
21313
|
+
if (cached) {
|
|
21314
|
+
logger17.log({
|
|
21315
|
+
level: "info",
|
|
21316
|
+
message: `Cache hit for getByType counter: ${cacheKey}`
|
|
21317
|
+
});
|
|
21318
|
+
return cached;
|
|
21319
|
+
}
|
|
21320
|
+
const data = await collection.findOne({ type });
|
|
21321
|
+
if (data) {
|
|
21322
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
21323
|
+
logger17.log({
|
|
21324
|
+
level: "info",
|
|
21325
|
+
message: `Cache set for counter by type: ${cacheKey}`
|
|
21326
|
+
});
|
|
21327
|
+
}).catch((err) => {
|
|
21328
|
+
logger17.log({
|
|
21329
|
+
level: "error",
|
|
21330
|
+
message: `Failed to set cache for counter by type: ${err.message}`
|
|
21331
|
+
});
|
|
21332
|
+
});
|
|
21333
|
+
}
|
|
21334
|
+
return data;
|
|
20580
21335
|
} catch (error) {
|
|
20581
21336
|
throw new Error("Failed to get counter.");
|
|
20582
21337
|
}
|
|
@@ -20594,7 +21349,7 @@ function useCounterRepo() {
|
|
|
20594
21349
|
import {
|
|
20595
21350
|
BadRequestError as BadRequestError30,
|
|
20596
21351
|
InternalServerError as InternalServerError19,
|
|
20597
|
-
logger as
|
|
21352
|
+
logger as logger18,
|
|
20598
21353
|
paginate as paginate10,
|
|
20599
21354
|
useAtlas as useAtlas17
|
|
20600
21355
|
} from "@goweekdays/utils";
|
|
@@ -20639,7 +21394,7 @@ function usePaymentRepo() {
|
|
|
20639
21394
|
value = createPayment(value);
|
|
20640
21395
|
await collection.insertOne(value, { session });
|
|
20641
21396
|
} catch (error) {
|
|
20642
|
-
|
|
21397
|
+
logger18.log({ level: "error", message: `${error}` });
|
|
20643
21398
|
const isDuplicated = error.message.includes("duplicate");
|
|
20644
21399
|
if (isDuplicated) {
|
|
20645
21400
|
throw new BadRequestError30("Payment already exists.");
|
|
@@ -20684,7 +21439,7 @@ function usePaymentRepo() {
|
|
|
20684
21439
|
const length = await collection.countDocuments(query);
|
|
20685
21440
|
return paginate10(items, page, limit, length);
|
|
20686
21441
|
} catch (error) {
|
|
20687
|
-
|
|
21442
|
+
logger18.log({ level: "error", message: `${error}` });
|
|
20688
21443
|
throw new InternalServerError19("Internal server error.");
|
|
20689
21444
|
}
|
|
20690
21445
|
}
|
|
@@ -20710,7 +21465,7 @@ function usePaymentRepo() {
|
|
|
20710
21465
|
}
|
|
20711
21466
|
|
|
20712
21467
|
// src/repositories/price.repository.ts
|
|
20713
|
-
import { useAtlas as useAtlas18 } from "@goweekdays/utils";
|
|
21468
|
+
import { useAtlas as useAtlas18, useCache as useCache14, makeCacheKey as makeCacheKey14, logger as logger19 } from "@goweekdays/utils";
|
|
20714
21469
|
|
|
20715
21470
|
// src/models/price.model.ts
|
|
20716
21471
|
import { BadRequestError as BadRequestError31 } from "@goweekdays/utils";
|
|
@@ -20761,7 +21516,22 @@ function usePriceRepo() {
|
|
|
20761
21516
|
if (!db) {
|
|
20762
21517
|
throw new Error("Unable to connect to server.");
|
|
20763
21518
|
}
|
|
21519
|
+
const namespace_collection = "prices";
|
|
20764
21520
|
const { collection, createPrice } = usePriceModel(db);
|
|
21521
|
+
const { getCache, setCache, delNamespace } = useCache14();
|
|
21522
|
+
function delCachedData() {
|
|
21523
|
+
delNamespace(namespace_collection).then(() => {
|
|
21524
|
+
logger19.log({
|
|
21525
|
+
level: "info",
|
|
21526
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
21527
|
+
});
|
|
21528
|
+
}).catch((err) => {
|
|
21529
|
+
logger19.log({
|
|
21530
|
+
level: "error",
|
|
21531
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
21532
|
+
});
|
|
21533
|
+
});
|
|
21534
|
+
}
|
|
20765
21535
|
async function createIndex() {
|
|
20766
21536
|
try {
|
|
20767
21537
|
await collection.createIndexes([
|
|
@@ -20790,6 +21560,7 @@ function usePriceRepo() {
|
|
|
20790
21560
|
try {
|
|
20791
21561
|
value = createPrice(value);
|
|
20792
21562
|
await collection.insertOne(value);
|
|
21563
|
+
delCachedData();
|
|
20793
21564
|
} catch (error) {
|
|
20794
21565
|
throw new Error("Failed to add price.");
|
|
20795
21566
|
}
|
|
@@ -20801,13 +21572,37 @@ function usePriceRepo() {
|
|
|
20801
21572
|
{ $set: { saleValue: value.saleValue, saleExpiry: value.saleExpiry } },
|
|
20802
21573
|
{ session }
|
|
20803
21574
|
);
|
|
21575
|
+
delCachedData();
|
|
20804
21576
|
} catch (error) {
|
|
20805
21577
|
throw new Error(`Failed to set ${value.type} sale price.`);
|
|
20806
21578
|
}
|
|
20807
21579
|
}
|
|
20808
21580
|
async function getByNameType(name, type) {
|
|
21581
|
+
const cacheKey = makeCacheKey14(namespace_collection, { name, type });
|
|
20809
21582
|
try {
|
|
20810
|
-
|
|
21583
|
+
const cached = await getCache(cacheKey);
|
|
21584
|
+
if (cached) {
|
|
21585
|
+
logger19.log({
|
|
21586
|
+
level: "info",
|
|
21587
|
+
message: `Cache hit for getByNameType price: ${cacheKey}`
|
|
21588
|
+
});
|
|
21589
|
+
return cached;
|
|
21590
|
+
}
|
|
21591
|
+
const data = await collection.findOne({ name, type });
|
|
21592
|
+
if (data) {
|
|
21593
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
21594
|
+
logger19.log({
|
|
21595
|
+
level: "info",
|
|
21596
|
+
message: `Cache set for price by name and type: ${cacheKey}`
|
|
21597
|
+
});
|
|
21598
|
+
}).catch((err) => {
|
|
21599
|
+
logger19.log({
|
|
21600
|
+
level: "error",
|
|
21601
|
+
message: `Failed to set cache for price by name and type: ${err.message}`
|
|
21602
|
+
});
|
|
21603
|
+
});
|
|
21604
|
+
}
|
|
21605
|
+
return data;
|
|
20811
21606
|
} catch (error) {
|
|
20812
21607
|
throw new Error("Failed to get price.");
|
|
20813
21608
|
}
|
|
@@ -20976,6 +21771,7 @@ function usePaypalService() {
|
|
|
20976
21771
|
}
|
|
20977
21772
|
|
|
20978
21773
|
// src/services/subscription.service.ts
|
|
21774
|
+
import { useJournalTypeRepo, useLedgerTypeRepo } from "@goweekdays/finance";
|
|
20979
21775
|
function useSubscriptionService() {
|
|
20980
21776
|
const {
|
|
20981
21777
|
getByUserId: _getByUserId,
|
|
@@ -20983,7 +21779,6 @@ function useSubscriptionService() {
|
|
|
20983
21779
|
getByOrgId: _getByOrgId,
|
|
20984
21780
|
getDueSubscriptions,
|
|
20985
21781
|
processSuccessfulPayment,
|
|
20986
|
-
markSubscriptionAsFailed,
|
|
20987
21782
|
updateSeatsById: _updateSeatsById,
|
|
20988
21783
|
getById: _getById,
|
|
20989
21784
|
updateMaxSeatsById,
|
|
@@ -21042,6 +21837,8 @@ function useSubscriptionService() {
|
|
|
21042
21837
|
nonProratedCost: formatAmount(nonProratedCost)
|
|
21043
21838
|
};
|
|
21044
21839
|
}
|
|
21840
|
+
const { add: addLedgerType } = useLedgerTypeRepo();
|
|
21841
|
+
const { add: addJournalType } = useJournalTypeRepo();
|
|
21045
21842
|
async function subscribe(value) {
|
|
21046
21843
|
const session = useAtlas19.getClient()?.startSession();
|
|
21047
21844
|
session?.startTransaction();
|
|
@@ -21084,6 +21881,14 @@ function useSubscriptionService() {
|
|
|
21084
21881
|
session
|
|
21085
21882
|
);
|
|
21086
21883
|
}
|
|
21884
|
+
await addJournalType(
|
|
21885
|
+
{ name: "General Journal", orgId, default: true },
|
|
21886
|
+
session
|
|
21887
|
+
);
|
|
21888
|
+
await addLedgerType(
|
|
21889
|
+
{ name: "General Ledger", orgId, default: true },
|
|
21890
|
+
session
|
|
21891
|
+
);
|
|
21087
21892
|
const description = "GoWeekdays Organization Monthly Subscription.";
|
|
21088
21893
|
const monthlySubscriptionPrice = await getByNameType(
|
|
21089
21894
|
"organization-subscription",
|
|
@@ -21574,7 +22379,7 @@ function useSubscriptionService() {
|
|
|
21574
22379
|
while (true) {
|
|
21575
22380
|
const subscriptions = await getDueSubscriptions(batchSize);
|
|
21576
22381
|
if (subscriptions.length === 0) {
|
|
21577
|
-
|
|
22382
|
+
logger20.log({
|
|
21578
22383
|
level: "info",
|
|
21579
22384
|
message: "No more subscriptions to process."
|
|
21580
22385
|
});
|
|
@@ -21714,14 +22519,14 @@ function useSubscriptionService() {
|
|
|
21714
22519
|
);
|
|
21715
22520
|
await session?.commitTransaction();
|
|
21716
22521
|
}
|
|
21717
|
-
|
|
22522
|
+
logger20.log({
|
|
21718
22523
|
level: "info",
|
|
21719
22524
|
message: `Processed subscription ${sub._id} successfully.`
|
|
21720
22525
|
});
|
|
21721
22526
|
return;
|
|
21722
22527
|
} catch (error) {
|
|
21723
22528
|
await session?.abortTransaction();
|
|
21724
|
-
|
|
22529
|
+
logger20.log({
|
|
21725
22530
|
level: "error",
|
|
21726
22531
|
message: `Failed to process ${sub._id}: ${error}`
|
|
21727
22532
|
});
|
|
@@ -21733,7 +22538,7 @@ function useSubscriptionService() {
|
|
|
21733
22538
|
}
|
|
21734
22539
|
})
|
|
21735
22540
|
);
|
|
21736
|
-
|
|
22541
|
+
logger20.log({
|
|
21737
22542
|
level: "info",
|
|
21738
22543
|
message: "Processed a batch of subscriptions."
|
|
21739
22544
|
});
|
|
@@ -22030,7 +22835,7 @@ function useSubscriptionService() {
|
|
|
22030
22835
|
await session?.commitTransaction();
|
|
22031
22836
|
} catch (error2) {
|
|
22032
22837
|
await session?.abortTransaction();
|
|
22033
|
-
|
|
22838
|
+
logger20.log({
|
|
22034
22839
|
level: "error",
|
|
22035
22840
|
message: `Failed to update subscription seats: ${error2}`
|
|
22036
22841
|
});
|
|
@@ -22231,7 +23036,7 @@ function useSubscriptionService() {
|
|
|
22231
23036
|
await session?.commitTransaction();
|
|
22232
23037
|
} catch (error2) {
|
|
22233
23038
|
await session?.abortTransaction();
|
|
22234
|
-
|
|
23039
|
+
logger20.log({
|
|
22235
23040
|
level: "error",
|
|
22236
23041
|
message: `Failed to update subscription seats: ${error2}`
|
|
22237
23042
|
});
|
|
@@ -22332,7 +23137,7 @@ function useSubscriptionService() {
|
|
|
22332
23137
|
await session?.commitTransaction();
|
|
22333
23138
|
} catch (error) {
|
|
22334
23139
|
await session?.abortTransaction();
|
|
22335
|
-
|
|
23140
|
+
logger20.log({
|
|
22336
23141
|
level: "error",
|
|
22337
23142
|
message: `Failed to process subscription payment: ${error}`
|
|
22338
23143
|
});
|
|
@@ -22835,7 +23640,7 @@ function MPaymentMethod(value) {
|
|
|
22835
23640
|
import {
|
|
22836
23641
|
BadRequestError as BadRequestError36,
|
|
22837
23642
|
InternalServerError as InternalServerError20,
|
|
22838
|
-
logger as
|
|
23643
|
+
logger as logger21,
|
|
22839
23644
|
useAtlas as useAtlas20
|
|
22840
23645
|
} from "@goweekdays/utils";
|
|
22841
23646
|
import { ObjectId as ObjectId30 } from "mongodb";
|
|
@@ -22881,7 +23686,7 @@ function usePaymentMethodRepo() {
|
|
|
22881
23686
|
await collection.insertOne(value, { session });
|
|
22882
23687
|
return "Successfully added payment method.";
|
|
22883
23688
|
} catch (error) {
|
|
22884
|
-
|
|
23689
|
+
logger21.log({ level: "error", message: `${error}` });
|
|
22885
23690
|
const isDuplicated = error.message.includes("duplicate");
|
|
22886
23691
|
if (isDuplicated) {
|
|
22887
23692
|
throw new BadRequestError36("Payment method already exist.");
|
|
@@ -24027,9 +24832,11 @@ import {
|
|
|
24027
24832
|
AppError as AppError11,
|
|
24028
24833
|
BadRequestError as BadRequestError44,
|
|
24029
24834
|
InternalServerError as InternalServerError22,
|
|
24030
|
-
logger as
|
|
24835
|
+
logger as logger22,
|
|
24836
|
+
makeCacheKey as makeCacheKey15,
|
|
24031
24837
|
paginate as paginate11,
|
|
24032
|
-
useAtlas as useAtlas23
|
|
24838
|
+
useAtlas as useAtlas23,
|
|
24839
|
+
useCache as useCache15
|
|
24033
24840
|
} from "@goweekdays/utils";
|
|
24034
24841
|
import { ObjectId as ObjectId32 } from "mongodb";
|
|
24035
24842
|
function useOrderRepo() {
|
|
@@ -24037,7 +24844,22 @@ function useOrderRepo() {
|
|
|
24037
24844
|
if (!db) {
|
|
24038
24845
|
throw new InternalServerError22("Unable to connect to server.");
|
|
24039
24846
|
}
|
|
24040
|
-
const
|
|
24847
|
+
const namespace_collection = "orders";
|
|
24848
|
+
const collection = db.collection(namespace_collection);
|
|
24849
|
+
const { getCache, setCache, delNamespace } = useCache15();
|
|
24850
|
+
function delCachedData() {
|
|
24851
|
+
delNamespace(namespace_collection).then(() => {
|
|
24852
|
+
logger22.log({
|
|
24853
|
+
level: "info",
|
|
24854
|
+
message: `Cache namespace cleared for ${namespace_collection}`
|
|
24855
|
+
});
|
|
24856
|
+
}).catch((err) => {
|
|
24857
|
+
logger22.log({
|
|
24858
|
+
level: "error",
|
|
24859
|
+
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
24860
|
+
});
|
|
24861
|
+
});
|
|
24862
|
+
}
|
|
24041
24863
|
function createIndex() {
|
|
24042
24864
|
try {
|
|
24043
24865
|
collection.createIndexes([
|
|
@@ -24053,8 +24875,9 @@ function useOrderRepo() {
|
|
|
24053
24875
|
try {
|
|
24054
24876
|
value = MOrder(value);
|
|
24055
24877
|
collection.insertOne(value, { session });
|
|
24878
|
+
delCachedData();
|
|
24056
24879
|
} catch (error) {
|
|
24057
|
-
|
|
24880
|
+
logger22.log({ level: "error", message: `${error}` });
|
|
24058
24881
|
if (error instanceof AppError11) {
|
|
24059
24882
|
throw error;
|
|
24060
24883
|
}
|
|
@@ -24086,7 +24909,24 @@ function useOrderRepo() {
|
|
|
24086
24909
|
throw new BadRequestError44("Invalid subscription ID.");
|
|
24087
24910
|
}
|
|
24088
24911
|
}
|
|
24912
|
+
const cacheKey = makeCacheKey15(namespace_collection, {
|
|
24913
|
+
search,
|
|
24914
|
+
page,
|
|
24915
|
+
limit,
|
|
24916
|
+
sort: JSON.stringify(sort),
|
|
24917
|
+
status,
|
|
24918
|
+
type,
|
|
24919
|
+
id
|
|
24920
|
+
});
|
|
24089
24921
|
try {
|
|
24922
|
+
const cached = await getCache(cacheKey);
|
|
24923
|
+
if (cached) {
|
|
24924
|
+
logger22.log({
|
|
24925
|
+
level: "info",
|
|
24926
|
+
message: `Cache hit for getOrders: ${cacheKey}`
|
|
24927
|
+
});
|
|
24928
|
+
return cached;
|
|
24929
|
+
}
|
|
24090
24930
|
const items = await collection.aggregate([
|
|
24091
24931
|
{ $match: query },
|
|
24092
24932
|
{ $sort: sort },
|
|
@@ -24094,9 +24934,21 @@ function useOrderRepo() {
|
|
|
24094
24934
|
{ $limit: limit }
|
|
24095
24935
|
]).toArray();
|
|
24096
24936
|
const length = await collection.countDocuments(query);
|
|
24097
|
-
|
|
24937
|
+
const data = paginate11(items, page, limit, length);
|
|
24938
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
24939
|
+
logger22.log({
|
|
24940
|
+
level: "info",
|
|
24941
|
+
message: `Cache set for getOrders: ${cacheKey}`
|
|
24942
|
+
});
|
|
24943
|
+
}).catch((err) => {
|
|
24944
|
+
logger22.log({
|
|
24945
|
+
level: "error",
|
|
24946
|
+
message: `Failed to set cache for getOrders: ${err.message}`
|
|
24947
|
+
});
|
|
24948
|
+
});
|
|
24949
|
+
return data;
|
|
24098
24950
|
} catch (error) {
|
|
24099
|
-
|
|
24951
|
+
logger22.log({ level: "error", message: `${error}` });
|
|
24100
24952
|
throw new InternalServerError22("Internal server error.");
|
|
24101
24953
|
}
|
|
24102
24954
|
}
|
|
@@ -24152,7 +25004,7 @@ function useOrderController() {
|
|
|
24152
25004
|
// src/services/invoice.service.ts
|
|
24153
25005
|
import {
|
|
24154
25006
|
BadRequestError as BadRequestError46,
|
|
24155
|
-
logger as
|
|
25007
|
+
logger as logger23,
|
|
24156
25008
|
NotFoundError as NotFoundError7,
|
|
24157
25009
|
useAtlas as useAtlas24
|
|
24158
25010
|
} from "@goweekdays/utils";
|
|
@@ -24174,7 +25026,7 @@ function useInvoiceService() {
|
|
|
24174
25026
|
while (true) {
|
|
24175
25027
|
const overdueInvoices = await getOverdueInvoices(BATCH_SIZE);
|
|
24176
25028
|
if (!overdueInvoices.length) {
|
|
24177
|
-
|
|
25029
|
+
logger23.log({
|
|
24178
25030
|
level: "info",
|
|
24179
25031
|
message: "No overdue invoices found."
|
|
24180
25032
|
});
|
|
@@ -24184,21 +25036,21 @@ function useInvoiceService() {
|
|
|
24184
25036
|
overdueInvoices.map(async (invoice) => {
|
|
24185
25037
|
const session = useAtlas24.getClient()?.startSession();
|
|
24186
25038
|
if (!session) {
|
|
24187
|
-
|
|
25039
|
+
logger23.log({
|
|
24188
25040
|
level: "error",
|
|
24189
25041
|
message: "Failed to start session."
|
|
24190
25042
|
});
|
|
24191
25043
|
return;
|
|
24192
25044
|
}
|
|
24193
25045
|
if (!invoice._id) {
|
|
24194
|
-
|
|
25046
|
+
logger23.log({
|
|
24195
25047
|
level: "error",
|
|
24196
25048
|
message: "Invoice ID is missing."
|
|
24197
25049
|
});
|
|
24198
25050
|
return;
|
|
24199
25051
|
}
|
|
24200
25052
|
if (!invoice.metadata?.subscriptionId) {
|
|
24201
|
-
|
|
25053
|
+
logger23.log({
|
|
24202
25054
|
level: "error",
|
|
24203
25055
|
message: "Subscription ID is missing."
|
|
24204
25056
|
});
|
|
@@ -24208,14 +25060,14 @@ function useInvoiceService() {
|
|
|
24208
25060
|
invoice.metadata.subscriptionId
|
|
24209
25061
|
).catch(() => null);
|
|
24210
25062
|
if (!subscription) {
|
|
24211
|
-
|
|
25063
|
+
logger23.log({
|
|
24212
25064
|
level: "error",
|
|
24213
25065
|
message: "Subscription not found."
|
|
24214
25066
|
});
|
|
24215
25067
|
return;
|
|
24216
25068
|
}
|
|
24217
25069
|
if (!subscription._id) {
|
|
24218
|
-
|
|
25070
|
+
logger23.log({
|
|
24219
25071
|
level: "error",
|
|
24220
25072
|
message: "Subscription ID is missing."
|
|
24221
25073
|
});
|
|
@@ -24295,7 +25147,7 @@ function useInvoiceService() {
|
|
|
24295
25147
|
return;
|
|
24296
25148
|
}
|
|
24297
25149
|
} catch (error) {
|
|
24298
|
-
|
|
25150
|
+
logger23.log({
|
|
24299
25151
|
level: "error",
|
|
24300
25152
|
message: String(error)
|
|
24301
25153
|
});
|
|
@@ -24305,7 +25157,7 @@ function useInvoiceService() {
|
|
|
24305
25157
|
}
|
|
24306
25158
|
})
|
|
24307
25159
|
);
|
|
24308
|
-
|
|
25160
|
+
logger23.log({
|
|
24309
25161
|
level: "info",
|
|
24310
25162
|
message: "Successfully processed overdue invoices."
|
|
24311
25163
|
});
|
|
@@ -24317,7 +25169,7 @@ function useInvoiceService() {
|
|
|
24317
25169
|
}
|
|
24318
25170
|
const session = useAtlas24.getClient()?.startSession();
|
|
24319
25171
|
if (!session) {
|
|
24320
|
-
|
|
25172
|
+
logger23.log({
|
|
24321
25173
|
level: "error",
|
|
24322
25174
|
message: "Failed to start session."
|
|
24323
25175
|
});
|
|
@@ -24386,7 +25238,7 @@ function useInvoiceService() {
|
|
|
24386
25238
|
return "Payment processed successfully.";
|
|
24387
25239
|
} catch (error) {
|
|
24388
25240
|
session.abortTransaction();
|
|
24389
|
-
|
|
25241
|
+
logger23.log({
|
|
24390
25242
|
level: "error",
|
|
24391
25243
|
message: String(error)
|
|
24392
25244
|
});
|