@goweekdays/core 1.1.7 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.ts +8 -41
- package/dist/index.js +1026 -286
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1148 -399
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
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;
|
|
@@ -10380,20 +10380,21 @@ var require_proxy_from_env = __commonJS({
|
|
|
10380
10380
|
}
|
|
10381
10381
|
});
|
|
10382
10382
|
|
|
10383
|
-
// node_modules/
|
|
10383
|
+
// node_modules/ms/index.js
|
|
10384
10384
|
var require_ms = __commonJS({
|
|
10385
|
-
"node_modules/
|
|
10385
|
+
"node_modules/ms/index.js"(exports, module) {
|
|
10386
10386
|
var s = 1e3;
|
|
10387
10387
|
var m = s * 60;
|
|
10388
10388
|
var h = m * 60;
|
|
10389
10389
|
var d = h * 24;
|
|
10390
|
+
var w = d * 7;
|
|
10390
10391
|
var y = d * 365.25;
|
|
10391
10392
|
module.exports = function(val, options) {
|
|
10392
10393
|
options = options || {};
|
|
10393
10394
|
var type = typeof val;
|
|
10394
10395
|
if (type === "string" && val.length > 0) {
|
|
10395
10396
|
return parse(val);
|
|
10396
|
-
} else if (type === "number" &&
|
|
10397
|
+
} else if (type === "number" && isFinite(val)) {
|
|
10397
10398
|
return options.long ? fmtLong(val) : fmtShort(val);
|
|
10398
10399
|
}
|
|
10399
10400
|
throw new Error(
|
|
@@ -10405,7 +10406,7 @@ var require_ms = __commonJS({
|
|
|
10405
10406
|
if (str.length > 100) {
|
|
10406
10407
|
return;
|
|
10407
10408
|
}
|
|
10408
|
-
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(
|
|
10409
10410
|
str
|
|
10410
10411
|
);
|
|
10411
10412
|
if (!match) {
|
|
@@ -10420,6 +10421,10 @@ var require_ms = __commonJS({
|
|
|
10420
10421
|
case "yr":
|
|
10421
10422
|
case "y":
|
|
10422
10423
|
return n * y;
|
|
10424
|
+
case "weeks":
|
|
10425
|
+
case "week":
|
|
10426
|
+
case "w":
|
|
10427
|
+
return n * w;
|
|
10423
10428
|
case "days":
|
|
10424
10429
|
case "day":
|
|
10425
10430
|
case "d":
|
|
@@ -10453,229 +10458,388 @@ var require_ms = __commonJS({
|
|
|
10453
10458
|
}
|
|
10454
10459
|
}
|
|
10455
10460
|
function fmtShort(ms) {
|
|
10456
|
-
|
|
10461
|
+
var msAbs = Math.abs(ms);
|
|
10462
|
+
if (msAbs >= d) {
|
|
10457
10463
|
return Math.round(ms / d) + "d";
|
|
10458
10464
|
}
|
|
10459
|
-
if (
|
|
10465
|
+
if (msAbs >= h) {
|
|
10460
10466
|
return Math.round(ms / h) + "h";
|
|
10461
10467
|
}
|
|
10462
|
-
if (
|
|
10468
|
+
if (msAbs >= m) {
|
|
10463
10469
|
return Math.round(ms / m) + "m";
|
|
10464
10470
|
}
|
|
10465
|
-
if (
|
|
10471
|
+
if (msAbs >= s) {
|
|
10466
10472
|
return Math.round(ms / s) + "s";
|
|
10467
10473
|
}
|
|
10468
10474
|
return ms + "ms";
|
|
10469
10475
|
}
|
|
10470
10476
|
function fmtLong(ms) {
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
|
|
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");
|
|
10476
10486
|
}
|
|
10477
|
-
if (
|
|
10478
|
-
return
|
|
10487
|
+
if (msAbs >= s) {
|
|
10488
|
+
return plural(ms, msAbs, s, "second");
|
|
10479
10489
|
}
|
|
10480
|
-
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" : "");
|
|
10481
10495
|
}
|
|
10482
10496
|
}
|
|
10483
10497
|
});
|
|
10484
10498
|
|
|
10485
|
-
// node_modules/debug/src/
|
|
10486
|
-
var
|
|
10487
|
-
"node_modules/debug/src/
|
|
10488
|
-
|
|
10489
|
-
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
|
|
10493
|
-
|
|
10494
|
-
|
|
10495
|
-
|
|
10496
|
-
|
|
10497
|
-
|
|
10498
|
-
|
|
10499
|
-
|
|
10500
|
-
|
|
10501
|
-
|
|
10502
|
-
|
|
10503
|
-
|
|
10504
|
-
|
|
10505
|
-
|
|
10506
|
-
|
|
10507
|
-
|
|
10508
|
-
if (!debug.enabled)
|
|
10509
|
-
return;
|
|
10510
|
-
var self2 = debug;
|
|
10511
|
-
var curr = +/* @__PURE__ */ new Date();
|
|
10512
|
-
var ms = curr - (prevTime || curr);
|
|
10513
|
-
self2.diff = ms;
|
|
10514
|
-
self2.prev = prevTime;
|
|
10515
|
-
self2.curr = curr;
|
|
10516
|
-
prevTime = curr;
|
|
10517
|
-
var args = new Array(arguments.length);
|
|
10518
|
-
for (var i = 0; i < args.length; i++) {
|
|
10519
|
-
args[i] = arguments[i];
|
|
10520
|
-
}
|
|
10521
|
-
args[0] = exports.coerce(args[0]);
|
|
10522
|
-
if ("string" !== typeof args[0]) {
|
|
10523
|
-
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;
|
|
10524
10522
|
}
|
|
10525
|
-
|
|
10526
|
-
|
|
10527
|
-
|
|
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
|
+
}
|
|
10528
10559
|
return match;
|
|
10529
|
-
|
|
10530
|
-
|
|
10531
|
-
|
|
10532
|
-
|
|
10533
|
-
|
|
10534
|
-
|
|
10535
|
-
|
|
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;
|
|
10536
10585
|
}
|
|
10537
|
-
return match;
|
|
10538
10586
|
});
|
|
10539
|
-
|
|
10540
|
-
|
|
10541
|
-
|
|
10542
|
-
|
|
10543
|
-
|
|
10544
|
-
|
|
10545
|
-
|
|
10546
|
-
|
|
10547
|
-
|
|
10548
|
-
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
|
|
10554
|
-
|
|
10555
|
-
|
|
10556
|
-
|
|
10557
|
-
|
|
10558
|
-
|
|
10559
|
-
|
|
10560
|
-
|
|
10561
|
-
namespaces = split[i].replace(/\*/g, ".*?");
|
|
10562
|
-
if (namespaces[0] === "-") {
|
|
10563
|
-
exports.skips.push(new RegExp("^" + namespaces.substr(1) + "$"));
|
|
10564
|
-
} else {
|
|
10565
|
-
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
|
+
}
|
|
10566
10609
|
}
|
|
10567
10610
|
}
|
|
10568
|
-
|
|
10569
|
-
|
|
10570
|
-
|
|
10571
|
-
|
|
10572
|
-
|
|
10573
|
-
|
|
10574
|
-
|
|
10575
|
-
|
|
10576
|
-
|
|
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
|
+
}
|
|
10577
10657
|
}
|
|
10658
|
+
return false;
|
|
10578
10659
|
}
|
|
10579
|
-
|
|
10580
|
-
if (
|
|
10581
|
-
return
|
|
10660
|
+
function coerce(val) {
|
|
10661
|
+
if (val instanceof Error) {
|
|
10662
|
+
return val.stack || val.message;
|
|
10582
10663
|
}
|
|
10664
|
+
return val;
|
|
10583
10665
|
}
|
|
10584
|
-
|
|
10585
|
-
|
|
10586
|
-
|
|
10587
|
-
|
|
10588
|
-
|
|
10589
|
-
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;
|
|
10590
10671
|
}
|
|
10672
|
+
module.exports = setup;
|
|
10591
10673
|
}
|
|
10592
10674
|
});
|
|
10593
10675
|
|
|
10594
10676
|
// node_modules/debug/src/browser.js
|
|
10595
10677
|
var require_browser = __commonJS({
|
|
10596
10678
|
"node_modules/debug/src/browser.js"(exports, module) {
|
|
10597
|
-
exports = module.exports = require_debug();
|
|
10598
|
-
exports.log = log;
|
|
10599
10679
|
exports.formatArgs = formatArgs;
|
|
10600
10680
|
exports.save = save;
|
|
10601
10681
|
exports.load = load;
|
|
10602
10682
|
exports.useColors = useColors;
|
|
10603
|
-
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
|
+
})();
|
|
10604
10693
|
exports.colors = [
|
|
10605
|
-
"
|
|
10606
|
-
"
|
|
10607
|
-
"
|
|
10608
|
-
"
|
|
10609
|
-
"
|
|
10610
|
-
"
|
|
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"
|
|
10611
10770
|
];
|
|
10612
10771
|
function useColors() {
|
|
10613
|
-
if (typeof window !== "undefined" && window.process && window.process.type === "renderer") {
|
|
10772
|
+
if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) {
|
|
10614
10773
|
return true;
|
|
10615
10774
|
}
|
|
10616
|
-
|
|
10617
|
-
|
|
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?
|
|
10618
10781
|
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
10619
|
-
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
|
|
10620
10783
|
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
10621
10784
|
}
|
|
10622
|
-
exports.formatters.j = function(v) {
|
|
10623
|
-
try {
|
|
10624
|
-
return JSON.stringify(v);
|
|
10625
|
-
} catch (err) {
|
|
10626
|
-
return "[UnexpectedJSONParseError]: " + err.message;
|
|
10627
|
-
}
|
|
10628
|
-
};
|
|
10629
10785
|
function formatArgs(args) {
|
|
10630
|
-
|
|
10631
|
-
|
|
10632
|
-
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) {
|
|
10633
10788
|
return;
|
|
10634
|
-
|
|
10789
|
+
}
|
|
10790
|
+
const c = "color: " + this.color;
|
|
10635
10791
|
args.splice(1, 0, c, "color: inherit");
|
|
10636
|
-
|
|
10637
|
-
|
|
10638
|
-
args[0].replace(/%[a-zA-Z%]/g,
|
|
10639
|
-
if ("%%"
|
|
10792
|
+
let index = 0;
|
|
10793
|
+
let lastC = 0;
|
|
10794
|
+
args[0].replace(/%[a-zA-Z%]/g, (match) => {
|
|
10795
|
+
if (match === "%%") {
|
|
10640
10796
|
return;
|
|
10797
|
+
}
|
|
10641
10798
|
index++;
|
|
10642
|
-
if ("%c"
|
|
10799
|
+
if (match === "%c") {
|
|
10643
10800
|
lastC = index;
|
|
10644
10801
|
}
|
|
10645
10802
|
});
|
|
10646
10803
|
args.splice(lastC, 0, c);
|
|
10647
10804
|
}
|
|
10648
|
-
|
|
10649
|
-
|
|
10650
|
-
}
|
|
10805
|
+
exports.log = console.debug || console.log || (() => {
|
|
10806
|
+
});
|
|
10651
10807
|
function save(namespaces) {
|
|
10652
10808
|
try {
|
|
10653
|
-
if (
|
|
10654
|
-
exports.storage.
|
|
10809
|
+
if (namespaces) {
|
|
10810
|
+
exports.storage.setItem("debug", namespaces);
|
|
10655
10811
|
} else {
|
|
10656
|
-
exports.storage.debug
|
|
10812
|
+
exports.storage.removeItem("debug");
|
|
10657
10813
|
}
|
|
10658
|
-
} catch (
|
|
10814
|
+
} catch (error) {
|
|
10659
10815
|
}
|
|
10660
10816
|
}
|
|
10661
10817
|
function load() {
|
|
10662
|
-
|
|
10818
|
+
let r;
|
|
10663
10819
|
try {
|
|
10664
|
-
r = exports.storage.debug;
|
|
10665
|
-
} catch (
|
|
10820
|
+
r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG");
|
|
10821
|
+
} catch (error) {
|
|
10666
10822
|
}
|
|
10667
10823
|
if (!r && typeof process !== "undefined" && "env" in process) {
|
|
10668
10824
|
r = process.env.DEBUG;
|
|
10669
10825
|
}
|
|
10670
10826
|
return r;
|
|
10671
10827
|
}
|
|
10672
|
-
exports.enable(load());
|
|
10673
10828
|
function localstorage() {
|
|
10674
10829
|
try {
|
|
10675
|
-
return
|
|
10676
|
-
} catch (
|
|
10830
|
+
return localStorage;
|
|
10831
|
+
} catch (error) {
|
|
10677
10832
|
}
|
|
10678
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
|
+
};
|
|
10679
10843
|
}
|
|
10680
10844
|
});
|
|
10681
10845
|
|
|
@@ -10684,129 +10848,179 @@ var require_node = __commonJS({
|
|
|
10684
10848
|
"node_modules/debug/src/node.js"(exports, module) {
|
|
10685
10849
|
var tty = __require("tty");
|
|
10686
10850
|
var util3 = __require("util");
|
|
10687
|
-
exports = module.exports = require_debug();
|
|
10688
10851
|
exports.init = init;
|
|
10689
10852
|
exports.log = log;
|
|
10690
10853
|
exports.formatArgs = formatArgs;
|
|
10691
10854
|
exports.save = save;
|
|
10692
10855
|
exports.load = load;
|
|
10693
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
|
+
);
|
|
10694
10862
|
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
10695
|
-
|
|
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) => {
|
|
10696
10948
|
return /^debug_/i.test(key);
|
|
10697
|
-
}).reduce(
|
|
10698
|
-
|
|
10949
|
+
}).reduce((obj, key) => {
|
|
10950
|
+
const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
|
|
10699
10951
|
return k.toUpperCase();
|
|
10700
10952
|
});
|
|
10701
|
-
|
|
10702
|
-
if (/^(yes|on|true|enabled)$/i.test(val))
|
|
10953
|
+
let val = process.env[key];
|
|
10954
|
+
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
|
10703
10955
|
val = true;
|
|
10704
|
-
else if (/^(no|off|false|disabled)$/i.test(val))
|
|
10956
|
+
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
|
10705
10957
|
val = false;
|
|
10706
|
-
else if (val === "null")
|
|
10958
|
+
} else if (val === "null") {
|
|
10707
10959
|
val = null;
|
|
10708
|
-
else
|
|
10960
|
+
} else {
|
|
10709
10961
|
val = Number(val);
|
|
10962
|
+
}
|
|
10710
10963
|
obj[prop] = val;
|
|
10711
10964
|
return obj;
|
|
10712
10965
|
}, {});
|
|
10713
|
-
var fd = parseInt(process.env.DEBUG_FD, 10) || 2;
|
|
10714
|
-
if (1 !== fd && 2 !== fd) {
|
|
10715
|
-
util3.deprecate(function() {
|
|
10716
|
-
}, "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)")();
|
|
10717
|
-
}
|
|
10718
|
-
var stream4 = 1 === fd ? process.stdout : 2 === fd ? process.stderr : createWritableStdioStream(fd);
|
|
10719
10966
|
function useColors() {
|
|
10720
|
-
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);
|
|
10721
10968
|
}
|
|
10722
|
-
exports.formatters.o = function(v) {
|
|
10723
|
-
this.inspectOpts.colors = this.useColors;
|
|
10724
|
-
return util3.inspect(v, this.inspectOpts).split("\n").map(function(str) {
|
|
10725
|
-
return str.trim();
|
|
10726
|
-
}).join(" ");
|
|
10727
|
-
};
|
|
10728
|
-
exports.formatters.O = function(v) {
|
|
10729
|
-
this.inspectOpts.colors = this.useColors;
|
|
10730
|
-
return util3.inspect(v, this.inspectOpts);
|
|
10731
|
-
};
|
|
10732
10969
|
function formatArgs(args) {
|
|
10733
|
-
|
|
10734
|
-
var useColors2 = this.useColors;
|
|
10970
|
+
const { namespace: name, useColors: useColors2 } = this;
|
|
10735
10971
|
if (useColors2) {
|
|
10736
|
-
|
|
10737
|
-
|
|
10972
|
+
const c = this.color;
|
|
10973
|
+
const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
|
|
10974
|
+
const prefix = ` ${colorCode};1m${name} \x1B[0m`;
|
|
10738
10975
|
args[0] = prefix + args[0].split("\n").join("\n" + prefix);
|
|
10739
|
-
args.push(
|
|
10976
|
+
args.push(colorCode + "m+" + module.exports.humanize(this.diff) + "\x1B[0m");
|
|
10740
10977
|
} else {
|
|
10741
|
-
args[0] = (
|
|
10978
|
+
args[0] = getDate() + name + " " + args[0];
|
|
10979
|
+
}
|
|
10980
|
+
}
|
|
10981
|
+
function getDate() {
|
|
10982
|
+
if (exports.inspectOpts.hideDate) {
|
|
10983
|
+
return "";
|
|
10742
10984
|
}
|
|
10985
|
+
return (/* @__PURE__ */ new Date()).toISOString() + " ";
|
|
10743
10986
|
}
|
|
10744
|
-
function log() {
|
|
10745
|
-
return
|
|
10987
|
+
function log(...args) {
|
|
10988
|
+
return process.stderr.write(util3.formatWithOptions(exports.inspectOpts, ...args) + "\n");
|
|
10746
10989
|
}
|
|
10747
10990
|
function save(namespaces) {
|
|
10748
|
-
if (
|
|
10749
|
-
delete process.env.DEBUG;
|
|
10750
|
-
} else {
|
|
10991
|
+
if (namespaces) {
|
|
10751
10992
|
process.env.DEBUG = namespaces;
|
|
10993
|
+
} else {
|
|
10994
|
+
delete process.env.DEBUG;
|
|
10752
10995
|
}
|
|
10753
10996
|
}
|
|
10754
10997
|
function load() {
|
|
10755
10998
|
return process.env.DEBUG;
|
|
10756
10999
|
}
|
|
10757
|
-
function createWritableStdioStream(fd2) {
|
|
10758
|
-
var stream5;
|
|
10759
|
-
var tty_wrap = process.binding("tty_wrap");
|
|
10760
|
-
switch (tty_wrap.guessHandleType(fd2)) {
|
|
10761
|
-
case "TTY":
|
|
10762
|
-
stream5 = new tty.WriteStream(fd2);
|
|
10763
|
-
stream5._type = "tty";
|
|
10764
|
-
if (stream5._handle && stream5._handle.unref) {
|
|
10765
|
-
stream5._handle.unref();
|
|
10766
|
-
}
|
|
10767
|
-
break;
|
|
10768
|
-
case "FILE":
|
|
10769
|
-
var fs = __require("fs");
|
|
10770
|
-
stream5 = new fs.SyncWriteStream(fd2, { autoClose: false });
|
|
10771
|
-
stream5._type = "fs";
|
|
10772
|
-
break;
|
|
10773
|
-
case "PIPE":
|
|
10774
|
-
case "TCP":
|
|
10775
|
-
var net = __require("net");
|
|
10776
|
-
stream5 = new net.Socket({
|
|
10777
|
-
fd: fd2,
|
|
10778
|
-
readable: false,
|
|
10779
|
-
writable: true
|
|
10780
|
-
});
|
|
10781
|
-
stream5.readable = false;
|
|
10782
|
-
stream5.read = null;
|
|
10783
|
-
stream5._type = "pipe";
|
|
10784
|
-
if (stream5._handle && stream5._handle.unref) {
|
|
10785
|
-
stream5._handle.unref();
|
|
10786
|
-
}
|
|
10787
|
-
break;
|
|
10788
|
-
default:
|
|
10789
|
-
throw new Error("Implement me. Unknown stream file type!");
|
|
10790
|
-
}
|
|
10791
|
-
stream5.fd = fd2;
|
|
10792
|
-
stream5._isStdio = true;
|
|
10793
|
-
return stream5;
|
|
10794
|
-
}
|
|
10795
11000
|
function init(debug) {
|
|
10796
11001
|
debug.inspectOpts = {};
|
|
10797
|
-
|
|
10798
|
-
for (
|
|
11002
|
+
const keys = Object.keys(exports.inspectOpts);
|
|
11003
|
+
for (let i = 0; i < keys.length; i++) {
|
|
10799
11004
|
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
10800
11005
|
}
|
|
10801
11006
|
}
|
|
10802
|
-
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
|
+
};
|
|
10803
11017
|
}
|
|
10804
11018
|
});
|
|
10805
11019
|
|
|
10806
11020
|
// node_modules/debug/src/index.js
|
|
10807
11021
|
var require_src = __commonJS({
|
|
10808
11022
|
"node_modules/debug/src/index.js"(exports, module) {
|
|
10809
|
-
if (typeof process
|
|
11023
|
+
if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
|
|
10810
11024
|
module.exports = require_browser();
|
|
10811
11025
|
} else {
|
|
10812
11026
|
module.exports = require_node();
|
|
@@ -10815,7 +11029,7 @@ var require_src = __commonJS({
|
|
|
10815
11029
|
});
|
|
10816
11030
|
|
|
10817
11031
|
// node_modules/follow-redirects/debug.js
|
|
10818
|
-
var
|
|
11032
|
+
var require_debug = __commonJS({
|
|
10819
11033
|
"node_modules/follow-redirects/debug.js"(exports, module) {
|
|
10820
11034
|
var debug;
|
|
10821
11035
|
module.exports = function() {
|
|
@@ -10843,7 +11057,7 @@ var require_follow_redirects = __commonJS({
|
|
|
10843
11057
|
var https2 = __require("https");
|
|
10844
11058
|
var Writable = __require("stream").Writable;
|
|
10845
11059
|
var assert = __require("assert");
|
|
10846
|
-
var debug =
|
|
11060
|
+
var debug = require_debug();
|
|
10847
11061
|
(function detectUnsupportedEnvironment() {
|
|
10848
11062
|
var looksLikeNode = typeof process !== "undefined";
|
|
10849
11063
|
var looksLikeBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
@@ -11461,7 +11675,7 @@ function useVerificationRepo() {
|
|
|
11461
11675
|
return cached;
|
|
11462
11676
|
}
|
|
11463
11677
|
const data = await collection.findOne({ _id });
|
|
11464
|
-
setCache(cacheKey, data).then(() => {
|
|
11678
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
11465
11679
|
logger.log({
|
|
11466
11680
|
level: "info",
|
|
11467
11681
|
message: `Cache set for verification by id: ${cacheKey}`
|
|
@@ -11541,7 +11755,7 @@ function useVerificationRepo() {
|
|
|
11541
11755
|
]).toArray();
|
|
11542
11756
|
const length = await collection.countDocuments(query);
|
|
11543
11757
|
const data = paginate(items, page, limit, length);
|
|
11544
|
-
setCache(cacheKey, data).then(() => {
|
|
11758
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
11545
11759
|
logger.log({
|
|
11546
11760
|
level: "info",
|
|
11547
11761
|
message: `Cache set for getVerifications: ${cacheKey}`
|
|
@@ -11572,7 +11786,7 @@ function useVerificationRepo() {
|
|
|
11572
11786
|
return cached;
|
|
11573
11787
|
}
|
|
11574
11788
|
const data = await collection.find({ type }).toArray();
|
|
11575
|
-
setCache(cacheKey, data).then(() => {
|
|
11789
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
11576
11790
|
logger.log({
|
|
11577
11791
|
level: "info",
|
|
11578
11792
|
message: `Cache set for verification by type: ${cacheKey}`
|
|
@@ -11796,7 +12010,7 @@ function useUserRepo() {
|
|
|
11796
12010
|
}
|
|
11797
12011
|
const result = await collection.findOne({ email });
|
|
11798
12012
|
if (result) {
|
|
11799
|
-
setCache(cacheKey, result).then(() => {
|
|
12013
|
+
setCache(cacheKey, result, 300, namespace_collection).then(() => {
|
|
11800
12014
|
logger2.log({
|
|
11801
12015
|
level: "info",
|
|
11802
12016
|
message: `Cache set for user by email: ${cacheKey}`
|
|
@@ -11826,7 +12040,7 @@ function useUserRepo() {
|
|
|
11826
12040
|
}
|
|
11827
12041
|
const result = await collection.findOne({ referralCode });
|
|
11828
12042
|
if (result) {
|
|
11829
|
-
setCache(cacheKey, result).then(() => {
|
|
12043
|
+
setCache(cacheKey, result, 300, namespace_collection).then(() => {
|
|
11830
12044
|
logger2.log({
|
|
11831
12045
|
level: "info",
|
|
11832
12046
|
message: `Cache set for user by referral code: ${cacheKey}`
|
|
@@ -11861,7 +12075,7 @@ function useUserRepo() {
|
|
|
11861
12075
|
}
|
|
11862
12076
|
const result = await collection.findOne({ _id });
|
|
11863
12077
|
if (result) {
|
|
11864
|
-
setCache(cacheKey, result).then(() => {
|
|
12078
|
+
setCache(cacheKey, result, 300, namespace_collection).then(() => {
|
|
11865
12079
|
logger2.log({
|
|
11866
12080
|
level: "info",
|
|
11867
12081
|
message: `Cache set for user by id: ${cacheKey}`
|
|
@@ -11935,7 +12149,7 @@ function useUserRepo() {
|
|
|
11935
12149
|
]).toArray();
|
|
11936
12150
|
const length = await collection.countDocuments(query);
|
|
11937
12151
|
const data = paginate2(items, page, limit, length);
|
|
11938
|
-
setCache(cacheKey, data).then(() => {
|
|
12152
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
11939
12153
|
logger2.log({
|
|
11940
12154
|
level: "info",
|
|
11941
12155
|
message: `Cache set for getUsers: ${cacheKey}`
|
|
@@ -12246,7 +12460,7 @@ function useMemberRepo() {
|
|
|
12246
12460
|
return cached;
|
|
12247
12461
|
}
|
|
12248
12462
|
const data = await collection.findOne({ _id });
|
|
12249
|
-
setCache(cacheKey, data).then(() => {
|
|
12463
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
12250
12464
|
logger3.log({
|
|
12251
12465
|
level: "info",
|
|
12252
12466
|
message: `Cache set for member by id: ${cacheKey}`
|
|
@@ -12283,7 +12497,7 @@ function useMemberRepo() {
|
|
|
12283
12497
|
return cached;
|
|
12284
12498
|
}
|
|
12285
12499
|
const data = await collection.findOne({ user });
|
|
12286
|
-
setCache(cacheKey, data).then(() => {
|
|
12500
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
12287
12501
|
logger3.log({
|
|
12288
12502
|
level: "info",
|
|
12289
12503
|
message: `Cache set for member by user ID: ${cacheKey}`
|
|
@@ -12387,7 +12601,7 @@ function useMemberRepo() {
|
|
|
12387
12601
|
]).toArray();
|
|
12388
12602
|
const length = await collection.countDocuments(query);
|
|
12389
12603
|
const data = paginate3(items, page, limit, length);
|
|
12390
|
-
setCache(cacheKey, data).then(() => {
|
|
12604
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
12391
12605
|
logger3.log({
|
|
12392
12606
|
level: "info",
|
|
12393
12607
|
message: `Cache set for getAll members: ${cacheKey}`
|
|
@@ -12422,7 +12636,7 @@ function useMemberRepo() {
|
|
|
12422
12636
|
return cached;
|
|
12423
12637
|
}
|
|
12424
12638
|
const data = await collection.countDocuments({ org, status: "active" });
|
|
12425
|
-
setCache(cacheKey, data).then(() => {
|
|
12639
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
12426
12640
|
logger3.log({
|
|
12427
12641
|
level: "info",
|
|
12428
12642
|
message: `Cache set for countByOrg members: ${cacheKey}`
|
|
@@ -12459,7 +12673,7 @@ function useMemberRepo() {
|
|
|
12459
12673
|
return cached;
|
|
12460
12674
|
}
|
|
12461
12675
|
const data = await collection.countDocuments({ user, status: "active" });
|
|
12462
|
-
setCache(cacheKey, data).then(() => {
|
|
12676
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
12463
12677
|
logger3.log({
|
|
12464
12678
|
level: "info",
|
|
12465
12679
|
message: `Cache set for countByUser members: ${cacheKey}`
|
|
@@ -12529,7 +12743,7 @@ function useMemberRepo() {
|
|
|
12529
12743
|
]).toArray();
|
|
12530
12744
|
const length = await collection.countDocuments(query);
|
|
12531
12745
|
const data = paginate3(items, page, limit, length);
|
|
12532
|
-
setCache(cacheKey, data).then(() => {
|
|
12746
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
12533
12747
|
logger3.log({
|
|
12534
12748
|
level: "info",
|
|
12535
12749
|
message: `Cache set for getOrgsByMembership members: ${cacheKey}`
|
|
@@ -12607,7 +12821,7 @@ function useMemberRepo() {
|
|
|
12607
12821
|
]).toArray();
|
|
12608
12822
|
const length = await collection.countDocuments(query);
|
|
12609
12823
|
const data = paginate3(items, page, limit, length);
|
|
12610
|
-
setCache(cacheKey, data).then(() => {
|
|
12824
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
12611
12825
|
logger3.log({
|
|
12612
12826
|
level: "info",
|
|
12613
12827
|
message: `Cache set for getOrgsByUserId members: ${cacheKey}`
|
|
@@ -13172,14 +13386,29 @@ var MToken = class {
|
|
|
13172
13386
|
};
|
|
13173
13387
|
|
|
13174
13388
|
// src/repositories/token.repository.ts
|
|
13175
|
-
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";
|
|
13176
13390
|
import { ObjectId as ObjectId8 } from "mongodb";
|
|
13177
13391
|
function useTokenRepo() {
|
|
13178
13392
|
const db = useAtlas5.getDb();
|
|
13179
13393
|
if (!db) {
|
|
13180
13394
|
throw new InternalServerError6("Unable to connect to server.");
|
|
13181
13395
|
}
|
|
13182
|
-
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
|
+
}
|
|
13183
13412
|
async function createToken({ token, user } = {}) {
|
|
13184
13413
|
try {
|
|
13185
13414
|
user = new ObjectId8(user);
|
|
@@ -13188,21 +13417,47 @@ function useTokenRepo() {
|
|
|
13188
13417
|
}
|
|
13189
13418
|
try {
|
|
13190
13419
|
await collection.insertOne({ token, user });
|
|
13420
|
+
delCachedData();
|
|
13191
13421
|
return "Token created";
|
|
13192
13422
|
} catch (error) {
|
|
13193
13423
|
return Promise.reject(error);
|
|
13194
13424
|
}
|
|
13195
13425
|
}
|
|
13196
13426
|
async function getToken(token) {
|
|
13427
|
+
const cacheKey = makeCacheKey4(namespace_collection, { token });
|
|
13197
13428
|
try {
|
|
13198
|
-
|
|
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;
|
|
13199
13452
|
} catch (error) {
|
|
13200
13453
|
return Promise.reject(error);
|
|
13201
13454
|
}
|
|
13202
13455
|
}
|
|
13203
13456
|
async function deleteToken(token) {
|
|
13204
13457
|
try {
|
|
13205
|
-
|
|
13458
|
+
const result = await collection.deleteOne({ token });
|
|
13459
|
+
delCachedData();
|
|
13460
|
+
return result;
|
|
13206
13461
|
} catch (error) {
|
|
13207
13462
|
return Promise.reject(error);
|
|
13208
13463
|
}
|
|
@@ -13220,10 +13475,10 @@ import {
|
|
|
13220
13475
|
InternalServerError as InternalServerError9,
|
|
13221
13476
|
NotFoundError as NotFoundError2,
|
|
13222
13477
|
hashPassword,
|
|
13223
|
-
logger as
|
|
13224
|
-
makeCacheKey as
|
|
13478
|
+
logger as logger9,
|
|
13479
|
+
makeCacheKey as makeCacheKey7,
|
|
13225
13480
|
useAtlas as useAtlas8,
|
|
13226
|
-
useCache as
|
|
13481
|
+
useCache as useCache7,
|
|
13227
13482
|
useS3
|
|
13228
13483
|
} from "@goweekdays/utils";
|
|
13229
13484
|
|
|
@@ -13231,7 +13486,10 @@ import {
|
|
|
13231
13486
|
import {
|
|
13232
13487
|
BadRequestError as BadRequestError8,
|
|
13233
13488
|
InternalServerError as InternalServerError7,
|
|
13234
|
-
|
|
13489
|
+
logger as logger6,
|
|
13490
|
+
makeCacheKey as makeCacheKey5,
|
|
13491
|
+
useAtlas as useAtlas6,
|
|
13492
|
+
useCache as useCache5
|
|
13235
13493
|
} from "@goweekdays/utils";
|
|
13236
13494
|
|
|
13237
13495
|
// src/models/file.model.ts
|
|
@@ -13252,11 +13510,27 @@ function useFileRepo() {
|
|
|
13252
13510
|
if (!db) {
|
|
13253
13511
|
throw new InternalServerError7("Unable to connect to server.");
|
|
13254
13512
|
}
|
|
13255
|
-
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
|
+
}
|
|
13256
13529
|
async function createFile(value, session) {
|
|
13257
13530
|
try {
|
|
13258
13531
|
value = new MFile(value);
|
|
13259
13532
|
const res = await collection.insertOne(value, { session });
|
|
13533
|
+
delCachedData();
|
|
13260
13534
|
return res.insertedId.toString();
|
|
13261
13535
|
} catch (error) {
|
|
13262
13536
|
throw new InternalServerError7("Failed to create file.");
|
|
@@ -13270,14 +13544,36 @@ function useFileRepo() {
|
|
|
13270
13544
|
}
|
|
13271
13545
|
try {
|
|
13272
13546
|
await collection.deleteOne({ _id }, { session });
|
|
13547
|
+
delCachedData();
|
|
13273
13548
|
return "File deleted successfully";
|
|
13274
13549
|
} catch (error) {
|
|
13275
13550
|
throw new InternalServerError7("Failed to delete file.");
|
|
13276
13551
|
}
|
|
13277
13552
|
}
|
|
13278
13553
|
async function getAllDraftedFiles() {
|
|
13554
|
+
const cacheKey = makeCacheKey5(namespace_collection, { status: "draft" });
|
|
13279
13555
|
try {
|
|
13280
|
-
|
|
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;
|
|
13281
13577
|
} catch (error) {
|
|
13282
13578
|
throw new InternalServerError7("Failed to get drafted files.");
|
|
13283
13579
|
}
|
|
@@ -16620,7 +16916,7 @@ var {
|
|
|
16620
16916
|
} = axios_default;
|
|
16621
16917
|
|
|
16622
16918
|
// src/services/xendit.service.ts
|
|
16623
|
-
import { AppError as AppError3, BadRequestError as BadRequestError9, logger as
|
|
16919
|
+
import { AppError as AppError3, BadRequestError as BadRequestError9, logger as logger7 } from "@goweekdays/utils";
|
|
16624
16920
|
import { ObjectId as ObjectId11 } from "mongodb";
|
|
16625
16921
|
import Joi3 from "joi";
|
|
16626
16922
|
|
|
@@ -16961,7 +17257,7 @@ function useXenditService() {
|
|
|
16961
17257
|
});
|
|
16962
17258
|
return res.data;
|
|
16963
17259
|
} catch (error) {
|
|
16964
|
-
|
|
17260
|
+
logger7.error(error.response.data.message);
|
|
16965
17261
|
throw new BadRequestError9(error.response.data.message);
|
|
16966
17262
|
}
|
|
16967
17263
|
}
|
|
@@ -17128,7 +17424,7 @@ function useXenditService() {
|
|
|
17128
17424
|
});
|
|
17129
17425
|
return res.data;
|
|
17130
17426
|
} catch (error) {
|
|
17131
|
-
|
|
17427
|
+
logger7.log({
|
|
17132
17428
|
level: "error",
|
|
17133
17429
|
message: `${error}`
|
|
17134
17430
|
});
|
|
@@ -17246,9 +17542,9 @@ import {
|
|
|
17246
17542
|
InternalServerError as InternalServerError8,
|
|
17247
17543
|
useAtlas as useAtlas7,
|
|
17248
17544
|
paginate as paginate4,
|
|
17249
|
-
logger as
|
|
17250
|
-
makeCacheKey as
|
|
17251
|
-
useCache as
|
|
17545
|
+
logger as logger8,
|
|
17546
|
+
makeCacheKey as makeCacheKey6,
|
|
17547
|
+
useCache as useCache6
|
|
17252
17548
|
} from "@goweekdays/utils";
|
|
17253
17549
|
|
|
17254
17550
|
// src/models/role.model.ts
|
|
@@ -17300,15 +17596,15 @@ function useRoleRepo() {
|
|
|
17300
17596
|
}
|
|
17301
17597
|
const namespace_collection = "roles";
|
|
17302
17598
|
const collection = db.collection(namespace_collection);
|
|
17303
|
-
const { getCache, setCache, delNamespace } =
|
|
17599
|
+
const { getCache, setCache, delNamespace } = useCache6();
|
|
17304
17600
|
function delCachedData() {
|
|
17305
17601
|
delNamespace(namespace_collection).then(() => {
|
|
17306
|
-
|
|
17602
|
+
logger8.log({
|
|
17307
17603
|
level: "info",
|
|
17308
17604
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
17309
17605
|
});
|
|
17310
17606
|
}).catch((err) => {
|
|
17311
|
-
|
|
17607
|
+
logger8.log({
|
|
17312
17608
|
level: "error",
|
|
17313
17609
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
17314
17610
|
});
|
|
@@ -17347,7 +17643,7 @@ function useRoleRepo() {
|
|
|
17347
17643
|
delCachedData();
|
|
17348
17644
|
return res.insertedId;
|
|
17349
17645
|
} catch (error) {
|
|
17350
|
-
|
|
17646
|
+
logger8.log({ level: "error", message: `${error}` });
|
|
17351
17647
|
const isDuplicated = error.message.includes("duplicate");
|
|
17352
17648
|
if (isDuplicated) {
|
|
17353
17649
|
throw new BadRequestError10("Role already exists");
|
|
@@ -17362,25 +17658,25 @@ function useRoleRepo() {
|
|
|
17362
17658
|
throw new BadRequestError10("Invalid user ID.");
|
|
17363
17659
|
}
|
|
17364
17660
|
try {
|
|
17365
|
-
const cacheKey =
|
|
17661
|
+
const cacheKey = makeCacheKey6(namespace_collection, {
|
|
17366
17662
|
user: String(value)
|
|
17367
17663
|
});
|
|
17368
17664
|
const cached = await getCache(cacheKey);
|
|
17369
17665
|
if (cached) {
|
|
17370
|
-
|
|
17666
|
+
logger8.log({
|
|
17371
17667
|
level: "info",
|
|
17372
17668
|
message: `Cache hit for getRoleByUserId role: ${cacheKey}`
|
|
17373
17669
|
});
|
|
17374
17670
|
return cached;
|
|
17375
17671
|
}
|
|
17376
17672
|
const data = await collection.findOne({ user: value });
|
|
17377
|
-
setCache(cacheKey, data).then(() => {
|
|
17378
|
-
|
|
17673
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
17674
|
+
logger8.log({
|
|
17379
17675
|
level: "info",
|
|
17380
17676
|
message: `Cache set for role by user ID: ${cacheKey}`
|
|
17381
17677
|
});
|
|
17382
17678
|
}).catch((err) => {
|
|
17383
|
-
|
|
17679
|
+
logger8.log({
|
|
17384
17680
|
level: "error",
|
|
17385
17681
|
message: `Failed to set cache for role by user ID: ${err.message}`
|
|
17386
17682
|
});
|
|
@@ -17397,25 +17693,25 @@ function useRoleRepo() {
|
|
|
17397
17693
|
throw new BadRequestError10("Invalid ID.");
|
|
17398
17694
|
}
|
|
17399
17695
|
try {
|
|
17400
|
-
const cacheKey =
|
|
17696
|
+
const cacheKey = makeCacheKey6(namespace_collection, {
|
|
17401
17697
|
id: _id.toString()
|
|
17402
17698
|
});
|
|
17403
17699
|
const cached = await getCache(cacheKey);
|
|
17404
17700
|
if (cached) {
|
|
17405
|
-
|
|
17701
|
+
logger8.log({
|
|
17406
17702
|
level: "info",
|
|
17407
17703
|
message: `Cache hit for getRoleById role: ${cacheKey}`
|
|
17408
17704
|
});
|
|
17409
17705
|
return cached;
|
|
17410
17706
|
}
|
|
17411
17707
|
const data = await collection.findOne({ _id });
|
|
17412
|
-
setCache(cacheKey, data).then(() => {
|
|
17413
|
-
|
|
17708
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
17709
|
+
logger8.log({
|
|
17414
17710
|
level: "info",
|
|
17415
17711
|
message: `Cache set for role by id: ${cacheKey}`
|
|
17416
17712
|
});
|
|
17417
17713
|
}).catch((err) => {
|
|
17418
|
-
|
|
17714
|
+
logger8.log({
|
|
17419
17715
|
level: "error",
|
|
17420
17716
|
message: `Failed to set cache for role by id: ${err.message}`
|
|
17421
17717
|
});
|
|
@@ -17430,25 +17726,25 @@ function useRoleRepo() {
|
|
|
17430
17726
|
throw new BadRequestError10("Role name is required.");
|
|
17431
17727
|
}
|
|
17432
17728
|
try {
|
|
17433
|
-
const cacheKey =
|
|
17729
|
+
const cacheKey = makeCacheKey6(namespace_collection, {
|
|
17434
17730
|
name
|
|
17435
17731
|
});
|
|
17436
17732
|
const cached = await getCache(cacheKey);
|
|
17437
17733
|
if (cached) {
|
|
17438
|
-
|
|
17734
|
+
logger8.log({
|
|
17439
17735
|
level: "info",
|
|
17440
17736
|
message: `Cache hit for getRoleByName role: ${cacheKey}`
|
|
17441
17737
|
});
|
|
17442
17738
|
return cached;
|
|
17443
17739
|
}
|
|
17444
17740
|
const data = await collection.findOne({ name });
|
|
17445
|
-
setCache(cacheKey, data).then(() => {
|
|
17446
|
-
|
|
17741
|
+
setCache(cacheKey, data, 300, namespace_collection).then(() => {
|
|
17742
|
+
logger8.log({
|
|
17447
17743
|
level: "info",
|
|
17448
17744
|
message: `Cache set for role by name: ${cacheKey}`
|
|
17449
17745
|
});
|
|
17450
17746
|
}).catch((err) => {
|
|
17451
|
-
|
|
17747
|
+
logger8.log({
|
|
17452
17748
|
level: "error",
|
|
17453
17749
|
message: `Failed to set cache for role by name: ${err.message}`
|
|
17454
17750
|
});
|
|
@@ -17491,10 +17787,10 @@ function useRoleRepo() {
|
|
|
17491
17787
|
}
|
|
17492
17788
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
17493
17789
|
cacheKeyOptions.sort = JSON.stringify(sort);
|
|
17494
|
-
const cacheKey =
|
|
17790
|
+
const cacheKey = makeCacheKey6(namespace_collection, cacheKeyOptions);
|
|
17495
17791
|
const cached = await getCache(cacheKey);
|
|
17496
17792
|
if (cached) {
|
|
17497
|
-
|
|
17793
|
+
logger8.log({
|
|
17498
17794
|
level: "info",
|
|
17499
17795
|
message: `Cache hit for getRoles: ${cacheKey}`
|
|
17500
17796
|
});
|
|
@@ -17509,20 +17805,20 @@ function useRoleRepo() {
|
|
|
17509
17805
|
]).toArray();
|
|
17510
17806
|
const length = await collection.countDocuments(query);
|
|
17511
17807
|
const data = paginate4(items, page, limit, length);
|
|
17512
|
-
setCache(cacheKey, data).then(() => {
|
|
17513
|
-
|
|
17808
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
17809
|
+
logger8.log({
|
|
17514
17810
|
level: "info",
|
|
17515
17811
|
message: `Cache set for getRoles: ${cacheKey}`
|
|
17516
17812
|
});
|
|
17517
17813
|
}).catch((err) => {
|
|
17518
|
-
|
|
17814
|
+
logger8.log({
|
|
17519
17815
|
level: "error",
|
|
17520
17816
|
message: `Failed to set cache for getRoles: ${err.message}`
|
|
17521
17817
|
});
|
|
17522
17818
|
});
|
|
17523
17819
|
return data;
|
|
17524
17820
|
} catch (error) {
|
|
17525
|
-
|
|
17821
|
+
logger8.log({ level: "error", message: `${error}` });
|
|
17526
17822
|
throw error;
|
|
17527
17823
|
}
|
|
17528
17824
|
}
|
|
@@ -17910,12 +18206,12 @@ function useUserService() {
|
|
|
17910
18206
|
}
|
|
17911
18207
|
const session = useAtlas8.getClient()?.startSession();
|
|
17912
18208
|
session?.startTransaction();
|
|
17913
|
-
const cacheKey =
|
|
18209
|
+
const cacheKey = makeCacheKey7("users", { user: _id });
|
|
17914
18210
|
try {
|
|
17915
|
-
|
|
17916
|
-
|
|
18211
|
+
useCache7().delCache(cacheKey).then(() => {
|
|
18212
|
+
logger9.info(`Cache cleared for user: ${_id}`);
|
|
17917
18213
|
}).catch((error) => {
|
|
17918
|
-
|
|
18214
|
+
logger9.error(`Failed to clear cache for user: ${_id}`, error);
|
|
17919
18215
|
});
|
|
17920
18216
|
await _updateName({ _id, firstName, lastName }, session);
|
|
17921
18217
|
await updateMemberName(
|
|
@@ -18481,7 +18777,7 @@ function useAuthController() {
|
|
|
18481
18777
|
}
|
|
18482
18778
|
|
|
18483
18779
|
// src/services/file.service.ts
|
|
18484
|
-
import { logger as
|
|
18780
|
+
import { logger as logger10, useS3 as useS32, useAtlas as useAtlas9 } from "@goweekdays/utils";
|
|
18485
18781
|
import cron from "node-cron";
|
|
18486
18782
|
function useFileService() {
|
|
18487
18783
|
const {
|
|
@@ -18542,12 +18838,12 @@ function useFileService() {
|
|
|
18542
18838
|
const file = files[index];
|
|
18543
18839
|
try {
|
|
18544
18840
|
await deleteFile(file._id.toString());
|
|
18545
|
-
await
|
|
18841
|
+
await logger10.log({
|
|
18546
18842
|
level: "info",
|
|
18547
18843
|
message: "Successfully deleted draft files."
|
|
18548
18844
|
});
|
|
18549
18845
|
} catch (error) {
|
|
18550
|
-
|
|
18846
|
+
logger10.log({
|
|
18551
18847
|
level: "info",
|
|
18552
18848
|
message: "Successfully deleted draft files."
|
|
18553
18849
|
});
|
|
@@ -18801,16 +19097,33 @@ import { ObjectId as ObjectId16 } from "mongodb";
|
|
|
18801
19097
|
import {
|
|
18802
19098
|
BadRequestError as BadRequestError17,
|
|
18803
19099
|
InternalServerError as InternalServerError15,
|
|
18804
|
-
logger as
|
|
19100
|
+
logger as logger11,
|
|
19101
|
+
makeCacheKey as makeCacheKey8,
|
|
18805
19102
|
paginate as paginate5,
|
|
18806
|
-
useAtlas as useAtlas10
|
|
19103
|
+
useAtlas as useAtlas10,
|
|
19104
|
+
useCache as useCache8
|
|
18807
19105
|
} from "@goweekdays/utils";
|
|
18808
19106
|
function useEntityRepo() {
|
|
18809
19107
|
const db = useAtlas10.getDb();
|
|
18810
19108
|
if (!db) {
|
|
18811
19109
|
throw new InternalServerError15("Unable to connect to server.");
|
|
18812
19110
|
}
|
|
18813
|
-
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
|
+
}
|
|
18814
19127
|
async function createIndex() {
|
|
18815
19128
|
try {
|
|
18816
19129
|
await collection.createIndex({ name: 1 });
|
|
@@ -18832,9 +19145,10 @@ function useEntityRepo() {
|
|
|
18832
19145
|
const res = await collection.insertOne(value, {
|
|
18833
19146
|
session
|
|
18834
19147
|
});
|
|
19148
|
+
delCachedData();
|
|
18835
19149
|
return res.insertedId.toString();
|
|
18836
19150
|
} catch (error) {
|
|
18837
|
-
|
|
19151
|
+
logger11.log({ level: "error", message: `${error}` });
|
|
18838
19152
|
const isDuplicated = error.message.includes("duplicate");
|
|
18839
19153
|
if (isDuplicated) {
|
|
18840
19154
|
throw new BadRequestError17("Entity name already exists.");
|
|
@@ -18854,7 +19168,22 @@ function useEntityRepo() {
|
|
|
18854
19168
|
if (search) {
|
|
18855
19169
|
query.$text = { $search: search };
|
|
18856
19170
|
}
|
|
19171
|
+
const cacheKey = makeCacheKey8(namespace_collection, {
|
|
19172
|
+
search,
|
|
19173
|
+
page,
|
|
19174
|
+
limit,
|
|
19175
|
+
sort: JSON.stringify(sort),
|
|
19176
|
+
status: "active"
|
|
19177
|
+
});
|
|
18857
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
|
+
}
|
|
18858
19187
|
const items = await collection.aggregate([
|
|
18859
19188
|
{ $match: query },
|
|
18860
19189
|
{ $sort: sort },
|
|
@@ -18862,9 +19191,21 @@ function useEntityRepo() {
|
|
|
18862
19191
|
{ $limit: limit }
|
|
18863
19192
|
]).toArray();
|
|
18864
19193
|
const length = await collection.countDocuments(query);
|
|
18865
|
-
|
|
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;
|
|
18866
19207
|
} catch (error) {
|
|
18867
|
-
|
|
19208
|
+
logger11.log({ level: "error", message: `${error}` });
|
|
18868
19209
|
throw error;
|
|
18869
19210
|
}
|
|
18870
19211
|
}
|
|
@@ -18887,6 +19228,7 @@ function useEntityRepo() {
|
|
|
18887
19228
|
// Dynamically set the field
|
|
18888
19229
|
{ session }
|
|
18889
19230
|
);
|
|
19231
|
+
delCachedData();
|
|
18890
19232
|
return `Successfully updated entity ${field}.`;
|
|
18891
19233
|
} catch (error) {
|
|
18892
19234
|
throw new InternalServerError15(`Failed to update entity ${field}.`);
|
|
@@ -18899,10 +19241,12 @@ function useEntityRepo() {
|
|
|
18899
19241
|
throw new BadRequestError17("Invalid entity ID.");
|
|
18900
19242
|
}
|
|
18901
19243
|
try {
|
|
18902
|
-
|
|
19244
|
+
const result = await collection.updateOne(
|
|
18903
19245
|
{ _id },
|
|
18904
19246
|
{ $set: { status: "deleted", deletedAt: (/* @__PURE__ */ new Date()).toISOString() } }
|
|
18905
19247
|
);
|
|
19248
|
+
delCachedData();
|
|
19249
|
+
return result;
|
|
18906
19250
|
} catch (error) {
|
|
18907
19251
|
return Promise.reject(error);
|
|
18908
19252
|
}
|
|
@@ -19115,7 +19459,7 @@ function MSubscription(value) {
|
|
|
19115
19459
|
}
|
|
19116
19460
|
|
|
19117
19461
|
// src/repositories/subscription.repository.ts
|
|
19118
|
-
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";
|
|
19119
19463
|
import { ObjectId as ObjectId18 } from "mongodb";
|
|
19120
19464
|
import Joi10 from "joi";
|
|
19121
19465
|
function useSubscriptionRepo() {
|
|
@@ -19123,7 +19467,22 @@ function useSubscriptionRepo() {
|
|
|
19123
19467
|
if (!db) {
|
|
19124
19468
|
throw new BadRequestError20("Unable to connect to server.");
|
|
19125
19469
|
}
|
|
19126
|
-
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
|
+
}
|
|
19127
19486
|
async function createIndex() {
|
|
19128
19487
|
try {
|
|
19129
19488
|
await collection.createIndexes([
|
|
@@ -19154,6 +19513,7 @@ function useSubscriptionRepo() {
|
|
|
19154
19513
|
try {
|
|
19155
19514
|
value = MSubscription(value);
|
|
19156
19515
|
const res = await collection.insertOne(value, { session });
|
|
19516
|
+
delCachedData();
|
|
19157
19517
|
return res.insertedId;
|
|
19158
19518
|
} catch (error) {
|
|
19159
19519
|
throw new BadRequestError20("Failed to create subscription.");
|
|
@@ -19165,20 +19525,66 @@ function useSubscriptionRepo() {
|
|
|
19165
19525
|
} catch (error) {
|
|
19166
19526
|
throw new BadRequestError20("Invalid ID.");
|
|
19167
19527
|
}
|
|
19528
|
+
const cacheKey = makeCacheKey9(namespace_collection, { _id: String(_id) });
|
|
19168
19529
|
try {
|
|
19169
|
-
|
|
19170
|
-
|
|
19171
|
-
|
|
19172
|
-
|
|
19173
|
-
|
|
19174
|
-
|
|
19175
|
-
|
|
19176
|
-
|
|
19177
|
-
|
|
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;
|
|
19553
|
+
} catch (error) {
|
|
19554
|
+
throw new BadRequestError20("Failed to get subscription by ID.");
|
|
19555
|
+
}
|
|
19556
|
+
}
|
|
19557
|
+
async function getByUserId(user) {
|
|
19558
|
+
try {
|
|
19559
|
+
user = new ObjectId18(user);
|
|
19560
|
+
} catch (error) {
|
|
19178
19561
|
throw new BadRequestError20("Invalid user ID.");
|
|
19179
19562
|
}
|
|
19563
|
+
const cacheKey = makeCacheKey9(namespace_collection, { user: String(user) });
|
|
19180
19564
|
try {
|
|
19181
|
-
|
|
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;
|
|
19182
19588
|
} catch (error) {
|
|
19183
19589
|
throw new BadRequestError20("Failed to get subscription by ID.");
|
|
19184
19590
|
}
|
|
@@ -19214,8 +19620,31 @@ function useSubscriptionRepo() {
|
|
|
19214
19620
|
}
|
|
19215
19621
|
}
|
|
19216
19622
|
async function getBySubscriptionId(subscriptionId) {
|
|
19623
|
+
const cacheKey = makeCacheKey9(namespace_collection, { subscriptionId });
|
|
19217
19624
|
try {
|
|
19218
|
-
|
|
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;
|
|
19219
19648
|
} catch (error) {
|
|
19220
19649
|
throw new BadRequestError20(
|
|
19221
19650
|
"Failed to get subscription by subscription ID."
|
|
@@ -19235,7 +19664,22 @@ function useSubscriptionRepo() {
|
|
|
19235
19664
|
if (search) {
|
|
19236
19665
|
query.$text = { $search: search };
|
|
19237
19666
|
}
|
|
19667
|
+
const cacheKey = makeCacheKey9(namespace_collection, {
|
|
19668
|
+
search,
|
|
19669
|
+
page,
|
|
19670
|
+
limit,
|
|
19671
|
+
sort: JSON.stringify(sort),
|
|
19672
|
+
status
|
|
19673
|
+
});
|
|
19238
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
|
+
}
|
|
19239
19683
|
const items = await collection.aggregate([
|
|
19240
19684
|
{ $match: query },
|
|
19241
19685
|
{ $sort: sort },
|
|
@@ -19243,9 +19687,21 @@ function useSubscriptionRepo() {
|
|
|
19243
19687
|
{ $limit: limit }
|
|
19244
19688
|
]).toArray();
|
|
19245
19689
|
const length = await collection.countDocuments(query);
|
|
19246
|
-
|
|
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;
|
|
19247
19703
|
} catch (error) {
|
|
19248
|
-
|
|
19704
|
+
logger12.log({ level: "error", message: `${error}` });
|
|
19249
19705
|
throw error;
|
|
19250
19706
|
}
|
|
19251
19707
|
}
|
|
@@ -19392,10 +19848,10 @@ function useSubscriptionRepo() {
|
|
|
19392
19848
|
},
|
|
19393
19849
|
{ session }
|
|
19394
19850
|
);
|
|
19395
|
-
|
|
19851
|
+
logger12.info(`${res.modifiedCount} subscription updated.`);
|
|
19396
19852
|
return "Successfully updated subscription.";
|
|
19397
19853
|
} catch (error2) {
|
|
19398
|
-
|
|
19854
|
+
logger12.error(`${error2}`);
|
|
19399
19855
|
throw new BadRequestError20("Failed to update subscription.");
|
|
19400
19856
|
}
|
|
19401
19857
|
}
|
|
@@ -19644,18 +20100,18 @@ function useSubscriptionRepo() {
|
|
|
19644
20100
|
}
|
|
19645
20101
|
|
|
19646
20102
|
// src/services/subscription.service.ts
|
|
19647
|
-
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";
|
|
19648
20104
|
|
|
19649
20105
|
// src/repositories/organization.repository.ts
|
|
19650
20106
|
import {
|
|
19651
20107
|
AppError as AppError8,
|
|
19652
20108
|
BadRequestError as BadRequestError22,
|
|
19653
20109
|
InternalServerError as InternalServerError16,
|
|
19654
|
-
logger as
|
|
19655
|
-
makeCacheKey as
|
|
20110
|
+
logger as logger13,
|
|
20111
|
+
makeCacheKey as makeCacheKey10,
|
|
19656
20112
|
paginate as paginate7,
|
|
19657
20113
|
useAtlas as useAtlas12,
|
|
19658
|
-
useCache as
|
|
20114
|
+
useCache as useCache10
|
|
19659
20115
|
} from "@goweekdays/utils";
|
|
19660
20116
|
|
|
19661
20117
|
// src/models/organization.model.ts
|
|
@@ -19710,7 +20166,7 @@ function useOrgRepo() {
|
|
|
19710
20166
|
}
|
|
19711
20167
|
const namespace_collection = "organizations";
|
|
19712
20168
|
const collection = db.collection(namespace_collection);
|
|
19713
|
-
const { getCache, setCache, delNamespace } =
|
|
20169
|
+
const { getCache, setCache, delNamespace } = useCache10();
|
|
19714
20170
|
async function createIndex() {
|
|
19715
20171
|
try {
|
|
19716
20172
|
await collection.createIndex([
|
|
@@ -19746,12 +20202,12 @@ function useOrgRepo() {
|
|
|
19746
20202
|
}
|
|
19747
20203
|
function delCachedData() {
|
|
19748
20204
|
delNamespace(namespace_collection).then(() => {
|
|
19749
|
-
|
|
20205
|
+
logger13.log({
|
|
19750
20206
|
level: "info",
|
|
19751
20207
|
message: `Cache namespace cleared for ${namespace_collection}`
|
|
19752
20208
|
});
|
|
19753
20209
|
}).catch((err) => {
|
|
19754
|
-
|
|
20210
|
+
logger13.log({
|
|
19755
20211
|
level: "error",
|
|
19756
20212
|
message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
|
|
19757
20213
|
});
|
|
@@ -19764,7 +20220,7 @@ function useOrgRepo() {
|
|
|
19764
20220
|
delCachedData();
|
|
19765
20221
|
return res.insertedId;
|
|
19766
20222
|
} catch (error) {
|
|
19767
|
-
|
|
20223
|
+
logger13.log({
|
|
19768
20224
|
level: "error",
|
|
19769
20225
|
message: error.message
|
|
19770
20226
|
});
|
|
@@ -19792,21 +20248,21 @@ function useOrgRepo() {
|
|
|
19792
20248
|
if (search) {
|
|
19793
20249
|
query.$text = { $search: search };
|
|
19794
20250
|
}
|
|
19795
|
-
const cacheKey =
|
|
20251
|
+
const cacheKey = makeCacheKey10(namespace_collection, {
|
|
19796
20252
|
search,
|
|
19797
20253
|
page,
|
|
19798
20254
|
limit,
|
|
19799
20255
|
sort: JSON.stringify(sort),
|
|
19800
20256
|
status
|
|
19801
20257
|
});
|
|
19802
|
-
|
|
20258
|
+
logger13.log({
|
|
19803
20259
|
level: "info",
|
|
19804
20260
|
message: `Cache key for getAll organizations: ${cacheKey}`
|
|
19805
20261
|
});
|
|
19806
20262
|
try {
|
|
19807
20263
|
const cached = await getCache(cacheKey);
|
|
19808
20264
|
if (cached) {
|
|
19809
|
-
|
|
20265
|
+
logger13.log({
|
|
19810
20266
|
level: "info",
|
|
19811
20267
|
message: `Cache hit for getAll organizations: ${cacheKey}`
|
|
19812
20268
|
});
|
|
@@ -19829,20 +20285,20 @@ function useOrgRepo() {
|
|
|
19829
20285
|
]).toArray();
|
|
19830
20286
|
const length = await collection.countDocuments(query);
|
|
19831
20287
|
const data = paginate7(items, page, limit, length);
|
|
19832
|
-
setCache(cacheKey, data).then(() => {
|
|
19833
|
-
|
|
20288
|
+
setCache(cacheKey, data, 600, namespace_collection).then(() => {
|
|
20289
|
+
logger13.log({
|
|
19834
20290
|
level: "info",
|
|
19835
20291
|
message: `Cache set for getAll organizations: ${cacheKey}`
|
|
19836
20292
|
});
|
|
19837
20293
|
}).catch((err) => {
|
|
19838
|
-
|
|
20294
|
+
logger13.log({
|
|
19839
20295
|
level: "error",
|
|
19840
20296
|
message: `Failed to set cache for getAll organizations: ${err.message}`
|
|
19841
20297
|
});
|
|
19842
20298
|
});
|
|
19843
20299
|
return data;
|
|
19844
20300
|
} catch (error) {
|
|
19845
|
-
|
|
20301
|
+
logger13.log({ level: "error", message: `${error}` });
|
|
19846
20302
|
throw error;
|
|
19847
20303
|
}
|
|
19848
20304
|
}
|
|
@@ -19852,11 +20308,11 @@ function useOrgRepo() {
|
|
|
19852
20308
|
} catch (error) {
|
|
19853
20309
|
throw new BadRequestError22("Invalid ID.");
|
|
19854
20310
|
}
|
|
19855
|
-
const cacheKey =
|
|
20311
|
+
const cacheKey = makeCacheKey10(namespace_collection, { _id: String(_id) });
|
|
19856
20312
|
try {
|
|
19857
20313
|
const cached = await getCache(cacheKey);
|
|
19858
20314
|
if (cached) {
|
|
19859
|
-
|
|
20315
|
+
logger13.log({
|
|
19860
20316
|
level: "info",
|
|
19861
20317
|
message: `Cache hit for getById organization: ${cacheKey}`
|
|
19862
20318
|
});
|
|
@@ -19866,13 +20322,13 @@ function useOrgRepo() {
|
|
|
19866
20322
|
if (!result) {
|
|
19867
20323
|
throw new BadRequestError22("Organization not found.");
|
|
19868
20324
|
}
|
|
19869
|
-
setCache(cacheKey, result).then(() => {
|
|
19870
|
-
|
|
20325
|
+
setCache(cacheKey, result, 300, namespace_collection).then(() => {
|
|
20326
|
+
logger13.log({
|
|
19871
20327
|
level: "info",
|
|
19872
20328
|
message: `Cache set for organization by id: ${cacheKey}`
|
|
19873
20329
|
});
|
|
19874
20330
|
}).catch((err) => {
|
|
19875
|
-
|
|
20331
|
+
logger13.log({
|
|
19876
20332
|
level: "error",
|
|
19877
20333
|
message: `Failed to set cache for organization by id: ${err.message}`
|
|
19878
20334
|
});
|
|
@@ -19887,11 +20343,11 @@ function useOrgRepo() {
|
|
|
19887
20343
|
}
|
|
19888
20344
|
}
|
|
19889
20345
|
async function getByName(name) {
|
|
19890
|
-
const cacheKey =
|
|
20346
|
+
const cacheKey = makeCacheKey10(namespace_collection, { name });
|
|
19891
20347
|
try {
|
|
19892
20348
|
const cached = await getCache(cacheKey);
|
|
19893
20349
|
if (cached) {
|
|
19894
|
-
|
|
20350
|
+
logger13.log({
|
|
19895
20351
|
level: "info",
|
|
19896
20352
|
message: `Cache hit for getByName organization: ${cacheKey}`
|
|
19897
20353
|
});
|
|
@@ -19901,13 +20357,13 @@ function useOrgRepo() {
|
|
|
19901
20357
|
if (!result) {
|
|
19902
20358
|
throw new BadRequestError22("Organization not found.");
|
|
19903
20359
|
}
|
|
19904
|
-
setCache(cacheKey, result).then(() => {
|
|
19905
|
-
|
|
20360
|
+
setCache(cacheKey, result, 300, namespace_collection).then(() => {
|
|
20361
|
+
logger13.log({
|
|
19906
20362
|
level: "info",
|
|
19907
20363
|
message: `Cache set for organization by name: ${cacheKey}`
|
|
19908
20364
|
});
|
|
19909
20365
|
}).catch((err) => {
|
|
19910
|
-
|
|
20366
|
+
logger13.log({
|
|
19911
20367
|
level: "error",
|
|
19912
20368
|
message: `Failed to set cache for organization by name: ${err.message}`
|
|
19913
20369
|
});
|
|
@@ -19977,7 +20433,7 @@ function useOrgRepo() {
|
|
|
19977
20433
|
}
|
|
19978
20434
|
|
|
19979
20435
|
// src/repositories/address.repository.ts
|
|
19980
|
-
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";
|
|
19981
20437
|
|
|
19982
20438
|
// src/models/address.model.ts
|
|
19983
20439
|
import { BadRequestError as BadRequestError23 } from "@goweekdays/utils";
|
|
@@ -20031,7 +20487,22 @@ function useAddressRepo() {
|
|
|
20031
20487
|
if (!db) {
|
|
20032
20488
|
throw new BadRequestError24("Unable to connect to server.");
|
|
20033
20489
|
}
|
|
20034
|
-
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
|
+
}
|
|
20035
20506
|
async function createIndex() {
|
|
20036
20507
|
try {
|
|
20037
20508
|
await collection.createIndexes([
|
|
@@ -20047,6 +20518,7 @@ function useAddressRepo() {
|
|
|
20047
20518
|
try {
|
|
20048
20519
|
value = MAddress(value);
|
|
20049
20520
|
const res = await collection.insertOne(value, { session });
|
|
20521
|
+
delCachedData();
|
|
20050
20522
|
return res.insertedId;
|
|
20051
20523
|
} catch (error) {
|
|
20052
20524
|
throw new BadRequestError24("Failed to create address.");
|
|
@@ -20071,6 +20543,7 @@ function useAddressRepo() {
|
|
|
20071
20543
|
{ $set: value },
|
|
20072
20544
|
{ session, upsert: true }
|
|
20073
20545
|
);
|
|
20546
|
+
delCachedData();
|
|
20074
20547
|
return "Successfully updated address.";
|
|
20075
20548
|
} catch (error) {
|
|
20076
20549
|
throw new BadRequestError24("Failed to update address.");
|
|
@@ -20082,8 +20555,31 @@ function useAddressRepo() {
|
|
|
20082
20555
|
} catch (error) {
|
|
20083
20556
|
throw new BadRequestError24("Invalid user ID.");
|
|
20084
20557
|
}
|
|
20558
|
+
const cacheKey = makeCacheKey11(namespace_collection, { user: String(user) });
|
|
20085
20559
|
try {
|
|
20086
|
-
|
|
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;
|
|
20087
20583
|
} catch (error) {
|
|
20088
20584
|
throw new BadRequestError24("Failed to get address by ID.");
|
|
20089
20585
|
}
|
|
@@ -20094,8 +20590,31 @@ function useAddressRepo() {
|
|
|
20094
20590
|
} catch (error) {
|
|
20095
20591
|
throw new BadRequestError24("Invalid orgId.");
|
|
20096
20592
|
}
|
|
20593
|
+
const cacheKey = makeCacheKey11(namespace_collection, { org: String(org) });
|
|
20097
20594
|
try {
|
|
20098
|
-
|
|
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;
|
|
20099
20618
|
} catch (error) {
|
|
20100
20619
|
throw new BadRequestError24("Failed to get address by orgId.");
|
|
20101
20620
|
}
|
|
@@ -20113,9 +20632,11 @@ function useAddressRepo() {
|
|
|
20113
20632
|
import {
|
|
20114
20633
|
BadRequestError as BadRequestError26,
|
|
20115
20634
|
InternalServerError as InternalServerError17,
|
|
20116
|
-
logger as
|
|
20635
|
+
logger as logger15,
|
|
20636
|
+
makeCacheKey as makeCacheKey12,
|
|
20117
20637
|
paginate as paginate8,
|
|
20118
|
-
useAtlas as useAtlas14
|
|
20638
|
+
useAtlas as useAtlas14,
|
|
20639
|
+
useCache as useCache12
|
|
20119
20640
|
} from "@goweekdays/utils";
|
|
20120
20641
|
|
|
20121
20642
|
// src/validations/promo-code.schema.ts
|
|
@@ -20173,7 +20694,22 @@ function usePromoCodeRepo() {
|
|
|
20173
20694
|
if (!db) {
|
|
20174
20695
|
throw new InternalServerError17("Unable to connect to server.");
|
|
20175
20696
|
}
|
|
20176
|
-
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
|
+
}
|
|
20177
20713
|
async function createIndex() {
|
|
20178
20714
|
try {
|
|
20179
20715
|
await collection.createIndexes([
|
|
@@ -20199,8 +20735,9 @@ function usePromoCodeRepo() {
|
|
|
20199
20735
|
try {
|
|
20200
20736
|
value = MPromoCode(value);
|
|
20201
20737
|
await collection.insertOne(value);
|
|
20738
|
+
delCachedData();
|
|
20202
20739
|
} catch (error) {
|
|
20203
|
-
|
|
20740
|
+
logger15.log({ level: "error", message: `${error}` });
|
|
20204
20741
|
const isDuplicated = error.message.includes("duplicate");
|
|
20205
20742
|
if (isDuplicated) {
|
|
20206
20743
|
throw new BadRequestError26("Promo code already exists.");
|
|
@@ -20225,8 +20762,31 @@ function usePromoCodeRepo() {
|
|
|
20225
20762
|
} else if (assigned === false) {
|
|
20226
20763
|
query.assignedTo = { $in: [null, ""] };
|
|
20227
20764
|
}
|
|
20765
|
+
const cacheKey = makeCacheKey12(namespace_collection, { code, type: type || "default", assigned: assigned?.toString() || "any" });
|
|
20228
20766
|
try {
|
|
20229
|
-
|
|
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;
|
|
20230
20790
|
} catch (error2) {
|
|
20231
20791
|
throw new InternalServerError17("Internal server error.");
|
|
20232
20792
|
}
|
|
@@ -20244,8 +20804,31 @@ function usePromoCodeRepo() {
|
|
|
20244
20804
|
} catch (error2) {
|
|
20245
20805
|
throw new BadRequestError26("Invalid ID.");
|
|
20246
20806
|
}
|
|
20807
|
+
const cacheKey = makeCacheKey12(namespace_collection, { _id: String(_id) });
|
|
20247
20808
|
try {
|
|
20248
|
-
|
|
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;
|
|
20249
20832
|
} catch (error2) {
|
|
20250
20833
|
throw new InternalServerError17("Internal server error.");
|
|
20251
20834
|
}
|
|
@@ -20267,7 +20850,23 @@ function usePromoCodeRepo() {
|
|
|
20267
20850
|
if (type) {
|
|
20268
20851
|
query.type = type;
|
|
20269
20852
|
}
|
|
20853
|
+
const cacheKey = makeCacheKey12(namespace_collection, {
|
|
20854
|
+
search,
|
|
20855
|
+
page,
|
|
20856
|
+
limit,
|
|
20857
|
+
sort: JSON.stringify(sort),
|
|
20858
|
+
status,
|
|
20859
|
+
type
|
|
20860
|
+
});
|
|
20270
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
|
+
}
|
|
20271
20870
|
const items = await collection.aggregate([
|
|
20272
20871
|
{ $match: query },
|
|
20273
20872
|
{ $sort: sort },
|
|
@@ -20275,9 +20874,21 @@ function usePromoCodeRepo() {
|
|
|
20275
20874
|
{ $limit: limit }
|
|
20276
20875
|
]).toArray();
|
|
20277
20876
|
const length = await collection.countDocuments(query);
|
|
20278
|
-
|
|
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;
|
|
20279
20890
|
} catch (error) {
|
|
20280
|
-
|
|
20891
|
+
logger15.log({ level: "error", message: `${error}` });
|
|
20281
20892
|
throw new InternalServerError17("Internal server error.");
|
|
20282
20893
|
}
|
|
20283
20894
|
}
|
|
@@ -20301,6 +20912,7 @@ function usePromoCodeRepo() {
|
|
|
20301
20912
|
{ $set: { assignedTo: user } },
|
|
20302
20913
|
{ session }
|
|
20303
20914
|
);
|
|
20915
|
+
delCachedData();
|
|
20304
20916
|
} catch (error2) {
|
|
20305
20917
|
throw new InternalServerError17("Internal server error.");
|
|
20306
20918
|
}
|
|
@@ -20323,7 +20935,7 @@ import Joi15 from "joi";
|
|
|
20323
20935
|
import {
|
|
20324
20936
|
BadRequestError as BadRequestError28,
|
|
20325
20937
|
InternalServerError as InternalServerError18,
|
|
20326
|
-
logger as
|
|
20938
|
+
logger as logger16,
|
|
20327
20939
|
paginate as paginate9,
|
|
20328
20940
|
useAtlas as useAtlas15
|
|
20329
20941
|
} from "@goweekdays/utils";
|
|
@@ -20458,7 +21070,7 @@ function useInvoiceRepo() {
|
|
|
20458
21070
|
value = createInvoice(value);
|
|
20459
21071
|
await collection.insertOne(value, { session });
|
|
20460
21072
|
} catch (error) {
|
|
20461
|
-
|
|
21073
|
+
logger16.log({ level: "error", message: `${error}` });
|
|
20462
21074
|
const isDuplicated = error.message.includes("duplicate");
|
|
20463
21075
|
if (isDuplicated) {
|
|
20464
21076
|
throw new BadRequestError28("Invoice already exists.");
|
|
@@ -20591,7 +21203,7 @@ function useInvoiceRepo() {
|
|
|
20591
21203
|
}
|
|
20592
21204
|
|
|
20593
21205
|
// src/repositories/counter.repository.ts
|
|
20594
|
-
import { useAtlas as useAtlas16 } from "@goweekdays/utils";
|
|
21206
|
+
import { useAtlas as useAtlas16, useCache as useCache13, makeCacheKey as makeCacheKey13, logger as logger17 } from "@goweekdays/utils";
|
|
20595
21207
|
|
|
20596
21208
|
// src/models/counter.model.ts
|
|
20597
21209
|
import { BadRequestError as BadRequestError29 } from "@goweekdays/utils";
|
|
@@ -20633,7 +21245,22 @@ function useCounterRepo() {
|
|
|
20633
21245
|
if (!db) {
|
|
20634
21246
|
throw new Error("Unable to connect to server.");
|
|
20635
21247
|
}
|
|
21248
|
+
const namespace_collection = "counters";
|
|
20636
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
|
+
}
|
|
20637
21264
|
async function createIndex() {
|
|
20638
21265
|
try {
|
|
20639
21266
|
await collection.createIndexes([
|
|
@@ -20662,6 +21289,7 @@ function useCounterRepo() {
|
|
|
20662
21289
|
try {
|
|
20663
21290
|
const value = createCounter({ type });
|
|
20664
21291
|
await collection.insertOne(value);
|
|
21292
|
+
delCachedData();
|
|
20665
21293
|
} catch (error) {
|
|
20666
21294
|
throw new Error("Failed to add counter.");
|
|
20667
21295
|
}
|
|
@@ -20673,13 +21301,37 @@ function useCounterRepo() {
|
|
|
20673
21301
|
{ $inc: { count: 1 } },
|
|
20674
21302
|
{ session }
|
|
20675
21303
|
);
|
|
21304
|
+
delCachedData();
|
|
20676
21305
|
} catch (error) {
|
|
20677
21306
|
throw new Error(`Failed to increment ${type} counter.`);
|
|
20678
21307
|
}
|
|
20679
21308
|
}
|
|
20680
21309
|
async function getByType(type) {
|
|
21310
|
+
const cacheKey = makeCacheKey13(namespace_collection, { type });
|
|
20681
21311
|
try {
|
|
20682
|
-
|
|
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;
|
|
20683
21335
|
} catch (error) {
|
|
20684
21336
|
throw new Error("Failed to get counter.");
|
|
20685
21337
|
}
|
|
@@ -20697,7 +21349,7 @@ function useCounterRepo() {
|
|
|
20697
21349
|
import {
|
|
20698
21350
|
BadRequestError as BadRequestError30,
|
|
20699
21351
|
InternalServerError as InternalServerError19,
|
|
20700
|
-
logger as
|
|
21352
|
+
logger as logger18,
|
|
20701
21353
|
paginate as paginate10,
|
|
20702
21354
|
useAtlas as useAtlas17
|
|
20703
21355
|
} from "@goweekdays/utils";
|
|
@@ -20742,7 +21394,7 @@ function usePaymentRepo() {
|
|
|
20742
21394
|
value = createPayment(value);
|
|
20743
21395
|
await collection.insertOne(value, { session });
|
|
20744
21396
|
} catch (error) {
|
|
20745
|
-
|
|
21397
|
+
logger18.log({ level: "error", message: `${error}` });
|
|
20746
21398
|
const isDuplicated = error.message.includes("duplicate");
|
|
20747
21399
|
if (isDuplicated) {
|
|
20748
21400
|
throw new BadRequestError30("Payment already exists.");
|
|
@@ -20787,7 +21439,7 @@ function usePaymentRepo() {
|
|
|
20787
21439
|
const length = await collection.countDocuments(query);
|
|
20788
21440
|
return paginate10(items, page, limit, length);
|
|
20789
21441
|
} catch (error) {
|
|
20790
|
-
|
|
21442
|
+
logger18.log({ level: "error", message: `${error}` });
|
|
20791
21443
|
throw new InternalServerError19("Internal server error.");
|
|
20792
21444
|
}
|
|
20793
21445
|
}
|
|
@@ -20813,7 +21465,7 @@ function usePaymentRepo() {
|
|
|
20813
21465
|
}
|
|
20814
21466
|
|
|
20815
21467
|
// src/repositories/price.repository.ts
|
|
20816
|
-
import { useAtlas as useAtlas18 } from "@goweekdays/utils";
|
|
21468
|
+
import { useAtlas as useAtlas18, useCache as useCache14, makeCacheKey as makeCacheKey14, logger as logger19 } from "@goweekdays/utils";
|
|
20817
21469
|
|
|
20818
21470
|
// src/models/price.model.ts
|
|
20819
21471
|
import { BadRequestError as BadRequestError31 } from "@goweekdays/utils";
|
|
@@ -20864,7 +21516,22 @@ function usePriceRepo() {
|
|
|
20864
21516
|
if (!db) {
|
|
20865
21517
|
throw new Error("Unable to connect to server.");
|
|
20866
21518
|
}
|
|
21519
|
+
const namespace_collection = "prices";
|
|
20867
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
|
+
}
|
|
20868
21535
|
async function createIndex() {
|
|
20869
21536
|
try {
|
|
20870
21537
|
await collection.createIndexes([
|
|
@@ -20893,6 +21560,7 @@ function usePriceRepo() {
|
|
|
20893
21560
|
try {
|
|
20894
21561
|
value = createPrice(value);
|
|
20895
21562
|
await collection.insertOne(value);
|
|
21563
|
+
delCachedData();
|
|
20896
21564
|
} catch (error) {
|
|
20897
21565
|
throw new Error("Failed to add price.");
|
|
20898
21566
|
}
|
|
@@ -20904,13 +21572,37 @@ function usePriceRepo() {
|
|
|
20904
21572
|
{ $set: { saleValue: value.saleValue, saleExpiry: value.saleExpiry } },
|
|
20905
21573
|
{ session }
|
|
20906
21574
|
);
|
|
21575
|
+
delCachedData();
|
|
20907
21576
|
} catch (error) {
|
|
20908
21577
|
throw new Error(`Failed to set ${value.type} sale price.`);
|
|
20909
21578
|
}
|
|
20910
21579
|
}
|
|
20911
21580
|
async function getByNameType(name, type) {
|
|
21581
|
+
const cacheKey = makeCacheKey14(namespace_collection, { name, type });
|
|
20912
21582
|
try {
|
|
20913
|
-
|
|
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;
|
|
20914
21606
|
} catch (error) {
|
|
20915
21607
|
throw new Error("Failed to get price.");
|
|
20916
21608
|
}
|
|
@@ -21079,6 +21771,7 @@ function usePaypalService() {
|
|
|
21079
21771
|
}
|
|
21080
21772
|
|
|
21081
21773
|
// src/services/subscription.service.ts
|
|
21774
|
+
import { useJournalTypeRepo, useLedgerTypeRepo } from "@goweekdays/finance";
|
|
21082
21775
|
function useSubscriptionService() {
|
|
21083
21776
|
const {
|
|
21084
21777
|
getByUserId: _getByUserId,
|
|
@@ -21086,7 +21779,6 @@ function useSubscriptionService() {
|
|
|
21086
21779
|
getByOrgId: _getByOrgId,
|
|
21087
21780
|
getDueSubscriptions,
|
|
21088
21781
|
processSuccessfulPayment,
|
|
21089
|
-
markSubscriptionAsFailed,
|
|
21090
21782
|
updateSeatsById: _updateSeatsById,
|
|
21091
21783
|
getById: _getById,
|
|
21092
21784
|
updateMaxSeatsById,
|
|
@@ -21145,6 +21837,8 @@ function useSubscriptionService() {
|
|
|
21145
21837
|
nonProratedCost: formatAmount(nonProratedCost)
|
|
21146
21838
|
};
|
|
21147
21839
|
}
|
|
21840
|
+
const { add: addLedgerType } = useLedgerTypeRepo();
|
|
21841
|
+
const { add: addJournalType } = useJournalTypeRepo();
|
|
21148
21842
|
async function subscribe(value) {
|
|
21149
21843
|
const session = useAtlas19.getClient()?.startSession();
|
|
21150
21844
|
session?.startTransaction();
|
|
@@ -21187,6 +21881,14 @@ function useSubscriptionService() {
|
|
|
21187
21881
|
session
|
|
21188
21882
|
);
|
|
21189
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
|
+
);
|
|
21190
21892
|
const description = "GoWeekdays Organization Monthly Subscription.";
|
|
21191
21893
|
const monthlySubscriptionPrice = await getByNameType(
|
|
21192
21894
|
"organization-subscription",
|
|
@@ -21677,7 +22379,7 @@ function useSubscriptionService() {
|
|
|
21677
22379
|
while (true) {
|
|
21678
22380
|
const subscriptions = await getDueSubscriptions(batchSize);
|
|
21679
22381
|
if (subscriptions.length === 0) {
|
|
21680
|
-
|
|
22382
|
+
logger20.log({
|
|
21681
22383
|
level: "info",
|
|
21682
22384
|
message: "No more subscriptions to process."
|
|
21683
22385
|
});
|
|
@@ -21817,14 +22519,14 @@ function useSubscriptionService() {
|
|
|
21817
22519
|
);
|
|
21818
22520
|
await session?.commitTransaction();
|
|
21819
22521
|
}
|
|
21820
|
-
|
|
22522
|
+
logger20.log({
|
|
21821
22523
|
level: "info",
|
|
21822
22524
|
message: `Processed subscription ${sub._id} successfully.`
|
|
21823
22525
|
});
|
|
21824
22526
|
return;
|
|
21825
22527
|
} catch (error) {
|
|
21826
22528
|
await session?.abortTransaction();
|
|
21827
|
-
|
|
22529
|
+
logger20.log({
|
|
21828
22530
|
level: "error",
|
|
21829
22531
|
message: `Failed to process ${sub._id}: ${error}`
|
|
21830
22532
|
});
|
|
@@ -21836,7 +22538,7 @@ function useSubscriptionService() {
|
|
|
21836
22538
|
}
|
|
21837
22539
|
})
|
|
21838
22540
|
);
|
|
21839
|
-
|
|
22541
|
+
logger20.log({
|
|
21840
22542
|
level: "info",
|
|
21841
22543
|
message: "Processed a batch of subscriptions."
|
|
21842
22544
|
});
|
|
@@ -22133,7 +22835,7 @@ function useSubscriptionService() {
|
|
|
22133
22835
|
await session?.commitTransaction();
|
|
22134
22836
|
} catch (error2) {
|
|
22135
22837
|
await session?.abortTransaction();
|
|
22136
|
-
|
|
22838
|
+
logger20.log({
|
|
22137
22839
|
level: "error",
|
|
22138
22840
|
message: `Failed to update subscription seats: ${error2}`
|
|
22139
22841
|
});
|
|
@@ -22334,7 +23036,7 @@ function useSubscriptionService() {
|
|
|
22334
23036
|
await session?.commitTransaction();
|
|
22335
23037
|
} catch (error2) {
|
|
22336
23038
|
await session?.abortTransaction();
|
|
22337
|
-
|
|
23039
|
+
logger20.log({
|
|
22338
23040
|
level: "error",
|
|
22339
23041
|
message: `Failed to update subscription seats: ${error2}`
|
|
22340
23042
|
});
|
|
@@ -22435,7 +23137,7 @@ function useSubscriptionService() {
|
|
|
22435
23137
|
await session?.commitTransaction();
|
|
22436
23138
|
} catch (error) {
|
|
22437
23139
|
await session?.abortTransaction();
|
|
22438
|
-
|
|
23140
|
+
logger20.log({
|
|
22439
23141
|
level: "error",
|
|
22440
23142
|
message: `Failed to process subscription payment: ${error}`
|
|
22441
23143
|
});
|
|
@@ -22938,7 +23640,7 @@ function MPaymentMethod(value) {
|
|
|
22938
23640
|
import {
|
|
22939
23641
|
BadRequestError as BadRequestError36,
|
|
22940
23642
|
InternalServerError as InternalServerError20,
|
|
22941
|
-
logger as
|
|
23643
|
+
logger as logger21,
|
|
22942
23644
|
useAtlas as useAtlas20
|
|
22943
23645
|
} from "@goweekdays/utils";
|
|
22944
23646
|
import { ObjectId as ObjectId30 } from "mongodb";
|
|
@@ -22984,7 +23686,7 @@ function usePaymentMethodRepo() {
|
|
|
22984
23686
|
await collection.insertOne(value, { session });
|
|
22985
23687
|
return "Successfully added payment method.";
|
|
22986
23688
|
} catch (error) {
|
|
22987
|
-
|
|
23689
|
+
logger21.log({ level: "error", message: `${error}` });
|
|
22988
23690
|
const isDuplicated = error.message.includes("duplicate");
|
|
22989
23691
|
if (isDuplicated) {
|
|
22990
23692
|
throw new BadRequestError36("Payment method already exist.");
|
|
@@ -24130,9 +24832,11 @@ import {
|
|
|
24130
24832
|
AppError as AppError11,
|
|
24131
24833
|
BadRequestError as BadRequestError44,
|
|
24132
24834
|
InternalServerError as InternalServerError22,
|
|
24133
|
-
logger as
|
|
24835
|
+
logger as logger22,
|
|
24836
|
+
makeCacheKey as makeCacheKey15,
|
|
24134
24837
|
paginate as paginate11,
|
|
24135
|
-
useAtlas as useAtlas23
|
|
24838
|
+
useAtlas as useAtlas23,
|
|
24839
|
+
useCache as useCache15
|
|
24136
24840
|
} from "@goweekdays/utils";
|
|
24137
24841
|
import { ObjectId as ObjectId32 } from "mongodb";
|
|
24138
24842
|
function useOrderRepo() {
|
|
@@ -24140,7 +24844,22 @@ function useOrderRepo() {
|
|
|
24140
24844
|
if (!db) {
|
|
24141
24845
|
throw new InternalServerError22("Unable to connect to server.");
|
|
24142
24846
|
}
|
|
24143
|
-
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
|
+
}
|
|
24144
24863
|
function createIndex() {
|
|
24145
24864
|
try {
|
|
24146
24865
|
collection.createIndexes([
|
|
@@ -24156,8 +24875,9 @@ function useOrderRepo() {
|
|
|
24156
24875
|
try {
|
|
24157
24876
|
value = MOrder(value);
|
|
24158
24877
|
collection.insertOne(value, { session });
|
|
24878
|
+
delCachedData();
|
|
24159
24879
|
} catch (error) {
|
|
24160
|
-
|
|
24880
|
+
logger22.log({ level: "error", message: `${error}` });
|
|
24161
24881
|
if (error instanceof AppError11) {
|
|
24162
24882
|
throw error;
|
|
24163
24883
|
}
|
|
@@ -24189,7 +24909,24 @@ function useOrderRepo() {
|
|
|
24189
24909
|
throw new BadRequestError44("Invalid subscription ID.");
|
|
24190
24910
|
}
|
|
24191
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
|
+
});
|
|
24192
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
|
+
}
|
|
24193
24930
|
const items = await collection.aggregate([
|
|
24194
24931
|
{ $match: query },
|
|
24195
24932
|
{ $sort: sort },
|
|
@@ -24197,9 +24934,21 @@ function useOrderRepo() {
|
|
|
24197
24934
|
{ $limit: limit }
|
|
24198
24935
|
]).toArray();
|
|
24199
24936
|
const length = await collection.countDocuments(query);
|
|
24200
|
-
|
|
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;
|
|
24201
24950
|
} catch (error) {
|
|
24202
|
-
|
|
24951
|
+
logger22.log({ level: "error", message: `${error}` });
|
|
24203
24952
|
throw new InternalServerError22("Internal server error.");
|
|
24204
24953
|
}
|
|
24205
24954
|
}
|
|
@@ -24255,7 +25004,7 @@ function useOrderController() {
|
|
|
24255
25004
|
// src/services/invoice.service.ts
|
|
24256
25005
|
import {
|
|
24257
25006
|
BadRequestError as BadRequestError46,
|
|
24258
|
-
logger as
|
|
25007
|
+
logger as logger23,
|
|
24259
25008
|
NotFoundError as NotFoundError7,
|
|
24260
25009
|
useAtlas as useAtlas24
|
|
24261
25010
|
} from "@goweekdays/utils";
|
|
@@ -24277,7 +25026,7 @@ function useInvoiceService() {
|
|
|
24277
25026
|
while (true) {
|
|
24278
25027
|
const overdueInvoices = await getOverdueInvoices(BATCH_SIZE);
|
|
24279
25028
|
if (!overdueInvoices.length) {
|
|
24280
|
-
|
|
25029
|
+
logger23.log({
|
|
24281
25030
|
level: "info",
|
|
24282
25031
|
message: "No overdue invoices found."
|
|
24283
25032
|
});
|
|
@@ -24287,21 +25036,21 @@ function useInvoiceService() {
|
|
|
24287
25036
|
overdueInvoices.map(async (invoice) => {
|
|
24288
25037
|
const session = useAtlas24.getClient()?.startSession();
|
|
24289
25038
|
if (!session) {
|
|
24290
|
-
|
|
25039
|
+
logger23.log({
|
|
24291
25040
|
level: "error",
|
|
24292
25041
|
message: "Failed to start session."
|
|
24293
25042
|
});
|
|
24294
25043
|
return;
|
|
24295
25044
|
}
|
|
24296
25045
|
if (!invoice._id) {
|
|
24297
|
-
|
|
25046
|
+
logger23.log({
|
|
24298
25047
|
level: "error",
|
|
24299
25048
|
message: "Invoice ID is missing."
|
|
24300
25049
|
});
|
|
24301
25050
|
return;
|
|
24302
25051
|
}
|
|
24303
25052
|
if (!invoice.metadata?.subscriptionId) {
|
|
24304
|
-
|
|
25053
|
+
logger23.log({
|
|
24305
25054
|
level: "error",
|
|
24306
25055
|
message: "Subscription ID is missing."
|
|
24307
25056
|
});
|
|
@@ -24311,14 +25060,14 @@ function useInvoiceService() {
|
|
|
24311
25060
|
invoice.metadata.subscriptionId
|
|
24312
25061
|
).catch(() => null);
|
|
24313
25062
|
if (!subscription) {
|
|
24314
|
-
|
|
25063
|
+
logger23.log({
|
|
24315
25064
|
level: "error",
|
|
24316
25065
|
message: "Subscription not found."
|
|
24317
25066
|
});
|
|
24318
25067
|
return;
|
|
24319
25068
|
}
|
|
24320
25069
|
if (!subscription._id) {
|
|
24321
|
-
|
|
25070
|
+
logger23.log({
|
|
24322
25071
|
level: "error",
|
|
24323
25072
|
message: "Subscription ID is missing."
|
|
24324
25073
|
});
|
|
@@ -24398,7 +25147,7 @@ function useInvoiceService() {
|
|
|
24398
25147
|
return;
|
|
24399
25148
|
}
|
|
24400
25149
|
} catch (error) {
|
|
24401
|
-
|
|
25150
|
+
logger23.log({
|
|
24402
25151
|
level: "error",
|
|
24403
25152
|
message: String(error)
|
|
24404
25153
|
});
|
|
@@ -24408,7 +25157,7 @@ function useInvoiceService() {
|
|
|
24408
25157
|
}
|
|
24409
25158
|
})
|
|
24410
25159
|
);
|
|
24411
|
-
|
|
25160
|
+
logger23.log({
|
|
24412
25161
|
level: "info",
|
|
24413
25162
|
message: "Successfully processed overdue invoices."
|
|
24414
25163
|
});
|
|
@@ -24420,7 +25169,7 @@ function useInvoiceService() {
|
|
|
24420
25169
|
}
|
|
24421
25170
|
const session = useAtlas24.getClient()?.startSession();
|
|
24422
25171
|
if (!session) {
|
|
24423
|
-
|
|
25172
|
+
logger23.log({
|
|
24424
25173
|
level: "error",
|
|
24425
25174
|
message: "Failed to start session."
|
|
24426
25175
|
});
|
|
@@ -24489,7 +25238,7 @@ function useInvoiceService() {
|
|
|
24489
25238
|
return "Payment processed successfully.";
|
|
24490
25239
|
} catch (error) {
|
|
24491
25240
|
session.abortTransaction();
|
|
24492
|
-
|
|
25241
|
+
logger23.log({
|
|
24493
25242
|
level: "error",
|
|
24494
25243
|
message: String(error)
|
|
24495
25244
|
});
|