@positivegrid/pg-mongoose-schema 28.0.0-beta.3 → 28.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +212 -153
- package/dist/index.d.mts +221 -215
- package/dist/index.mjs +213 -151
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -20,27 +20,23 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
20
20
|
enumerable: true
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
//#endregion
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
let lodash = require("lodash");
|
|
26
|
-
lodash = __toESM(lodash, 1);
|
|
23
|
+
let node_util = require("node:util");
|
|
24
|
+
let es_toolkit_compat = require("es-toolkit/compat");
|
|
27
25
|
let mongoose_lean_virtuals = require("mongoose-lean-virtuals");
|
|
28
26
|
mongoose_lean_virtuals = __toESM(mongoose_lean_virtuals, 1);
|
|
27
|
+
let es_toolkit = require("es-toolkit");
|
|
29
28
|
let mongoose_deep_populate = require("mongoose-deep-populate");
|
|
30
29
|
mongoose_deep_populate = __toESM(mongoose_deep_populate, 1);
|
|
30
|
+
let date_fns = require("date-fns");
|
|
31
31
|
let is_subset = require("is-subset");
|
|
32
32
|
is_subset = __toESM(is_subset, 1);
|
|
33
|
-
let moment = require("moment");
|
|
34
|
-
moment = __toESM(moment, 1);
|
|
35
33
|
let node_crypto = require("node:crypto");
|
|
36
34
|
node_crypto = __toESM(node_crypto, 1);
|
|
37
|
-
let _positivegrid_pg_error = require("@positivegrid/pg-error");
|
|
38
35
|
let is_email = require("is-email");
|
|
39
36
|
is_email = __toESM(is_email, 1);
|
|
40
37
|
let random_string = require("random-string");
|
|
41
38
|
random_string = __toESM(random_string, 1);
|
|
42
39
|
//#region src/models/banks.ts
|
|
43
|
-
(0, debug.default)("model:banks");
|
|
44
40
|
function buildBanks(mongoose) {
|
|
45
41
|
const { Schema } = mongoose;
|
|
46
42
|
const ObjectId = Schema.Types.ObjectId;
|
|
@@ -322,7 +318,10 @@ function buildFeaturedList(mongoose) {
|
|
|
322
318
|
is_shown: true,
|
|
323
319
|
list_for: "jamup"
|
|
324
320
|
};
|
|
325
|
-
const queryObj =
|
|
321
|
+
const queryObj = (0, es_toolkit_compat.has)(reqQuery, "list_for") ? {
|
|
322
|
+
...defaultQuery,
|
|
323
|
+
list_for: reqQuery.list_for
|
|
324
|
+
} : defaultQuery;
|
|
326
325
|
return this.find(queryObj).sort({ order: 1 }).select("-is_shown").lean({ virtuals: true }).exec();
|
|
327
326
|
},
|
|
328
327
|
getLimitedPresetLists(reqQuery) {
|
|
@@ -331,7 +330,10 @@ function buildFeaturedList(mongoose) {
|
|
|
331
330
|
is_shown: true,
|
|
332
331
|
list_for: "jamup"
|
|
333
332
|
};
|
|
334
|
-
const queryObj =
|
|
333
|
+
const queryObj = (0, es_toolkit_compat.has)(reqQuery, "list_for") ? {
|
|
334
|
+
...defaultQuery,
|
|
335
|
+
list_for: reqQuery.list_for
|
|
336
|
+
} : defaultQuery;
|
|
335
337
|
return this.find(queryObj).sort({ order: 1 }).select("-is_shown").lean({ virtuals: true }).exec();
|
|
336
338
|
}
|
|
337
339
|
});
|
|
@@ -345,7 +347,7 @@ function buildFeaturedList(mongoose) {
|
|
|
345
347
|
}
|
|
346
348
|
//#endregion
|
|
347
349
|
//#region src/models/hardware.ts
|
|
348
|
-
const log$7 = (0,
|
|
350
|
+
const log$7 = (0, node_util.debuglog)("model:promo");
|
|
349
351
|
function _identifyHardwareByModel(model) {
|
|
350
352
|
switch (model) {
|
|
351
353
|
case "G1": return "head";
|
|
@@ -356,7 +358,7 @@ function _identifyHardwareByModel(model) {
|
|
|
356
358
|
}
|
|
357
359
|
}
|
|
358
360
|
function _parseHardwareSerialNumber(hwSn) {
|
|
359
|
-
if (
|
|
361
|
+
if (typeof hwSn !== "string") throw new Error(`Invalid hardware series number format: ${hwSn}`);
|
|
360
362
|
if (/^S/.test(hwSn)) {
|
|
361
363
|
const hwModel = hwSn.slice(0, 1);
|
|
362
364
|
const hwWattage = hwSn.slice(1, 4);
|
|
@@ -661,15 +663,15 @@ function buildHardware(mongoose) {
|
|
|
661
663
|
let mostMatchingMeta = {};
|
|
662
664
|
let mostMatchingNumber = 0;
|
|
663
665
|
allMatch.forEach((metaItem) => {
|
|
664
|
-
if (
|
|
665
|
-
const matchItem =
|
|
666
|
+
if (Array.isArray(metaItem.pattern) && metaItem.pattern.length > 0) {
|
|
667
|
+
const matchItem = (0, es_toolkit.intersection)(metaItem.pattern, snPatternArr);
|
|
666
668
|
if (matchItem.length === metaItem.pattern.length && matchItem.length > mostMatchingNumber) {
|
|
667
669
|
mostMatchingMeta = metaItem;
|
|
668
670
|
mostMatchingNumber = matchItem.length;
|
|
669
671
|
}
|
|
670
672
|
}
|
|
671
673
|
});
|
|
672
|
-
if (
|
|
674
|
+
if ((0, es_toolkit_compat.isEmpty)(mostMatchingMeta) || mostMatchingNumber === 0) {
|
|
673
675
|
if (opts.allowEmpty === true) return null;
|
|
674
676
|
throw new Error("Cannot find any activation meta match the SN pattern");
|
|
675
677
|
}
|
|
@@ -910,7 +912,7 @@ function buildOauth(mongoose) {
|
|
|
910
912
|
}
|
|
911
913
|
//#endregion
|
|
912
914
|
//#region src/models/partner.ts
|
|
913
|
-
const log$6 = (0,
|
|
915
|
+
const log$6 = (0, node_util.debuglog)("model:partner");
|
|
914
916
|
const OEM_PROMOTION_TYPE = ["discount_coupon"];
|
|
915
917
|
function _identifyItemTypeBySku(sku) {
|
|
916
918
|
if (/^B(.*)/.test(sku)) return "bundle";
|
|
@@ -1247,8 +1249,8 @@ function buildPartner(mongoose) {
|
|
|
1247
1249
|
});
|
|
1248
1250
|
OemRedeemPromotionSchema.static({ async findRedeemFullfillPromotion(redeemData) {
|
|
1249
1251
|
try {
|
|
1250
|
-
if (!
|
|
1251
|
-
if (!
|
|
1252
|
+
if (!(0, es_toolkit_compat.has)(redeemData, "metadata.OEM_Name")) throw new Error("This is not a OEM redeem code.");
|
|
1253
|
+
if (!(0, es_toolkit_compat.has)(redeemData, "metadata.product_name") || !(0, es_toolkit_compat.has)(redeemData, "metadata.type")) throw new Error("This is not a valid redeem code.");
|
|
1252
1254
|
return this.find({
|
|
1253
1255
|
redeem_product: redeemData.metadata.product_name,
|
|
1254
1256
|
product_type: redeemData.metadata.type,
|
|
@@ -1272,7 +1274,7 @@ function buildPartner(mongoose) {
|
|
|
1272
1274
|
}
|
|
1273
1275
|
//#endregion
|
|
1274
1276
|
//#region src/models/payment.ts
|
|
1275
|
-
const log$5 = (0,
|
|
1277
|
+
const log$5 = (0, node_util.debuglog)("model:payment");
|
|
1276
1278
|
const OEM_FOCUSRITE_SUPPORT_LICENSE = [
|
|
1277
1279
|
{
|
|
1278
1280
|
support_type: {
|
|
@@ -1314,13 +1316,13 @@ function _oemMetaToLicenseName(redeemMeta) {
|
|
|
1314
1316
|
let ret;
|
|
1315
1317
|
switch (redeemMeta.OEM_Name) {
|
|
1316
1318
|
case "focusrite":
|
|
1317
|
-
ret =
|
|
1319
|
+
ret = OEM_FOCUSRITE_SUPPORT_LICENSE.find((o) => (0, is_subset.default)(redeemMeta, o.support_type));
|
|
1318
1320
|
break;
|
|
1319
1321
|
case "Apogee":
|
|
1320
|
-
ret =
|
|
1322
|
+
ret = OEM_APOGEE_SUPPORT_LICENSE.find((o) => (0, is_subset.default)(redeemMeta, o.support_type));
|
|
1321
1323
|
break;
|
|
1322
1324
|
case "ProSonus":
|
|
1323
|
-
ret =
|
|
1325
|
+
ret = OEM_PROSONUS_SUPPORT_LICENSE.find((o) => (0, is_subset.default)(redeemMeta, o.support_type));
|
|
1324
1326
|
break;
|
|
1325
1327
|
default:
|
|
1326
1328
|
log$5("ERROR:_oemMetaToLicenseName %o", redeemMeta);
|
|
@@ -1988,16 +1990,16 @@ function buildPayment(mongoose) {
|
|
|
1988
1990
|
AdditionalPurchaseSchema.index({ exclude_country: 1 });
|
|
1989
1991
|
AdditionalPurchaseSchema.static({
|
|
1990
1992
|
async canPurchaseAdditional(ownedSku, additionalSku) {
|
|
1991
|
-
if (!
|
|
1993
|
+
if (!Array.isArray(ownedSku) || !Array.isArray(additionalSku)) throw new Error("Invalid parameter format!");
|
|
1992
1994
|
const additionalPurchaseData = await this.find({
|
|
1993
1995
|
"additional_purchase.sku": { $in: additionalSku },
|
|
1994
1996
|
status: 1
|
|
1995
1997
|
}).exec();
|
|
1996
1998
|
if (additionalPurchaseData.length <= 0) return true;
|
|
1997
1999
|
let canPurchase = false;
|
|
1998
|
-
|
|
2000
|
+
additionalPurchaseData.forEach((addition) => {
|
|
1999
2001
|
if (addition.rule === "has") {
|
|
2000
|
-
if (
|
|
2002
|
+
if ((0, es_toolkit.difference)(ownedSku, addition.main_product_sku).length < ownedSku.length) canPurchase = true;
|
|
2001
2003
|
}
|
|
2002
2004
|
});
|
|
2003
2005
|
return canPurchase;
|
|
@@ -2009,10 +2011,10 @@ function buildPayment(mongoose) {
|
|
|
2009
2011
|
}).lean().exec();
|
|
2010
2012
|
if (hasAdditionalPurchase.length <= 0) return true;
|
|
2011
2013
|
let hasFulfill = true;
|
|
2012
|
-
|
|
2014
|
+
hasAdditionalPurchase.forEach((addition) => {
|
|
2013
2015
|
if (addition.rule === "has") {
|
|
2014
2016
|
const mainSkus = addition.main_product_sku;
|
|
2015
|
-
if (
|
|
2017
|
+
if ((0, es_toolkit.difference)(mainSkus, skus).length >= mainSkus.length) hasFulfill = false;
|
|
2016
2018
|
}
|
|
2017
2019
|
});
|
|
2018
2020
|
return hasFulfill;
|
|
@@ -2048,7 +2050,7 @@ function buildPayment(mongoose) {
|
|
|
2048
2050
|
}, { collection: "cn_sales_meta" });
|
|
2049
2051
|
CnSalesMetaSchema.static({ async getAllSaleItems(query = {}) {
|
|
2050
2052
|
try {
|
|
2051
|
-
const queryCondition =
|
|
2053
|
+
const queryCondition = typeof query === "object" && query !== null && (0, es_toolkit_compat.isEmpty)(query) ? { status: 1 } : query;
|
|
2052
2054
|
return await this.aggregate().match(queryCondition).lookup({
|
|
2053
2055
|
from: "jamup_product",
|
|
2054
2056
|
localField: "product_id",
|
|
@@ -2286,11 +2288,12 @@ function buildPayment(mongoose) {
|
|
|
2286
2288
|
}).sort({ created_on: -1 }).populate("product_id").exec();
|
|
2287
2289
|
},
|
|
2288
2290
|
getUserLicense(query, cb) {
|
|
2289
|
-
if (
|
|
2290
|
-
const queryObj =
|
|
2291
|
+
if (typeof query !== "object" || query === null) return cb(/* @__PURE__ */ new Error("Given query params should be a object"));
|
|
2292
|
+
const queryObj = {
|
|
2293
|
+
...query,
|
|
2291
2294
|
status: { $in: [1, 4] },
|
|
2292
2295
|
$or: [{ due_date: null }, { due_date: { $gt: /* @__PURE__ */ new Date() } }]
|
|
2293
|
-
}
|
|
2296
|
+
};
|
|
2294
2297
|
this.find(queryObj).sort({ created_on: -1 }).populate("product_id", "id name price product_type status version addition extra_payment_fields").then((licenses) => {
|
|
2295
2298
|
if (!Array.isArray(licenses)) return cb(/* @__PURE__ */ new Error("Invalid data format"));
|
|
2296
2299
|
const result = [];
|
|
@@ -2301,13 +2304,14 @@ function buildPayment(mongoose) {
|
|
|
2301
2304
|
}, (err) => cb(err));
|
|
2302
2305
|
},
|
|
2303
2306
|
async getUserLicensePromise(query) {
|
|
2304
|
-
if (
|
|
2305
|
-
const queryObj =
|
|
2307
|
+
if (typeof query !== "object" || query === null) throw new Error("Given query params should be a object");
|
|
2308
|
+
const queryObj = {
|
|
2309
|
+
...query,
|
|
2306
2310
|
status: { $in: [1, 4] },
|
|
2307
2311
|
$or: [{ due_date: null }, { due_date: { $gt: /* @__PURE__ */ new Date() } }]
|
|
2308
|
-
}
|
|
2312
|
+
};
|
|
2309
2313
|
const licenseData = await this.find(queryObj).sort({ created_on: -1 }).populate("product_id", "id name price product_type status version addition extra_payment_fields").exec();
|
|
2310
|
-
if (!
|
|
2314
|
+
if (!Array.isArray(licenseData)) throw new Error("Invalid license data");
|
|
2311
2315
|
const result = [];
|
|
2312
2316
|
licenseData.forEach((item) => {
|
|
2313
2317
|
if (item.product_id) result.push(item);
|
|
@@ -2315,23 +2319,25 @@ function buildPayment(mongoose) {
|
|
|
2315
2319
|
return result;
|
|
2316
2320
|
},
|
|
2317
2321
|
getUserPurchase(query, productType, cb) {
|
|
2318
|
-
if (
|
|
2322
|
+
if (typeof query !== "object" || query === null) return cb(/* @__PURE__ */ new Error("Given query params should be a object"));
|
|
2319
2323
|
const populateProductList = productType === "pack" ? "id name product_type display_name extra_payment_fields created_on" : "id name price product_type display_name status version addition";
|
|
2320
|
-
const queryObj =
|
|
2324
|
+
const queryObj = {
|
|
2325
|
+
...query,
|
|
2321
2326
|
status: { $in: [1, 4] },
|
|
2322
2327
|
$or: [{ due_date: null }, { due_date: { $gt: /* @__PURE__ */ new Date() } }]
|
|
2323
|
-
}
|
|
2328
|
+
};
|
|
2324
2329
|
this.find(queryObj).sort({ created_on: -1 }).populate("product_id", populateProductList).then((docs) => cb(null, docs), (err) => cb(err));
|
|
2325
2330
|
},
|
|
2326
2331
|
async getUserPurchasePromise(query, productType, opts) {
|
|
2327
|
-
if (
|
|
2332
|
+
if (typeof query !== "object" || query === null) throw new Error("Given query params should be a object");
|
|
2328
2333
|
const populateProductList = productType === "pack" ? "id name sku product_type display_name extra_payment_fields created_on" : "id name sku product_type display_name addition created_on";
|
|
2329
|
-
const
|
|
2330
|
-
const queryObj = lodash.default.assign({}, {
|
|
2334
|
+
const queryObj = {
|
|
2331
2335
|
status: { $in: [1, 4] },
|
|
2332
|
-
$or: [{ due_date: null }, { due_date: { $gt: /* @__PURE__ */ new Date() } }]
|
|
2333
|
-
|
|
2334
|
-
|
|
2336
|
+
$or: [{ due_date: null }, { due_date: { $gt: /* @__PURE__ */ new Date() } }],
|
|
2337
|
+
...productType === "free_trial" ? { $and: [{ from_free_trial: { $ne: null } }, { from_free_trial: { $exists: true } }] } : { $or: [{ from_free_trial: null }, { from_free_trial: { $exists: false } }] },
|
|
2338
|
+
...query
|
|
2339
|
+
};
|
|
2340
|
+
if (opts?.isLean === true) return this.find(queryObj).sort({ created_on: -1 }).populate("product_id", populateProductList).lean({ virtuals: true }).exec();
|
|
2335
2341
|
return this.find(queryObj).sort({ created_on: -1 }).populate("product_id", populateProductList).exec();
|
|
2336
2342
|
},
|
|
2337
2343
|
async getUserIapLicenses(userId, iapIds) {
|
|
@@ -2367,11 +2373,13 @@ function buildPayment(mongoose) {
|
|
|
2367
2373
|
},
|
|
2368
2374
|
async createTrialLicense(data) {
|
|
2369
2375
|
try {
|
|
2370
|
-
|
|
2371
|
-
|
|
2376
|
+
const dueDate = new Date(data.due_date);
|
|
2377
|
+
if (!Object.hasOwn(data, "due_date") || !(0, date_fns.isValid)(dueDate)) throw new Error("Invalid trail license format!");
|
|
2378
|
+
return await this.create({
|
|
2379
|
+
...data,
|
|
2372
2380
|
status: 4,
|
|
2373
|
-
due_date:
|
|
2374
|
-
})
|
|
2381
|
+
due_date: dueDate
|
|
2382
|
+
});
|
|
2375
2383
|
} catch (err) {
|
|
2376
2384
|
log$5("ERR:createTrialLicense:%o", err);
|
|
2377
2385
|
throw err;
|
|
@@ -2527,11 +2535,14 @@ function buildPgConfig(mongoose) {
|
|
|
2527
2535
|
const that = this;
|
|
2528
2536
|
let realCb = cb;
|
|
2529
2537
|
let realMerge;
|
|
2530
|
-
if (
|
|
2538
|
+
if (typeof doMerge === "function") realCb = doMerge;
|
|
2531
2539
|
else realMerge = doMerge;
|
|
2532
2540
|
that.findOne({ config_key: key }).then((config) => {
|
|
2533
2541
|
if (config) {
|
|
2534
|
-
config.config_value =
|
|
2542
|
+
config.config_value = realMerge === true ? {
|
|
2543
|
+
...config.config_value,
|
|
2544
|
+
...value
|
|
2545
|
+
} : value;
|
|
2535
2546
|
config.created_on = /* @__PURE__ */ new Date();
|
|
2536
2547
|
config.save().then((saved) => realCb(null, saved), (err) => realCb(err));
|
|
2537
2548
|
} else that.create({
|
|
@@ -2556,12 +2567,18 @@ function buildPgConfig(mongoose) {
|
|
|
2556
2567
|
}
|
|
2557
2568
|
//#endregion
|
|
2558
2569
|
//#region src/models/preset.ts
|
|
2559
|
-
const log$4 = (0,
|
|
2570
|
+
const log$4 = (0, node_util.debuglog)("model:preset");
|
|
2560
2571
|
function _queryCompatibilityHandler(query) {
|
|
2561
2572
|
let formatQuery = {};
|
|
2562
|
-
if (
|
|
2563
|
-
|
|
2564
|
-
|
|
2573
|
+
if ((0, es_toolkit_compat.has)(query, "preset_for") && query.preset_for === "amp2") formatQuery = {
|
|
2574
|
+
...query,
|
|
2575
|
+
preset_for: { $in: ["amp2", "bias"] }
|
|
2576
|
+
};
|
|
2577
|
+
else if (!(0, es_toolkit_compat.has)(query, "preset_for") || query.preset_for === "") formatQuery = {
|
|
2578
|
+
...query,
|
|
2579
|
+
preset_for: "jamup"
|
|
2580
|
+
};
|
|
2581
|
+
if ((0, es_toolkit_compat.isEmpty)(formatQuery)) formatQuery = { ...query };
|
|
2565
2582
|
return formatQuery;
|
|
2566
2583
|
}
|
|
2567
2584
|
function _handlePresetVersion(queryObj, req) {
|
|
@@ -2573,15 +2590,15 @@ function _handlePresetVersion(queryObj, req) {
|
|
|
2573
2590
|
"lte",
|
|
2574
2591
|
"ne"
|
|
2575
2592
|
];
|
|
2576
|
-
if (!
|
|
2577
|
-
else if (
|
|
2578
|
-
if (
|
|
2579
|
-
const tmpVersionQuery =
|
|
2593
|
+
if (!(0, es_toolkit_compat.has)(req.query, "preset_for") || (0, es_toolkit_compat.has)(req.query, "preset_for") && req.query.preset_for !== "live") return { ...queryObj };
|
|
2594
|
+
else if ((0, es_toolkit_compat.has)(req.query, "preset_version") && (0, es_toolkit_compat.has)(req.query, "version_comparison")) {
|
|
2595
|
+
if (supportVersionComparison.indexOf(req.query.version_comparison) !== -1) {
|
|
2596
|
+
const tmpVersionQuery = { ...queryObj };
|
|
2580
2597
|
const versionQuery = _buildPresetVersionQuery(req.query.preset_version, req.query.version_comparison);
|
|
2581
|
-
if (versionQuery) return
|
|
2598
|
+
if (versionQuery) return (0, es_toolkit_compat.merge)(tmpVersionQuery, versionQuery);
|
|
2582
2599
|
}
|
|
2583
2600
|
}
|
|
2584
|
-
return
|
|
2601
|
+
return { ...queryObj };
|
|
2585
2602
|
}
|
|
2586
2603
|
function _buildPresetVersionQuery(version, comparison) {
|
|
2587
2604
|
const tmpAttrs = String(version).split(".");
|
|
@@ -2615,7 +2632,7 @@ function _buildLicenseTierQuery(licenseTierParam) {
|
|
|
2615
2632
|
const tmpData = /* @__PURE__ */ new Set();
|
|
2616
2633
|
const expansionData = /* @__PURE__ */ new Set();
|
|
2617
2634
|
const allExpansion = new Set(["celestion", "classic"]);
|
|
2618
|
-
|
|
2635
|
+
tmpLicenseTier.forEach((lic) => {
|
|
2619
2636
|
switch (lic) {
|
|
2620
2637
|
case "celestion":
|
|
2621
2638
|
case "classic":
|
|
@@ -2646,7 +2663,7 @@ function _buildLicenseTierQuery(licenseTierParam) {
|
|
|
2646
2663
|
});
|
|
2647
2664
|
return expansionData.size > 0 ? { $and: [
|
|
2648
2665
|
{ license_tier: { $in: Array.from(tmpData) } },
|
|
2649
|
-
{ license_tier: { $in:
|
|
2666
|
+
{ license_tier: { $in: [...Array.from(tmpData), ...Array.from(expansionData)] } },
|
|
2650
2667
|
{ license_tier: { $nin: Array.from(allExpansion) } }
|
|
2651
2668
|
] } : { $and: [{ license_tier: { $in: Array.from(tmpData) } }, { license_tier: { $nin: Array.from(allExpansion) } }] };
|
|
2652
2669
|
}
|
|
@@ -2655,13 +2672,13 @@ function _parsePageParams(data) {
|
|
|
2655
2672
|
page_size: 12,
|
|
2656
2673
|
page: 1
|
|
2657
2674
|
};
|
|
2658
|
-
if (data &&
|
|
2675
|
+
if (data && (0, es_toolkit_compat.has)(data, "page_size")) {
|
|
2659
2676
|
const pageSize = Array.isArray(data.page_size) ? parseInt(data.page_size.pop(), 10) : parseInt(data.page_size, 10);
|
|
2660
|
-
if (pageSize >= 1) pageParams =
|
|
2677
|
+
if (pageSize >= 1) pageParams = (0, es_toolkit_compat.merge)(pageParams, { page_size: pageSize });
|
|
2661
2678
|
}
|
|
2662
|
-
if (data &&
|
|
2679
|
+
if (data && (0, es_toolkit_compat.has)(data, "page")) {
|
|
2663
2680
|
const page = Array.isArray(data.page) ? parseInt(data.page.pop(), 10) : parseInt(data.page, 10);
|
|
2664
|
-
if (page > 1) pageParams =
|
|
2681
|
+
if (page > 1) pageParams = (0, es_toolkit_compat.merge)(pageParams, { page });
|
|
2665
2682
|
}
|
|
2666
2683
|
return pageParams;
|
|
2667
2684
|
}
|
|
@@ -2929,14 +2946,17 @@ function buildPreset(mongoose) {
|
|
|
2929
2946
|
this.find({ creator_id: userId }).sort({ created_on: -1 }).then((docs) => cb(null, docs), (err) => cb(err));
|
|
2930
2947
|
},
|
|
2931
2948
|
async getPresetByQuery(req, opts = {}) {
|
|
2932
|
-
if (!
|
|
2949
|
+
if (!(0, es_toolkit_compat.has)(req.query, "keyword") || !(0, es_toolkit_compat.isString)(req.query.keyword)) throw new Error("missing the searching term");
|
|
2933
2950
|
const pageParams = _parsePageParams(req.query);
|
|
2934
2951
|
let searchCondition = {
|
|
2935
2952
|
preset_for: req.query.preset_for ? req.query.preset_for : "jamup",
|
|
2936
2953
|
status: 0
|
|
2937
2954
|
};
|
|
2938
|
-
if (
|
|
2939
|
-
if (
|
|
2955
|
+
if ((0, es_toolkit_compat.has)(req.query, "license_tier")) searchCondition = (0, es_toolkit_compat.merge)({ ...searchCondition }, _buildLicenseTierQuery(req.query.license_tier));
|
|
2956
|
+
if ((0, es_toolkit_compat.has)(req.query, "order") && req.query.order === "hot") searchCondition = {
|
|
2957
|
+
...searchCondition,
|
|
2958
|
+
created_on: { $gte: (0, date_fns.subMonths)(/* @__PURE__ */ new Date(), 1) }
|
|
2959
|
+
};
|
|
2940
2960
|
searchCondition = _handlePresetVersion(searchCondition, req);
|
|
2941
2961
|
const aggregatePipeline = [
|
|
2942
2962
|
{ $search: {
|
|
@@ -2964,7 +2984,7 @@ function buildPreset(mongoose) {
|
|
|
2964
2984
|
{ $skip: (pageParams.page - 1) * pageParams.page_size },
|
|
2965
2985
|
{ $limit: pageParams.page_size }
|
|
2966
2986
|
];
|
|
2967
|
-
if (!
|
|
2987
|
+
if (!(0, es_toolkit_compat.has)(opts, "full")) aggregatePipeline.push({ $project: { preset_data: 0 } });
|
|
2968
2988
|
return this.aggregate(aggregatePipeline);
|
|
2969
2989
|
},
|
|
2970
2990
|
async getPresetsBySearch(req) {
|
|
@@ -2975,52 +2995,55 @@ function buildPreset(mongoose) {
|
|
|
2975
2995
|
status: 0
|
|
2976
2996
|
};
|
|
2977
2997
|
let selectOps = {};
|
|
2978
|
-
if (!
|
|
2979
|
-
if (
|
|
2998
|
+
if (!(0, es_toolkit_compat.has)(req.query, "detail") || req.query.detail !== "yes") selectOps = { preset_data: 0 };
|
|
2999
|
+
if ((0, es_toolkit_compat.has)(req.query, "pids")) {
|
|
2980
3000
|
const pids = req.query.pids.split(",");
|
|
2981
3001
|
searchCondition._id = { $in: pids };
|
|
2982
3002
|
}
|
|
2983
|
-
if (
|
|
2984
|
-
else if (
|
|
2985
|
-
if (
|
|
2986
|
-
if (
|
|
3003
|
+
if ((0, es_toolkit_compat.has)(req.query, "category")) searchCondition.category = { $in: String(req.query.category).split(",") };
|
|
3004
|
+
else if ((0, es_toolkit_compat.has)(req.query, "except_cateogry")) searchCondition.category = { $nin: String(req.query.except_cateogry).split(",") };
|
|
3005
|
+
if ((0, es_toolkit_compat.has)(req.query, "pedal_type")) searchCondition["preset_meta.pedal_type"] = req.query.pedal_type;
|
|
3006
|
+
if ((0, es_toolkit_compat.has)(req.query, "preset_features")) {
|
|
2987
3007
|
const params = req.query.preset_features.split(",");
|
|
2988
3008
|
const featureQuery = {};
|
|
2989
|
-
|
|
3009
|
+
params.forEach((param) => {
|
|
2990
3010
|
const t = param.split(":");
|
|
2991
3011
|
if (t.length === 2) featureQuery[t[0]] = parseInt(t[1], 10);
|
|
2992
3012
|
});
|
|
2993
3013
|
searchCondition.preset_features = featureQuery;
|
|
2994
3014
|
}
|
|
2995
3015
|
const createQuery = {};
|
|
2996
|
-
if (
|
|
2997
|
-
const d =
|
|
2998
|
-
if (
|
|
3016
|
+
if ((0, es_toolkit_compat.has)(req.query, "create_after")) {
|
|
3017
|
+
const d = new Date(req.query.create_after);
|
|
3018
|
+
if ((0, date_fns.isValid)(d)) createQuery.$gte = d;
|
|
2999
3019
|
}
|
|
3000
|
-
if (
|
|
3001
|
-
const d =
|
|
3002
|
-
if (
|
|
3020
|
+
if ((0, es_toolkit_compat.has)(req.query, "create_before")) {
|
|
3021
|
+
const d = new Date(req.query.create_before);
|
|
3022
|
+
if ((0, date_fns.isValid)(d)) createQuery.$lte = d;
|
|
3003
3023
|
}
|
|
3004
|
-
if (!
|
|
3024
|
+
if (!(0, es_toolkit_compat.isEmpty)(createQuery)) searchCondition.created_on = createQuery;
|
|
3005
3025
|
const updateQuery = {};
|
|
3006
|
-
if (
|
|
3007
|
-
const d =
|
|
3008
|
-
if (
|
|
3026
|
+
if ((0, es_toolkit_compat.has)(req.query, "update_after")) {
|
|
3027
|
+
const d = new Date(req.query.update_after);
|
|
3028
|
+
if ((0, date_fns.isValid)(d)) updateQuery.$gte = d;
|
|
3009
3029
|
}
|
|
3010
|
-
if (
|
|
3011
|
-
const d =
|
|
3012
|
-
if (
|
|
3030
|
+
if ((0, es_toolkit_compat.has)(req.query, "update_before")) {
|
|
3031
|
+
const d = new Date(req.query.update_before);
|
|
3032
|
+
if ((0, date_fns.isValid)(d)) updateQuery.$lte = d;
|
|
3013
3033
|
}
|
|
3014
|
-
if (!
|
|
3015
|
-
if (
|
|
3016
|
-
if (
|
|
3034
|
+
if (!(0, es_toolkit_compat.isEmpty)(updateQuery)) searchCondition.updated_on = updateQuery;
|
|
3035
|
+
if ((0, es_toolkit_compat.has)(req.query, "license_tier")) searchCondition = (0, es_toolkit_compat.merge)({ ...searchCondition }, _buildLicenseTierQuery(req.query.license_tier));
|
|
3036
|
+
if ((0, es_toolkit_compat.has)(req.query, "order") && req.query.order === "hot") searchCondition = {
|
|
3037
|
+
...searchCondition,
|
|
3038
|
+
created_on: { $gte: (0, date_fns.subMonths)(/* @__PURE__ */ new Date(), 1) }
|
|
3039
|
+
};
|
|
3017
3040
|
if (searchCondition.preset_for === "spark") {
|
|
3018
|
-
if (
|
|
3019
|
-
if (
|
|
3041
|
+
if ((0, es_toolkit_compat.has)(req.query, "signal_chain_type")) searchCondition.signal_chain_type = req.query.signal_chain_type;
|
|
3042
|
+
if ((0, es_toolkit_compat.has)(req.query, "no_dspid")) searchCondition["preset_meta.dspId"] = { $nin: String(req.query.no_dspid).split(",") };
|
|
3020
3043
|
}
|
|
3021
3044
|
searchCondition = _handlePresetVersion(searchCondition, req);
|
|
3022
|
-
if (
|
|
3023
|
-
if (
|
|
3045
|
+
if ((0, es_toolkit_compat.has)(req, "query.keyword") && !(0, es_toolkit_compat.isEmpty)(req.query.keyword)) {
|
|
3046
|
+
if ((0, es_toolkit_compat.has)(process.env, "IS_CHINA")) {
|
|
3024
3047
|
searchCondition.$or = [{ name: new RegExp(`^${_filterKeyword(req.query.keyword)}`, "i") }, { description: new RegExp(`${_filterKeyword(req.query.keyword)}`, "i") }];
|
|
3025
3048
|
return this.aggregate([
|
|
3026
3049
|
{ $match: _queryCompatibilityHandler(searchCondition) },
|
|
@@ -3056,14 +3079,14 @@ function buildPreset(mongoose) {
|
|
|
3056
3079
|
getPresetsList(query, sort, req, cb) {
|
|
3057
3080
|
const pageParams = _parsePageParams(req.query);
|
|
3058
3081
|
let q = query;
|
|
3059
|
-
if (
|
|
3060
|
-
if (
|
|
3082
|
+
if ((0, es_toolkit_compat.isPlainObject)(q)) q.status = 0;
|
|
3083
|
+
if ((0, es_toolkit_compat.has)(q, "preset_for") && q.preset_for !== "jamup") {
|
|
3061
3084
|
q.image_url = { $ne: null };
|
|
3062
3085
|
q.thumb_url = { $ne: null };
|
|
3063
3086
|
}
|
|
3064
|
-
if (
|
|
3087
|
+
if ((0, es_toolkit_compat.has)(req.query, "license_tier")) q = (0, es_toolkit_compat.merge)({ ...q }, _buildLicenseTierQuery(req.query.license_tier));
|
|
3065
3088
|
let finalSort = sort;
|
|
3066
|
-
if (
|
|
3089
|
+
if ((0, es_toolkit_compat.has)(req.query, "order")) finalSort = _buildSortQuery(req.query.order);
|
|
3067
3090
|
q = _handlePresetVersion(q, req);
|
|
3068
3091
|
this.find(_queryCompatibilityHandler(q)).sort(finalSort).select("-preset_data").skip((pageParams.page - 1) * pageParams.page_size).limit(pageParams.page_size).then((docs) => cb(null, docs), (err) => cb(err));
|
|
3069
3092
|
},
|
|
@@ -3075,8 +3098,8 @@ function buildPreset(mongoose) {
|
|
|
3075
3098
|
getMyPresets(query, sort, req, cb) {
|
|
3076
3099
|
const pageParams = _parsePageParams(req.query);
|
|
3077
3100
|
let q = query;
|
|
3078
|
-
if (
|
|
3079
|
-
if (
|
|
3101
|
+
if ((0, es_toolkit_compat.isPlainObject)(q)) q.status = { $in: [0, 2] };
|
|
3102
|
+
if ((0, es_toolkit_compat.has)(q, "preset_for") && q.preset_for !== "jamup") {
|
|
3080
3103
|
q.image_url = { $ne: null };
|
|
3081
3104
|
q.thumb_url = { $ne: null };
|
|
3082
3105
|
}
|
|
@@ -3084,8 +3107,8 @@ function buildPreset(mongoose) {
|
|
|
3084
3107
|
this.find(_queryCompatibilityHandler(q)).sort(sort).select("-preset_data").skip((pageParams.page - 1) * pageParams.page_size).limit(pageParams.page_size).then((docs) => cb(null, docs), (err) => cb(err));
|
|
3085
3108
|
},
|
|
3086
3109
|
getOnePresetByCondition(query, opts, cb) {
|
|
3087
|
-
const defaultSort =
|
|
3088
|
-
const defaultSelect =
|
|
3110
|
+
const defaultSort = (0, es_toolkit_compat.has)(opts, "sort") && (0, es_toolkit_compat.isPlainObject)(opts.sort) ? opts.sort : { created_on: -1 };
|
|
3111
|
+
const defaultSelect = (0, es_toolkit_compat.has)(opts, "select") && (0, es_toolkit_compat.isString)(opts.select) ? opts.select : "";
|
|
3089
3112
|
this.findOne(_queryCompatibilityHandler(query)).sort(defaultSort).select(defaultSelect).then((doc) => cb(null, doc), (err) => cb(err));
|
|
3090
3113
|
},
|
|
3091
3114
|
getSinglePreset(id, cb) {
|
|
@@ -3154,9 +3177,8 @@ function buildPreset(mongoose) {
|
|
|
3154
3177
|
PresetUserLike.static({
|
|
3155
3178
|
getCountByPresetCondition(query, condition, cb) {
|
|
3156
3179
|
this.find(query).populate("preset_id").then((result) => {
|
|
3157
|
-
return cb(null,
|
|
3158
|
-
|
|
3159
|
-
return lodash.default.has(tmpObj.preset_id, condition);
|
|
3180
|
+
return cb(null, result.filter((item) => {
|
|
3181
|
+
return (0, es_toolkit_compat.has)((item.toObject ? item.toObject() : item).preset_id, condition);
|
|
3160
3182
|
}).length);
|
|
3161
3183
|
}, (err) => cb(err));
|
|
3162
3184
|
},
|
|
@@ -3164,12 +3186,15 @@ function buildPreset(mongoose) {
|
|
|
3164
3186
|
const pageParams = _parsePageParams(req.query);
|
|
3165
3187
|
const defaultPresetCondition = { "preset.status": { $eq: 0 } };
|
|
3166
3188
|
let filterQuery = {};
|
|
3167
|
-
if (
|
|
3189
|
+
if ((0, es_toolkit_compat.has)(query, "no_dspid")) {
|
|
3168
3190
|
defaultPresetCondition["preset.preset_meta.dspId"] = { $nin: String(query.no_dspid).split(",") };
|
|
3169
|
-
filterQuery =
|
|
3170
|
-
} else filterQuery =
|
|
3191
|
+
filterQuery = (0, es_toolkit.omit)(query, ["no_dspid"]);
|
|
3192
|
+
} else filterQuery = { ...query };
|
|
3171
3193
|
const aggregateQuery = [
|
|
3172
|
-
{ $match:
|
|
3194
|
+
{ $match: {
|
|
3195
|
+
..._queryCompatibilityHandler(filterQuery),
|
|
3196
|
+
user_id: new mongoose.Types.ObjectId(filterQuery.user_id)
|
|
3197
|
+
} },
|
|
3173
3198
|
{ $lookup: {
|
|
3174
3199
|
from: "jamup_preset",
|
|
3175
3200
|
localField: "preset_id",
|
|
@@ -3180,10 +3205,10 @@ function buildPreset(mongoose) {
|
|
|
3180
3205
|
{ $match: defaultPresetCondition }
|
|
3181
3206
|
];
|
|
3182
3207
|
const presetQuery = _handlePresetVersion({}, req);
|
|
3183
|
-
if (!
|
|
3208
|
+
if (!(0, es_toolkit_compat.isEmpty)(presetQuery) && (0, es_toolkit_compat.has)(presetQuery, "$and") && Array.isArray(presetQuery.$and)) presetQuery.$and.forEach((item) => {
|
|
3184
3209
|
const newQuery = { $match: {} };
|
|
3185
|
-
const objKey =
|
|
3186
|
-
const objVal =
|
|
3210
|
+
const objKey = Object.keys(item);
|
|
3211
|
+
const objVal = Object.values(item);
|
|
3187
3212
|
if (objKey.length === 1 && objVal.length === 1) {
|
|
3188
3213
|
newQuery.$match[`preset.${objKey[0]}`] = objVal[0];
|
|
3189
3214
|
aggregateQuery.push(newQuery);
|
|
@@ -3221,7 +3246,7 @@ function buildPreset(mongoose) {
|
|
|
3221
3246
|
}
|
|
3222
3247
|
//#endregion
|
|
3223
3248
|
//#region src/models/promotion.ts
|
|
3224
|
-
const log$3 = (0,
|
|
3249
|
+
const log$3 = (0, node_util.debuglog)("model:promotion");
|
|
3225
3250
|
const CAMPAIGN_TYPE = ["free_upgrade"];
|
|
3226
3251
|
function buildPromotion(mongoose) {
|
|
3227
3252
|
const { Schema } = mongoose;
|
|
@@ -3380,15 +3405,15 @@ function buildPromotion(mongoose) {
|
|
|
3380
3405
|
try {
|
|
3381
3406
|
const nowTime = /* @__PURE__ */ new Date();
|
|
3382
3407
|
const defaultQuery = { $and: [{ $or: [{ start_time: null }, { start_time: { $lt: nowTime } }] }, { $or: [{ end_time: null }, { end_time: { $gt: nowTime } }] }] };
|
|
3383
|
-
if (
|
|
3408
|
+
if (params !== void 0) {
|
|
3384
3409
|
log$3("getAvailableAnnouncement:querystring %o", params);
|
|
3385
3410
|
const { pname, locale, ta_device, country, device_list, device_os } = params;
|
|
3386
|
-
if (
|
|
3387
|
-
if (
|
|
3388
|
-
if (
|
|
3389
|
-
if (
|
|
3411
|
+
if (typeof pname === "string") defaultQuery.$and.push({ announce_for: { $in: [pname, "all"] } });
|
|
3412
|
+
if (typeof locale === "string") defaultQuery.$and.push({ locale });
|
|
3413
|
+
if (typeof ta_device === "string") defaultQuery.$and.push({ target_audience_device: { $in: [...ta_device.split(","), "all"] } });
|
|
3414
|
+
if (typeof country === "string") defaultQuery.$and.push({ $or: [{ country: { $all: country.split(",") } }, { country: { $in: ["all"] } }] });
|
|
3390
3415
|
else defaultQuery.$and.push({ $or: [{ country: { $in: ["all"] } }, { country: { $exists: false } }] });
|
|
3391
|
-
if (
|
|
3416
|
+
if (device_list !== void 0) if (typeof device_list === "string" && device_list.length > 0) {
|
|
3392
3417
|
const tmpDeviceList = device_list.split(",");
|
|
3393
3418
|
const deviceList = [];
|
|
3394
3419
|
const allTypeSet = /* @__PURE__ */ new Set();
|
|
@@ -3403,17 +3428,17 @@ function buildPromotion(mongoose) {
|
|
|
3403
3428
|
if (uniqueProductLineSet.size > 0) uniqueProductLineSet.forEach((item) => deviceList.push(`${item}_all`));
|
|
3404
3429
|
defaultQuery.$and.push({ device_list: { $in: deviceList } });
|
|
3405
3430
|
} else defaultQuery.$and.push({ device_list: { $in: ["none"] } });
|
|
3406
|
-
if (
|
|
3431
|
+
if (typeof device_os === "string") defaultQuery.$and.push({ $or: [{ device_os: "all" }, { device_os }] });
|
|
3407
3432
|
}
|
|
3408
3433
|
let ret;
|
|
3409
|
-
if (
|
|
3434
|
+
if (params?.email === void 0) {
|
|
3410
3435
|
defaultQuery.$and.push({ user_list_num: 0 });
|
|
3411
3436
|
defaultQuery.$and.push({ action_button: { $elemMatch: { type: { $ne: "free_trial" } } } });
|
|
3412
3437
|
ret = await this.find(defaultQuery).lean().exec();
|
|
3413
3438
|
} else {
|
|
3414
|
-
const noUserQuery =
|
|
3439
|
+
const noUserQuery = structuredClone(defaultQuery);
|
|
3415
3440
|
noUserQuery.$and.push({ user_list_num: 0 });
|
|
3416
|
-
const hasUserQuery =
|
|
3441
|
+
const hasUserQuery = structuredClone(defaultQuery);
|
|
3417
3442
|
hasUserQuery.$and.push({ user_list_num: { $gt: 0 } });
|
|
3418
3443
|
const [noUserData, hasUserData] = await Promise.all([this.aggregate([{ $match: noUserQuery }]).exec(), this.aggregate([
|
|
3419
3444
|
{ $match: hasUserQuery },
|
|
@@ -3429,9 +3454,9 @@ function buildPromotion(mongoose) {
|
|
|
3429
3454
|
"paUserList.status": 1
|
|
3430
3455
|
} }
|
|
3431
3456
|
]).exec()]);
|
|
3432
|
-
ret =
|
|
3457
|
+
ret = [...noUserData, ...hasUserData];
|
|
3433
3458
|
}
|
|
3434
|
-
return
|
|
3459
|
+
return (0, es_toolkit_compat.orderBy)(ret, ["order", "start_time"], ["desc", "asc"]);
|
|
3435
3460
|
} catch (err) {
|
|
3436
3461
|
log$3("ERR:getAvailableAnnouncement %j", err);
|
|
3437
3462
|
throw err;
|
|
@@ -4314,7 +4339,34 @@ function buildToneThemeFeaturedList(mongoose) {
|
|
|
4314
4339
|
}
|
|
4315
4340
|
//#endregion
|
|
4316
4341
|
//#region src/models/user.ts
|
|
4317
|
-
const log$2 = (0,
|
|
4342
|
+
const log$2 = (0, node_util.debuglog)("model:user");
|
|
4343
|
+
/**
|
|
4344
|
+
* Error thrown by User auth statics. Replaces the previous dependency on
|
|
4345
|
+
* `@positivegrid/pg-error`'s `AuthError`. Preserves the `errorCode` +
|
|
4346
|
+
* `statusCode` property contract so existing duck-typing checks
|
|
4347
|
+
* (`err.errorCode === 'USER_UNAUTHORIZED'`) keep working. Consumers that
|
|
4348
|
+
* relied on `instanceof AuthError` should switch to `instanceof AuthError`
|
|
4349
|
+
* (re-exported from the package root).
|
|
4350
|
+
*/
|
|
4351
|
+
const AUTH_ERROR_STATUS = {
|
|
4352
|
+
USER_UNAUTHORIZED: 401,
|
|
4353
|
+
USER_NOT_EXIST: 404,
|
|
4354
|
+
USER_OAUTH_LOGIN: 400,
|
|
4355
|
+
ACCOUNT_WERE_DELETED: 400,
|
|
4356
|
+
INTERNAL_SYSMTEM_ERROR: 500
|
|
4357
|
+
};
|
|
4358
|
+
var AuthError = class extends Error {
|
|
4359
|
+
errorCode;
|
|
4360
|
+
statusCode;
|
|
4361
|
+
customData;
|
|
4362
|
+
constructor(code, message, customData) {
|
|
4363
|
+
super(message);
|
|
4364
|
+
this.name = "AuthError";
|
|
4365
|
+
this.errorCode = code;
|
|
4366
|
+
this.statusCode = AUTH_ERROR_STATUS[code.toUpperCase()] ?? 500;
|
|
4367
|
+
if (customData) this.customData = customData;
|
|
4368
|
+
}
|
|
4369
|
+
};
|
|
4318
4370
|
function encryptPassword(pwd) {
|
|
4319
4371
|
if (!pwd) return "";
|
|
4320
4372
|
const encryptType = "sha1";
|
|
@@ -4746,23 +4798,23 @@ function buildUser(mongoose) {
|
|
|
4746
4798
|
try {
|
|
4747
4799
|
user = await this.findOne({ username: normalized }).exec();
|
|
4748
4800
|
} catch (err) {
|
|
4749
|
-
throw new
|
|
4801
|
+
throw new AuthError("internal_sysmtem_error", err.message);
|
|
4750
4802
|
}
|
|
4751
4803
|
if (!user) {
|
|
4752
4804
|
let bgUser;
|
|
4753
4805
|
try {
|
|
4754
4806
|
bgUser = await this.findOne({ bk_username: { $in: [normalized] } }).exec();
|
|
4755
4807
|
} catch (err) {
|
|
4756
|
-
throw new
|
|
4808
|
+
throw new AuthError("INTERNAL_SYSMTEM_ERROR", err.message);
|
|
4757
4809
|
}
|
|
4758
|
-
if (!bgUser) throw new
|
|
4759
|
-
else if (!bgUser.authenticate(password)) throw new
|
|
4810
|
+
if (!bgUser) throw new AuthError("USER_NOT_EXIST", `Cannot find user ${normalized}`);
|
|
4811
|
+
else if (!bgUser.authenticate(password)) throw new AuthError("USER_UNAUTHORIZED", "unauthorized");
|
|
4760
4812
|
return bgUser;
|
|
4761
4813
|
}
|
|
4762
|
-
if (user.user_status === 2) throw new
|
|
4814
|
+
if (user.user_status === 2) throw new AuthError("ACCOUNT_WERE_DELETED", `Account ${user.email} already deleted`);
|
|
4763
4815
|
if (!user.authenticate(password)) {
|
|
4764
|
-
if (user.facebook_id !== null) throw new
|
|
4765
|
-
throw new
|
|
4816
|
+
if (user.facebook_id !== null) throw new AuthError("USER_OAUTH_LOGIN", "Please use FB to login your account");
|
|
4817
|
+
throw new AuthError("USER_UNAUTHORIZED", "unauthorized");
|
|
4766
4818
|
}
|
|
4767
4819
|
return user;
|
|
4768
4820
|
},
|
|
@@ -4771,14 +4823,14 @@ function buildUser(mongoose) {
|
|
|
4771
4823
|
this._async_auth(uname, password).then((user) => cb(null, user), (err) => cb(err));
|
|
4772
4824
|
},
|
|
4773
4825
|
login(query, cb) {
|
|
4774
|
-
if (
|
|
4826
|
+
if (typeof query !== "object" || query === null) return cb(/* @__PURE__ */ new Error("Invalid login parameter"));
|
|
4775
4827
|
this.findOne(query).then((u) => cb(null, u), (err) => cb(err));
|
|
4776
4828
|
},
|
|
4777
4829
|
loginForPassport(query, cb) {
|
|
4778
|
-
if (
|
|
4830
|
+
if (typeof query !== "object" || query === null) return cb(/* @__PURE__ */ new Error("Invalid login parameter"));
|
|
4779
4831
|
const q = query;
|
|
4780
|
-
if (
|
|
4781
|
-
if (
|
|
4832
|
+
if (Object.hasOwn(q, "username")) q.username = String(q.username).trim().toLowerCase();
|
|
4833
|
+
if (Object.hasOwn(q, "email")) q.email = String(q.email).trim().toLowerCase();
|
|
4782
4834
|
this.findOne(q).then((user) => {
|
|
4783
4835
|
if (!user) return cb({
|
|
4784
4836
|
status: 404,
|
|
@@ -4830,9 +4882,12 @@ function buildUser(mongoose) {
|
|
|
4830
4882
|
},
|
|
4831
4883
|
async getUserDetail(query, projectFields = {}) {
|
|
4832
4884
|
try {
|
|
4833
|
-
if (
|
|
4834
|
-
const queryCondition =
|
|
4835
|
-
|
|
4885
|
+
if (typeof query !== "object" || query === null) throw new Error("Query need to be object!");
|
|
4886
|
+
const queryCondition = {
|
|
4887
|
+
user_status: 1,
|
|
4888
|
+
...query
|
|
4889
|
+
};
|
|
4890
|
+
const defaultProjectFields = {
|
|
4836
4891
|
_id: 1,
|
|
4837
4892
|
email: 1,
|
|
4838
4893
|
username: 1,
|
|
@@ -4840,8 +4895,9 @@ function buildUser(mongoose) {
|
|
|
4840
4895
|
last_login: 1,
|
|
4841
4896
|
"userprofile.first_name": 1,
|
|
4842
4897
|
"userprofile.last_name": 1,
|
|
4843
|
-
"userprofile.full_name": 1
|
|
4844
|
-
|
|
4898
|
+
"userprofile.full_name": 1,
|
|
4899
|
+
...projectFields
|
|
4900
|
+
};
|
|
4845
4901
|
return await this.aggregate([
|
|
4846
4902
|
{ $match: queryCondition },
|
|
4847
4903
|
{ $lookup: {
|
|
@@ -4860,8 +4916,11 @@ function buildUser(mongoose) {
|
|
|
4860
4916
|
},
|
|
4861
4917
|
async getDealerDetail(query) {
|
|
4862
4918
|
try {
|
|
4863
|
-
if (
|
|
4864
|
-
const queryCondition =
|
|
4919
|
+
if (typeof query !== "object" || query === null) throw new Error("Query need to be object!");
|
|
4920
|
+
const queryCondition = {
|
|
4921
|
+
user_status: 1,
|
|
4922
|
+
...query
|
|
4923
|
+
};
|
|
4865
4924
|
return await this.aggregate([
|
|
4866
4925
|
{ $match: queryCondition },
|
|
4867
4926
|
{ $lookup: {
|
|
@@ -4988,7 +5047,7 @@ function buildUser(mongoose) {
|
|
|
4988
5047
|
}
|
|
4989
5048
|
//#endregion
|
|
4990
5049
|
//#region src/models/userTrack.ts
|
|
4991
|
-
const log$1 = (0,
|
|
5050
|
+
const log$1 = (0, node_util.debuglog)("model:usertrack");
|
|
4992
5051
|
const LICENSE_ADDITION = {
|
|
4993
5052
|
PRO: 0,
|
|
4994
5053
|
DEMO: 1,
|
|
@@ -5094,16 +5153,16 @@ function buildUserTrack(mongoose) {
|
|
|
5094
5153
|
const userID = new mongoose.Types.ObjectId(data.userID);
|
|
5095
5154
|
const startedAt = parseInt(String(data.startedAt), 10);
|
|
5096
5155
|
if (!mongoose.Types.ObjectId.isValid(userID) || PRODUCTS.indexOf(product) === -1 || Object.keys(LICENSE_ADDITION).indexOf(addition) === -1) throw new Error(`Invalid parameter: ${String(userID)}/${product}/${addition}`);
|
|
5097
|
-
else if (!startedAt || !(0,
|
|
5156
|
+
else if (!startedAt || !(0, date_fns.isValid)(new Date(startedAt))) throw new Error(`Invalid timestamp format: ${startedAt}/${data.updatedAt}`);
|
|
5098
5157
|
const trackData = {
|
|
5099
5158
|
user_id: userID,
|
|
5100
5159
|
product,
|
|
5101
5160
|
addition: LICENSE_ADDITION[addition],
|
|
5102
|
-
started_at:
|
|
5161
|
+
started_at: new Date(startedAt)
|
|
5103
5162
|
};
|
|
5104
|
-
if (
|
|
5163
|
+
if (Object.hasOwn(data, "updatedAt")) {
|
|
5105
5164
|
const updatedAt = parseInt(String(data.updatedAt), 10);
|
|
5106
|
-
if (updatedAt && (0,
|
|
5165
|
+
if (updatedAt && (0, date_fns.isValid)(new Date(updatedAt))) trackData.updated_at = new Date(updatedAt);
|
|
5107
5166
|
}
|
|
5108
5167
|
if (!await this.findOne(trackData).exec()) await this.create(trackData);
|
|
5109
5168
|
return true;
|
|
@@ -5120,7 +5179,7 @@ function buildUserTrack(mongoose) {
|
|
|
5120
5179
|
}
|
|
5121
5180
|
//#endregion
|
|
5122
5181
|
//#region src/index.ts
|
|
5123
|
-
const log = (0,
|
|
5182
|
+
const log = (0, node_util.debuglog)("model:init");
|
|
5124
5183
|
const ALL_BUILDERS = [
|
|
5125
5184
|
buildBanks,
|
|
5126
5185
|
buildDevice,
|