@goweekdays/core 0.0.21 → 0.1.1
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 +18 -0
- package/dist/index.d.ts +50 -11
- package/dist/index.js +528 -121
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +528 -121
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -2
package/dist/index.js
CHANGED
|
@@ -8975,9 +8975,9 @@ var require_iterate = __commonJS({
|
|
|
8975
8975
|
var async = require_async();
|
|
8976
8976
|
var abort = require_abort();
|
|
8977
8977
|
module2.exports = iterate;
|
|
8978
|
-
function iterate(list,
|
|
8978
|
+
function iterate(list, iterator2, state, callback) {
|
|
8979
8979
|
var key = state["keyedList"] ? state["keyedList"][state.index] : state.index;
|
|
8980
|
-
state.jobs[key] = runJob(
|
|
8980
|
+
state.jobs[key] = runJob(iterator2, key, list[key], function(error, output) {
|
|
8981
8981
|
if (!(key in state.jobs)) {
|
|
8982
8982
|
return;
|
|
8983
8983
|
}
|
|
@@ -8990,12 +8990,12 @@ var require_iterate = __commonJS({
|
|
|
8990
8990
|
callback(error, state.results);
|
|
8991
8991
|
});
|
|
8992
8992
|
}
|
|
8993
|
-
function runJob(
|
|
8993
|
+
function runJob(iterator2, key, item, callback) {
|
|
8994
8994
|
var aborter;
|
|
8995
|
-
if (
|
|
8996
|
-
aborter =
|
|
8995
|
+
if (iterator2.length == 2) {
|
|
8996
|
+
aborter = iterator2(item, async(callback));
|
|
8997
8997
|
} else {
|
|
8998
|
-
aborter =
|
|
8998
|
+
aborter = iterator2(item, key, async(callback));
|
|
8999
8999
|
}
|
|
9000
9000
|
return aborter;
|
|
9001
9001
|
}
|
|
@@ -9048,10 +9048,10 @@ var require_parallel = __commonJS({
|
|
|
9048
9048
|
var initState = require_state();
|
|
9049
9049
|
var terminator = require_terminator();
|
|
9050
9050
|
module2.exports = parallel;
|
|
9051
|
-
function parallel(list,
|
|
9051
|
+
function parallel(list, iterator2, callback) {
|
|
9052
9052
|
var state = initState(list);
|
|
9053
9053
|
while (state.index < (state["keyedList"] || list).length) {
|
|
9054
|
-
iterate(list,
|
|
9054
|
+
iterate(list, iterator2, state, function(error, result) {
|
|
9055
9055
|
if (error) {
|
|
9056
9056
|
callback(error, result);
|
|
9057
9057
|
return;
|
|
@@ -9077,16 +9077,16 @@ var require_serialOrdered = __commonJS({
|
|
|
9077
9077
|
module2.exports = serialOrdered;
|
|
9078
9078
|
module2.exports.ascending = ascending;
|
|
9079
9079
|
module2.exports.descending = descending;
|
|
9080
|
-
function serialOrdered(list,
|
|
9080
|
+
function serialOrdered(list, iterator2, sortMethod, callback) {
|
|
9081
9081
|
var state = initState(list, sortMethod);
|
|
9082
|
-
iterate(list,
|
|
9082
|
+
iterate(list, iterator2, state, function iteratorHandler(error, result) {
|
|
9083
9083
|
if (error) {
|
|
9084
9084
|
callback(error, result);
|
|
9085
9085
|
return;
|
|
9086
9086
|
}
|
|
9087
9087
|
state.index++;
|
|
9088
9088
|
if (state.index < (state["keyedList"] || list).length) {
|
|
9089
|
-
iterate(list,
|
|
9089
|
+
iterate(list, iterator2, state, iteratorHandler);
|
|
9090
9090
|
return;
|
|
9091
9091
|
}
|
|
9092
9092
|
callback(null, state.results);
|
|
@@ -9107,8 +9107,8 @@ var require_serial = __commonJS({
|
|
|
9107
9107
|
"node_modules/asynckit/serial.js"(exports, module2) {
|
|
9108
9108
|
var serialOrdered = require_serialOrdered();
|
|
9109
9109
|
module2.exports = serial;
|
|
9110
|
-
function serial(list,
|
|
9111
|
-
return serialOrdered(list,
|
|
9110
|
+
function serial(list, iterator2, callback) {
|
|
9111
|
+
return serialOrdered(list, iterator2, null, callback);
|
|
9112
9112
|
}
|
|
9113
9113
|
}
|
|
9114
9114
|
});
|
|
@@ -9674,6 +9674,7 @@ var require_get_intrinsic = __commonJS({
|
|
|
9674
9674
|
"%eval%": eval,
|
|
9675
9675
|
// eslint-disable-line no-eval
|
|
9676
9676
|
"%EvalError%": $EvalError,
|
|
9677
|
+
"%Float16Array%": typeof Float16Array === "undefined" ? undefined2 : Float16Array,
|
|
9677
9678
|
"%Float32Array%": typeof Float32Array === "undefined" ? undefined2 : Float32Array,
|
|
9678
9679
|
"%Float64Array%": typeof Float64Array === "undefined" ? undefined2 : Float64Array,
|
|
9679
9680
|
"%FinalizationRegistry%": typeof FinalizationRegistry === "undefined" ? undefined2 : FinalizationRegistry,
|
|
@@ -9946,23 +9947,23 @@ var require_es_set_tostringtag = __commonJS({
|
|
|
9946
9947
|
var hasToStringTag = require_shams2()();
|
|
9947
9948
|
var hasOwn = require_hasown();
|
|
9948
9949
|
var $TypeError = require_type();
|
|
9949
|
-
var
|
|
9950
|
+
var toStringTag2 = hasToStringTag ? Symbol.toStringTag : null;
|
|
9950
9951
|
module2.exports = function setToStringTag(object, value) {
|
|
9951
9952
|
var overrideIfSet = arguments.length > 2 && !!arguments[2] && arguments[2].force;
|
|
9952
9953
|
var nonConfigurable = arguments.length > 2 && !!arguments[2] && arguments[2].nonConfigurable;
|
|
9953
9954
|
if (typeof overrideIfSet !== "undefined" && typeof overrideIfSet !== "boolean" || typeof nonConfigurable !== "undefined" && typeof nonConfigurable !== "boolean") {
|
|
9954
9955
|
throw new $TypeError("if provided, the `overrideIfSet` and `nonConfigurable` options must be booleans");
|
|
9955
9956
|
}
|
|
9956
|
-
if (
|
|
9957
|
+
if (toStringTag2 && (overrideIfSet || !hasOwn(object, toStringTag2))) {
|
|
9957
9958
|
if ($defineProperty) {
|
|
9958
|
-
$defineProperty(object,
|
|
9959
|
+
$defineProperty(object, toStringTag2, {
|
|
9959
9960
|
configurable: !nonConfigurable,
|
|
9960
9961
|
enumerable: false,
|
|
9961
9962
|
value,
|
|
9962
9963
|
writable: false
|
|
9963
9964
|
});
|
|
9964
9965
|
} else {
|
|
9965
|
-
object[
|
|
9966
|
+
object[toStringTag2] = value;
|
|
9966
9967
|
}
|
|
9967
9968
|
}
|
|
9968
9969
|
};
|
|
@@ -12236,7 +12237,6 @@ function useVerificationController() {
|
|
|
12236
12237
|
res.json({ message: "Successfully invited user." });
|
|
12237
12238
|
return;
|
|
12238
12239
|
} catch (error2) {
|
|
12239
|
-
console.log(error2);
|
|
12240
12240
|
next(error2);
|
|
12241
12241
|
}
|
|
12242
12242
|
}
|
|
@@ -12826,6 +12826,7 @@ function bind(fn, thisArg) {
|
|
|
12826
12826
|
// node_modules/axios/lib/utils.js
|
|
12827
12827
|
var { toString } = Object.prototype;
|
|
12828
12828
|
var { getPrototypeOf } = Object;
|
|
12829
|
+
var { iterator, toStringTag } = Symbol;
|
|
12829
12830
|
var kindOf = ((cache) => (thing) => {
|
|
12830
12831
|
const str = toString.call(thing);
|
|
12831
12832
|
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
|
@@ -12860,7 +12861,7 @@ var isPlainObject = (val) => {
|
|
|
12860
12861
|
return false;
|
|
12861
12862
|
}
|
|
12862
12863
|
const prototype3 = getPrototypeOf(val);
|
|
12863
|
-
return (prototype3 === null || prototype3 === Object.prototype || Object.getPrototypeOf(prototype3) === null) && !(
|
|
12864
|
+
return (prototype3 === null || prototype3 === Object.prototype || Object.getPrototypeOf(prototype3) === null) && !(toStringTag in val) && !(iterator in val);
|
|
12864
12865
|
};
|
|
12865
12866
|
var isDate = kindOfTest("Date");
|
|
12866
12867
|
var isFile = kindOfTest("File");
|
|
@@ -13012,10 +13013,10 @@ var isTypedArray = ((TypedArray) => {
|
|
|
13012
13013
|
};
|
|
13013
13014
|
})(typeof Uint8Array !== "undefined" && getPrototypeOf(Uint8Array));
|
|
13014
13015
|
var forEachEntry = (obj, fn) => {
|
|
13015
|
-
const generator = obj && obj[
|
|
13016
|
-
const
|
|
13016
|
+
const generator = obj && obj[iterator];
|
|
13017
|
+
const _iterator = generator.call(obj);
|
|
13017
13018
|
let result;
|
|
13018
|
-
while ((result =
|
|
13019
|
+
while ((result = _iterator.next()) && !result.done) {
|
|
13019
13020
|
const pair = result.value;
|
|
13020
13021
|
fn.call(obj, pair[0], pair[1]);
|
|
13021
13022
|
}
|
|
@@ -13085,23 +13086,8 @@ var noop = () => {
|
|
|
13085
13086
|
var toFiniteNumber = (value, defaultValue) => {
|
|
13086
13087
|
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
|
13087
13088
|
};
|
|
13088
|
-
var ALPHA = "abcdefghijklmnopqrstuvwxyz";
|
|
13089
|
-
var DIGIT = "0123456789";
|
|
13090
|
-
var ALPHABET = {
|
|
13091
|
-
DIGIT,
|
|
13092
|
-
ALPHA,
|
|
13093
|
-
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
|
13094
|
-
};
|
|
13095
|
-
var generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|
13096
|
-
let str = "";
|
|
13097
|
-
const { length } = alphabet;
|
|
13098
|
-
while (size--) {
|
|
13099
|
-
str += alphabet[Math.random() * length | 0];
|
|
13100
|
-
}
|
|
13101
|
-
return str;
|
|
13102
|
-
};
|
|
13103
13089
|
function isSpecCompliantForm(thing) {
|
|
13104
|
-
return !!(thing && isFunction(thing.append) && thing[
|
|
13090
|
+
return !!(thing && isFunction(thing.append) && thing[toStringTag] === "FormData" && thing[iterator]);
|
|
13105
13091
|
}
|
|
13106
13092
|
var toJSONObject = (obj) => {
|
|
13107
13093
|
const stack = new Array(10);
|
|
@@ -13147,6 +13133,7 @@ var _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
|
|
13147
13133
|
isFunction(_global.postMessage)
|
|
13148
13134
|
);
|
|
13149
13135
|
var asap = typeof queueMicrotask !== "undefined" ? queueMicrotask.bind(_global) : typeof process !== "undefined" && process.nextTick || _setImmediate;
|
|
13136
|
+
var isIterable = (thing) => thing != null && isFunction(thing[iterator]);
|
|
13150
13137
|
var utils_default = {
|
|
13151
13138
|
isArray,
|
|
13152
13139
|
isArrayBuffer,
|
|
@@ -13198,14 +13185,13 @@ var utils_default = {
|
|
|
13198
13185
|
findKey,
|
|
13199
13186
|
global: _global,
|
|
13200
13187
|
isContextDefined,
|
|
13201
|
-
ALPHABET,
|
|
13202
|
-
generateString,
|
|
13203
13188
|
isSpecCompliantForm,
|
|
13204
13189
|
toJSONObject,
|
|
13205
13190
|
isAsyncFn,
|
|
13206
13191
|
isThenable,
|
|
13207
13192
|
setImmediate: _setImmediate,
|
|
13208
|
-
asap
|
|
13193
|
+
asap,
|
|
13194
|
+
isIterable
|
|
13209
13195
|
};
|
|
13210
13196
|
|
|
13211
13197
|
// node_modules/axios/lib/core/AxiosError.js
|
|
@@ -13537,11 +13523,31 @@ var transitional_default = {
|
|
|
13537
13523
|
clarifyTimeoutError: false
|
|
13538
13524
|
};
|
|
13539
13525
|
|
|
13526
|
+
// node_modules/axios/lib/platform/node/index.js
|
|
13527
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
13528
|
+
|
|
13540
13529
|
// node_modules/axios/lib/platform/node/classes/URLSearchParams.js
|
|
13541
13530
|
var import_url = __toESM(require("url"), 1);
|
|
13542
13531
|
var URLSearchParams_default = import_url.default.URLSearchParams;
|
|
13543
13532
|
|
|
13544
13533
|
// node_modules/axios/lib/platform/node/index.js
|
|
13534
|
+
var ALPHA = "abcdefghijklmnopqrstuvwxyz";
|
|
13535
|
+
var DIGIT = "0123456789";
|
|
13536
|
+
var ALPHABET = {
|
|
13537
|
+
DIGIT,
|
|
13538
|
+
ALPHA,
|
|
13539
|
+
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
|
13540
|
+
};
|
|
13541
|
+
var generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|
13542
|
+
let str = "";
|
|
13543
|
+
const { length } = alphabet;
|
|
13544
|
+
const randomValues = new Uint32Array(size);
|
|
13545
|
+
import_crypto.default.randomFillSync(randomValues);
|
|
13546
|
+
for (let i = 0; i < size; i++) {
|
|
13547
|
+
str += alphabet[randomValues[i] % length];
|
|
13548
|
+
}
|
|
13549
|
+
return str;
|
|
13550
|
+
};
|
|
13545
13551
|
var node_default = {
|
|
13546
13552
|
isNode: true,
|
|
13547
13553
|
classes: {
|
|
@@ -13549,6 +13555,8 @@ var node_default = {
|
|
|
13549
13555
|
FormData: FormData_default,
|
|
13550
13556
|
Blob: typeof Blob !== "undefined" && Blob || null
|
|
13551
13557
|
},
|
|
13558
|
+
ALPHABET,
|
|
13559
|
+
generateString,
|
|
13552
13560
|
protocols: ["http", "https", "file", "data"]
|
|
13553
13561
|
};
|
|
13554
13562
|
|
|
@@ -13871,10 +13879,15 @@ var AxiosHeaders = class {
|
|
|
13871
13879
|
setHeaders(header, valueOrRewrite);
|
|
13872
13880
|
} else if (utils_default.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
|
13873
13881
|
setHeaders(parseHeaders_default(header), valueOrRewrite);
|
|
13874
|
-
} else if (utils_default.
|
|
13875
|
-
|
|
13876
|
-
|
|
13882
|
+
} else if (utils_default.isObject(header) && utils_default.isIterable(header)) {
|
|
13883
|
+
let obj = {}, dest, key;
|
|
13884
|
+
for (const entry of header) {
|
|
13885
|
+
if (!utils_default.isArray(entry)) {
|
|
13886
|
+
throw TypeError("Object iterator must return a key-value pair");
|
|
13887
|
+
}
|
|
13888
|
+
obj[key = entry[0]] = (dest = obj[key]) ? utils_default.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]] : entry[1];
|
|
13877
13889
|
}
|
|
13890
|
+
setHeaders(obj, valueOrRewrite);
|
|
13878
13891
|
} else {
|
|
13879
13892
|
header != null && setHeader(valueOrRewrite, header, rewrite);
|
|
13880
13893
|
}
|
|
@@ -13978,6 +13991,9 @@ var AxiosHeaders = class {
|
|
|
13978
13991
|
toString() {
|
|
13979
13992
|
return Object.entries(this.toJSON()).map(([header, value]) => header + ": " + value).join("\n");
|
|
13980
13993
|
}
|
|
13994
|
+
getSetCookie() {
|
|
13995
|
+
return this.get("set-cookie") || [];
|
|
13996
|
+
}
|
|
13981
13997
|
get [Symbol.toStringTag]() {
|
|
13982
13998
|
return "AxiosHeaders";
|
|
13983
13999
|
}
|
|
@@ -14074,8 +14090,9 @@ function combineURLs(baseURL, relativeURL) {
|
|
|
14074
14090
|
}
|
|
14075
14091
|
|
|
14076
14092
|
// node_modules/axios/lib/core/buildFullPath.js
|
|
14077
|
-
function buildFullPath(baseURL, requestedURL) {
|
|
14078
|
-
|
|
14093
|
+
function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
|
|
14094
|
+
let isRelativeUrl = !isAbsoluteURL(requestedURL);
|
|
14095
|
+
if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) {
|
|
14079
14096
|
return combineURLs(baseURL, requestedURL);
|
|
14080
14097
|
}
|
|
14081
14098
|
return requestedURL;
|
|
@@ -14090,7 +14107,7 @@ var import_follow_redirects = __toESM(require_follow_redirects(), 1);
|
|
|
14090
14107
|
var import_zlib = __toESM(require("zlib"), 1);
|
|
14091
14108
|
|
|
14092
14109
|
// node_modules/axios/lib/env/data.js
|
|
14093
|
-
var VERSION = "1.
|
|
14110
|
+
var VERSION = "1.9.0";
|
|
14094
14111
|
|
|
14095
14112
|
// node_modules/axios/lib/helpers/parseProtocol.js
|
|
14096
14113
|
function parseProtocol(url2) {
|
|
@@ -14268,7 +14285,7 @@ var readBlob = async function* (blob) {
|
|
|
14268
14285
|
var readBlob_default = readBlob;
|
|
14269
14286
|
|
|
14270
14287
|
// node_modules/axios/lib/helpers/formDataToStream.js
|
|
14271
|
-
var BOUNDARY_ALPHABET =
|
|
14288
|
+
var BOUNDARY_ALPHABET = platform_default.ALPHABET.ALPHA_DIGIT + "-_";
|
|
14272
14289
|
var textEncoder = typeof TextEncoder === "function" ? new TextEncoder() : new import_util.default.TextEncoder();
|
|
14273
14290
|
var CRLF = "\r\n";
|
|
14274
14291
|
var CRLF_BYTES = textEncoder.encode(CRLF);
|
|
@@ -14311,7 +14328,7 @@ var formDataToStream = (form, headersHandler, options) => {
|
|
|
14311
14328
|
const {
|
|
14312
14329
|
tag = "form-data-boundary",
|
|
14313
14330
|
size = 25,
|
|
14314
|
-
boundary = tag + "-" +
|
|
14331
|
+
boundary = tag + "-" + platform_default.generateString(size, BOUNDARY_ALPHABET)
|
|
14315
14332
|
} = options || {};
|
|
14316
14333
|
if (!utils_default.isFormData(form)) {
|
|
14317
14334
|
throw TypeError("FormData instance required");
|
|
@@ -14320,7 +14337,7 @@ var formDataToStream = (form, headersHandler, options) => {
|
|
|
14320
14337
|
throw Error("boundary must be 10-70 characters long");
|
|
14321
14338
|
}
|
|
14322
14339
|
const boundaryBytes = textEncoder.encode("--" + boundary + CRLF);
|
|
14323
|
-
const footerBytes = textEncoder.encode("--" + boundary + "--" + CRLF
|
|
14340
|
+
const footerBytes = textEncoder.encode("--" + boundary + "--" + CRLF);
|
|
14324
14341
|
let contentLength = footerBytes.byteLength;
|
|
14325
14342
|
const parts = Array.from(form.entries()).map(([name, value]) => {
|
|
14326
14343
|
const part = new FormDataPart(name, value);
|
|
@@ -14628,7 +14645,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config2) {
|
|
|
14628
14645
|
config2.signal.aborted ? abort() : config2.signal.addEventListener("abort", abort);
|
|
14629
14646
|
}
|
|
14630
14647
|
}
|
|
14631
|
-
const fullPath = buildFullPath(config2.baseURL, config2.url);
|
|
14648
|
+
const fullPath = buildFullPath(config2.baseURL, config2.url, config2.allowAbsoluteUrls);
|
|
14632
14649
|
const parsed = new URL(fullPath, platform_default.hasBrowserEnv ? platform_default.origin : void 0);
|
|
14633
14650
|
const protocol = parsed.protocol || supportedProtocols[0];
|
|
14634
14651
|
if (protocol === "data:") {
|
|
@@ -15120,7 +15137,7 @@ var resolveConfig_default = (config2) => {
|
|
|
15120
15137
|
const newConfig = mergeConfig({}, config2);
|
|
15121
15138
|
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
|
15122
15139
|
newConfig.headers = headers = AxiosHeaders_default.from(headers);
|
|
15123
|
-
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config2.params, config2.paramsSerializer);
|
|
15140
|
+
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config2.params, config2.paramsSerializer);
|
|
15124
15141
|
if (auth) {
|
|
15125
15142
|
headers.set(
|
|
15126
15143
|
"Authorization",
|
|
@@ -15350,7 +15367,7 @@ var readStream = async function* (stream4) {
|
|
|
15350
15367
|
}
|
|
15351
15368
|
};
|
|
15352
15369
|
var trackStream = (stream4, chunkSize, onProgress, onFinish) => {
|
|
15353
|
-
const
|
|
15370
|
+
const iterator2 = readBytes(stream4, chunkSize);
|
|
15354
15371
|
let bytes = 0;
|
|
15355
15372
|
let done;
|
|
15356
15373
|
let _onFinish = (e) => {
|
|
@@ -15362,7 +15379,7 @@ var trackStream = (stream4, chunkSize, onProgress, onFinish) => {
|
|
|
15362
15379
|
return new ReadableStream({
|
|
15363
15380
|
async pull(controller) {
|
|
15364
15381
|
try {
|
|
15365
|
-
const { done: done2, value } = await
|
|
15382
|
+
const { done: done2, value } = await iterator2.next();
|
|
15366
15383
|
if (done2) {
|
|
15367
15384
|
_onFinish();
|
|
15368
15385
|
controller.close();
|
|
@@ -15381,7 +15398,7 @@ var trackStream = (stream4, chunkSize, onProgress, onFinish) => {
|
|
|
15381
15398
|
},
|
|
15382
15399
|
cancel(reason) {
|
|
15383
15400
|
_onFinish(reason);
|
|
15384
|
-
return
|
|
15401
|
+
return iterator2.return();
|
|
15385
15402
|
}
|
|
15386
15403
|
}, {
|
|
15387
15404
|
highWaterMark: 2
|
|
@@ -15540,7 +15557,7 @@ var fetch_default = isFetchSupported && (async (config2) => {
|
|
|
15540
15557
|
});
|
|
15541
15558
|
} catch (err) {
|
|
15542
15559
|
unsubscribe && unsubscribe();
|
|
15543
|
-
if (err && err.name === "TypeError" && /fetch/i.test(err.message)) {
|
|
15560
|
+
if (err && err.name === "TypeError" && /Load failed|fetch/i.test(err.message)) {
|
|
15544
15561
|
throw Object.assign(
|
|
15545
15562
|
new AxiosError_default("Network Error", AxiosError_default.ERR_NETWORK, config2, request),
|
|
15546
15563
|
{
|
|
@@ -15719,7 +15736,7 @@ var validator_default = {
|
|
|
15719
15736
|
var validators2 = validator_default.validators;
|
|
15720
15737
|
var Axios = class {
|
|
15721
15738
|
constructor(instanceConfig) {
|
|
15722
|
-
this.defaults = instanceConfig;
|
|
15739
|
+
this.defaults = instanceConfig || {};
|
|
15723
15740
|
this.interceptors = {
|
|
15724
15741
|
request: new InterceptorManager_default(),
|
|
15725
15742
|
response: new InterceptorManager_default()
|
|
@@ -15781,6 +15798,12 @@ var Axios = class {
|
|
|
15781
15798
|
}, true);
|
|
15782
15799
|
}
|
|
15783
15800
|
}
|
|
15801
|
+
if (config2.allowAbsoluteUrls !== void 0) {
|
|
15802
|
+
} else if (this.defaults.allowAbsoluteUrls !== void 0) {
|
|
15803
|
+
config2.allowAbsoluteUrls = this.defaults.allowAbsoluteUrls;
|
|
15804
|
+
} else {
|
|
15805
|
+
config2.allowAbsoluteUrls = true;
|
|
15806
|
+
}
|
|
15784
15807
|
validator_default.assertOptions(config2, {
|
|
15785
15808
|
baseUrl: validators2.spelling("baseURL"),
|
|
15786
15809
|
withXsrfToken: validators2.spelling("withXSRFToken")
|
|
@@ -15851,7 +15874,7 @@ var Axios = class {
|
|
|
15851
15874
|
}
|
|
15852
15875
|
getUri(config2) {
|
|
15853
15876
|
config2 = mergeConfig(this.defaults, config2);
|
|
15854
|
-
const fullPath = buildFullPath(config2.baseURL, config2.url);
|
|
15877
|
+
const fullPath = buildFullPath(config2.baseURL, config2.url, config2.allowAbsoluteUrls);
|
|
15855
15878
|
return buildURL(fullPath, config2.params, config2.paramsSerializer);
|
|
15856
15879
|
}
|
|
15857
15880
|
};
|
|
@@ -16243,7 +16266,8 @@ var TPaymentMethod = import_zod2.z.enum([
|
|
|
16243
16266
|
"VIRTUAL_ACCOUNT",
|
|
16244
16267
|
"EWALLET",
|
|
16245
16268
|
"OVER_THE_COUNTER",
|
|
16246
|
-
"QR_CODE"
|
|
16269
|
+
"QR_CODE",
|
|
16270
|
+
"PAYPAL"
|
|
16247
16271
|
]);
|
|
16248
16272
|
var TPaymentMetadata = import_zod2.z.object({
|
|
16249
16273
|
userId: import_zod2.z.union([import_zod2.z.string().length(24), import_zod2.z.instanceof(import_mongodb10.ObjectId)]).optional(),
|
|
@@ -16479,7 +16503,6 @@ function useXenditService() {
|
|
|
16479
16503
|
});
|
|
16480
16504
|
return res.data;
|
|
16481
16505
|
} catch (error) {
|
|
16482
|
-
console.log(error);
|
|
16483
16506
|
throw new import_utils36.BadRequestError(
|
|
16484
16507
|
"Failed to initiate GCash linking and payment request."
|
|
16485
16508
|
);
|
|
@@ -16513,7 +16536,6 @@ function useXenditService() {
|
|
|
16513
16536
|
});
|
|
16514
16537
|
return res.data;
|
|
16515
16538
|
} catch (error) {
|
|
16516
|
-
console.log(error);
|
|
16517
16539
|
throw new import_utils36.BadRequestError(
|
|
16518
16540
|
"Failed to initiate GCash linking and payment request."
|
|
16519
16541
|
);
|
|
@@ -16566,7 +16588,6 @@ function useXenditService() {
|
|
|
16566
16588
|
});
|
|
16567
16589
|
return res.data;
|
|
16568
16590
|
} catch (error) {
|
|
16569
|
-
console.log(error);
|
|
16570
16591
|
throw new import_utils36.BadRequestError("Failed to create subscription.");
|
|
16571
16592
|
}
|
|
16572
16593
|
}
|
|
@@ -16690,7 +16711,29 @@ function useXenditService() {
|
|
|
16690
16711
|
const res = await axios2.post("/v2/payment_methods", value);
|
|
16691
16712
|
return res.data;
|
|
16692
16713
|
} catch (error) {
|
|
16693
|
-
throw new import_utils36.BadRequestError(
|
|
16714
|
+
throw new import_utils36.BadRequestError(
|
|
16715
|
+
error.response.data.message ?? "Failed to link payment method."
|
|
16716
|
+
);
|
|
16717
|
+
}
|
|
16718
|
+
}
|
|
16719
|
+
async function getPaymentMethodsByCustomerId(customerId) {
|
|
16720
|
+
try {
|
|
16721
|
+
const res = await axios2.get("/v2/payment_methods", {
|
|
16722
|
+
params: { customer_id: customerId, status: "ACTIVE" }
|
|
16723
|
+
});
|
|
16724
|
+
return res.data;
|
|
16725
|
+
} catch (error) {
|
|
16726
|
+
throw new import_utils36.BadRequestError("Failed to get payment methods.");
|
|
16727
|
+
}
|
|
16728
|
+
}
|
|
16729
|
+
async function updatePaymentMethodStatusById(id, status) {
|
|
16730
|
+
try {
|
|
16731
|
+
const res = await axios2.patch(`/v2/payment_methods/${id}`, {
|
|
16732
|
+
status
|
|
16733
|
+
});
|
|
16734
|
+
return res.data;
|
|
16735
|
+
} catch (error) {
|
|
16736
|
+
throw new import_utils36.BadRequestError("Failed to update status payment methods.");
|
|
16694
16737
|
}
|
|
16695
16738
|
}
|
|
16696
16739
|
return {
|
|
@@ -16709,7 +16752,9 @@ function useXenditService() {
|
|
|
16709
16752
|
getCustomerById,
|
|
16710
16753
|
eWalletLinkOnly,
|
|
16711
16754
|
directDebitLinkOnly,
|
|
16712
|
-
cardLinkOnly
|
|
16755
|
+
cardLinkOnly,
|
|
16756
|
+
getPaymentMethodsByCustomerId,
|
|
16757
|
+
updatePaymentMethodStatusById
|
|
16713
16758
|
};
|
|
16714
16759
|
}
|
|
16715
16760
|
|
|
@@ -18077,7 +18122,6 @@ function useRoleController() {
|
|
|
18077
18122
|
res.json(data);
|
|
18078
18123
|
return;
|
|
18079
18124
|
} catch (error2) {
|
|
18080
|
-
console.log(error2);
|
|
18081
18125
|
next(error2);
|
|
18082
18126
|
}
|
|
18083
18127
|
}
|
|
@@ -18395,7 +18439,6 @@ function useEntityController() {
|
|
|
18395
18439
|
res.json({ message: "Successfully created entity.", id });
|
|
18396
18440
|
return;
|
|
18397
18441
|
} catch (error2) {
|
|
18398
|
-
console.log(error2);
|
|
18399
18442
|
next(error2);
|
|
18400
18443
|
return;
|
|
18401
18444
|
}
|
|
@@ -19710,8 +19753,8 @@ function MSubscription(value) {
|
|
|
19710
19753
|
_id: import_joi12.default.string().hex().optional().allow("", null),
|
|
19711
19754
|
user: import_joi12.default.string().hex().optional().allow("", null),
|
|
19712
19755
|
org: import_joi12.default.string().hex().optional().allow("", null),
|
|
19713
|
-
customerId: import_joi12.default.string().
|
|
19714
|
-
paymentMethodId: import_joi12.default.string().
|
|
19756
|
+
customerId: import_joi12.default.string().optional(),
|
|
19757
|
+
paymentMethodId: import_joi12.default.string().optional(),
|
|
19715
19758
|
amount: import_joi12.default.number().min(0).required(),
|
|
19716
19759
|
currency: import_joi12.default.string().required(),
|
|
19717
19760
|
description: import_joi12.default.string().optional().allow("", null),
|
|
@@ -19728,7 +19771,7 @@ function MSubscription(value) {
|
|
|
19728
19771
|
addedAt: import_joi12.default.date().optional(),
|
|
19729
19772
|
email: import_joi12.default.string().email().required()
|
|
19730
19773
|
})
|
|
19731
|
-
).optional()
|
|
19774
|
+
).optional(),
|
|
19732
19775
|
nextBillingDate: import_joi12.default.date().optional(),
|
|
19733
19776
|
lastPaymentStatus: import_joi12.default.string().optional().allow("", null),
|
|
19734
19777
|
failedAttempts: import_joi12.default.number().optional().allow("", null),
|
|
@@ -19765,8 +19808,8 @@ function MSubscription(value) {
|
|
|
19765
19808
|
_id: value._id,
|
|
19766
19809
|
user: value.user ?? "",
|
|
19767
19810
|
org: value.org ?? "",
|
|
19768
|
-
customerId: value.customerId,
|
|
19769
|
-
paymentMethodId: value.paymentMethodId,
|
|
19811
|
+
customerId: value.customerId ?? "",
|
|
19812
|
+
paymentMethodId: value.paymentMethodId ?? "",
|
|
19770
19813
|
amount: value.amount,
|
|
19771
19814
|
currency: value.currency,
|
|
19772
19815
|
description: value.description ?? "",
|
|
@@ -19830,7 +19873,6 @@ function useSubscriptionRepo() {
|
|
|
19830
19873
|
const res = await collection.insertOne(value, { session });
|
|
19831
19874
|
return res.insertedId;
|
|
19832
19875
|
} catch (error) {
|
|
19833
|
-
console.log(error);
|
|
19834
19876
|
throw new import_utils55.BadRequestError("Failed to create subscription.");
|
|
19835
19877
|
}
|
|
19836
19878
|
}
|
|
@@ -20635,8 +20677,19 @@ function useAddressRepo() {
|
|
|
20635
20677
|
} catch (error) {
|
|
20636
20678
|
throw new import_utils59.BadRequestError("Invalid address ID.");
|
|
20637
20679
|
}
|
|
20680
|
+
if (value.org) {
|
|
20681
|
+
try {
|
|
20682
|
+
value.org = new import_mongodb28.ObjectId(value.org);
|
|
20683
|
+
} catch (error) {
|
|
20684
|
+
throw new import_utils59.BadRequestError("Invalid org ID.");
|
|
20685
|
+
}
|
|
20686
|
+
}
|
|
20638
20687
|
try {
|
|
20639
|
-
await collection.updateOne(
|
|
20688
|
+
await collection.updateOne(
|
|
20689
|
+
{ _id },
|
|
20690
|
+
{ $set: value },
|
|
20691
|
+
{ session, upsert: true }
|
|
20692
|
+
);
|
|
20640
20693
|
return "Successfully updated address.";
|
|
20641
20694
|
} catch (error) {
|
|
20642
20695
|
throw new import_utils59.BadRequestError("Failed to update address.");
|
|
@@ -20910,6 +20963,7 @@ var TInvoiceItem = import_zod4.z.object({
|
|
|
20910
20963
|
total: import_zod4.z.number().min(0, { message: "Total amount must be at least 0." })
|
|
20911
20964
|
});
|
|
20912
20965
|
var TInvoiceMetadata = import_zod4.z.object({
|
|
20966
|
+
transactionId: import_zod4.z.string().optional(),
|
|
20913
20967
|
userId: import_zod4.z.union([import_zod4.z.string().length(24), import_zod4.z.instanceof(import_mongodb30.ObjectId)]).optional(),
|
|
20914
20968
|
orgId: import_zod4.z.union([import_zod4.z.string().length(24), import_zod4.z.instanceof(import_mongodb30.ObjectId)]).optional(),
|
|
20915
20969
|
billingCycle: import_zod4.z.enum(["monthly", "yearly", "quarterly"], {
|
|
@@ -21273,7 +21327,6 @@ function usePaymentRepo() {
|
|
|
21273
21327
|
value = createPayment(value);
|
|
21274
21328
|
await collection.insertOne(value, { session });
|
|
21275
21329
|
} catch (error) {
|
|
21276
|
-
console.log(error.issues[0].path);
|
|
21277
21330
|
import_utils66.logger.log({ level: "error", message: `${error}` });
|
|
21278
21331
|
const isDuplicated = error.message.includes("duplicate");
|
|
21279
21332
|
if (isDuplicated) {
|
|
@@ -21457,7 +21510,6 @@ function usePriceRepo() {
|
|
|
21457
21510
|
}
|
|
21458
21511
|
|
|
21459
21512
|
// src/services/subscription.service.ts
|
|
21460
|
-
var import_mongodb35 = require("mongodb");
|
|
21461
21513
|
function useSubscriptionService() {
|
|
21462
21514
|
const {
|
|
21463
21515
|
getByUserId: _getByUserId,
|
|
@@ -21492,6 +21544,7 @@ function useSubscriptionService() {
|
|
|
21492
21544
|
const { add: addPayment } = usePaymentRepo();
|
|
21493
21545
|
const { getByType, incrementByType } = useCounterRepo();
|
|
21494
21546
|
const { getByNameType } = usePriceRepo();
|
|
21547
|
+
const { getByNumber } = useInvoiceRepo();
|
|
21495
21548
|
function calculateTieredPricing(seats, tiers, prorationFactor = 1) {
|
|
21496
21549
|
let totalCost = 0;
|
|
21497
21550
|
let nonProratedCost = 0;
|
|
@@ -21522,6 +21575,169 @@ function useSubscriptionService() {
|
|
|
21522
21575
|
nonProratedCost: formatAmount(nonProratedCost)
|
|
21523
21576
|
};
|
|
21524
21577
|
}
|
|
21578
|
+
async function subscribe(value) {
|
|
21579
|
+
const session = import_utils69.useAtlas.getClient()?.startSession();
|
|
21580
|
+
session?.startTransaction();
|
|
21581
|
+
try {
|
|
21582
|
+
const _user = await _getUserByUserId(value.user);
|
|
21583
|
+
if (!_user) {
|
|
21584
|
+
throw new import_utils69.BadRequestError("User not found.");
|
|
21585
|
+
}
|
|
21586
|
+
const orgId = await addOrg(value.org, session);
|
|
21587
|
+
const role = await addRole(
|
|
21588
|
+
{
|
|
21589
|
+
org: orgId.toString(),
|
|
21590
|
+
name: "owner",
|
|
21591
|
+
permissions: ["*"],
|
|
21592
|
+
type: "organization",
|
|
21593
|
+
default: true
|
|
21594
|
+
},
|
|
21595
|
+
session
|
|
21596
|
+
);
|
|
21597
|
+
await addMember(
|
|
21598
|
+
{
|
|
21599
|
+
org: orgId.toString(),
|
|
21600
|
+
orgName: value.org.name,
|
|
21601
|
+
user: value.user,
|
|
21602
|
+
name: `${_user.firstName} ${_user.lastName}`,
|
|
21603
|
+
role: role.toString(),
|
|
21604
|
+
type: "organization"
|
|
21605
|
+
},
|
|
21606
|
+
session
|
|
21607
|
+
);
|
|
21608
|
+
if (!_user.defaultOrg) {
|
|
21609
|
+
await updateUserFieldById(
|
|
21610
|
+
{
|
|
21611
|
+
_id: value.user,
|
|
21612
|
+
field: "defaultOrg",
|
|
21613
|
+
value: orgId.toString()
|
|
21614
|
+
},
|
|
21615
|
+
session
|
|
21616
|
+
);
|
|
21617
|
+
}
|
|
21618
|
+
const description = "GoWeekdays Organization Monthly Subscription.";
|
|
21619
|
+
if (value.promoCode) {
|
|
21620
|
+
await assignByUserId(
|
|
21621
|
+
{ user: value.user, code: value.promoCode },
|
|
21622
|
+
session
|
|
21623
|
+
);
|
|
21624
|
+
}
|
|
21625
|
+
const monthlySubscriptionPrice = await getByNameType(
|
|
21626
|
+
"organization-subscription",
|
|
21627
|
+
"monthly-subscription"
|
|
21628
|
+
);
|
|
21629
|
+
if (!monthlySubscriptionPrice) {
|
|
21630
|
+
throw new import_utils69.BadRequestError(
|
|
21631
|
+
"Failed to fetch monthly subscription price."
|
|
21632
|
+
);
|
|
21633
|
+
}
|
|
21634
|
+
let amount = monthlySubscriptionPrice.value;
|
|
21635
|
+
const items = [];
|
|
21636
|
+
if (value.promoCode) {
|
|
21637
|
+
const promoCode = await getByCode(value.promoCode);
|
|
21638
|
+
if (!promoCode) {
|
|
21639
|
+
throw new import_utils69.BadRequestError("Promo code not found.");
|
|
21640
|
+
}
|
|
21641
|
+
if (promoCode && promoCode.type === "fixed" && promoCode.fixed_rate !== void 0 && promoCode.fixed_rate >= 0) {
|
|
21642
|
+
amount = promoCode.fixed_rate;
|
|
21643
|
+
items.push({
|
|
21644
|
+
description: "GoWeekdays Monthly Subscription",
|
|
21645
|
+
unitPrice: promoCode.fixed_rate,
|
|
21646
|
+
quantity: 1,
|
|
21647
|
+
seats: value.seats,
|
|
21648
|
+
total: promoCode.fixed_rate * value.seats
|
|
21649
|
+
});
|
|
21650
|
+
}
|
|
21651
|
+
if (promoCode && promoCode.type === "tiered" && promoCode.tiers && promoCode.tiers.length) {
|
|
21652
|
+
const computedTieredInvoice = calculateTieredPricing(
|
|
21653
|
+
value.seats,
|
|
21654
|
+
promoCode.tiers
|
|
21655
|
+
);
|
|
21656
|
+
items.push(...computedTieredInvoice.items);
|
|
21657
|
+
amount = computedTieredInvoice.totalCost;
|
|
21658
|
+
}
|
|
21659
|
+
}
|
|
21660
|
+
if (monthlySubscriptionPrice.saleValue && monthlySubscriptionPrice.saleExpiry && new Date(monthlySubscriptionPrice.saleExpiry) > /* @__PURE__ */ new Date()) {
|
|
21661
|
+
amount = monthlySubscriptionPrice.saleValue;
|
|
21662
|
+
}
|
|
21663
|
+
const subscription = await add(
|
|
21664
|
+
{
|
|
21665
|
+
org: orgId.toString(),
|
|
21666
|
+
amount,
|
|
21667
|
+
currency: value.currency,
|
|
21668
|
+
type: "organization",
|
|
21669
|
+
description,
|
|
21670
|
+
paidSeats: value.seats,
|
|
21671
|
+
currentSeats: value.seats,
|
|
21672
|
+
maxSeats: value.seats,
|
|
21673
|
+
billingCycle: "monthly",
|
|
21674
|
+
promoCode: value.promoCode
|
|
21675
|
+
},
|
|
21676
|
+
session
|
|
21677
|
+
);
|
|
21678
|
+
const invoiceCounter = await getByType("invoice");
|
|
21679
|
+
if (!invoiceCounter) {
|
|
21680
|
+
throw new import_utils69.BadRequestError("Failed to fetch invoice counter.");
|
|
21681
|
+
}
|
|
21682
|
+
const date = /* @__PURE__ */ new Date();
|
|
21683
|
+
const mm = String(date.getMonth() + 1).padStart(2, "0");
|
|
21684
|
+
const dd = String(date.getDate()).padStart(2, "0");
|
|
21685
|
+
const yyyy = date.getFullYear();
|
|
21686
|
+
const formattedDate = `${mm}-${dd}-${yyyy}`;
|
|
21687
|
+
const invoiceNumber = `inv-${formattedDate}-${invoiceCounter.count + 1}`;
|
|
21688
|
+
const invoiceData = {
|
|
21689
|
+
type: "organization-subscription",
|
|
21690
|
+
invoiceNumber,
|
|
21691
|
+
amount,
|
|
21692
|
+
dueDate: /* @__PURE__ */ new Date(),
|
|
21693
|
+
metadata: {
|
|
21694
|
+
transactionId: value.transactionId,
|
|
21695
|
+
orgId: orgId.toString(),
|
|
21696
|
+
currency: value.currency,
|
|
21697
|
+
subscriptionId: subscription.toString(),
|
|
21698
|
+
description: `Initial invoice for ${value.seats.toLocaleString()} seats`
|
|
21699
|
+
},
|
|
21700
|
+
status: "paid",
|
|
21701
|
+
items: items && items.length ? items : [
|
|
21702
|
+
{
|
|
21703
|
+
description: "GoWeekdays Monthly Subscription",
|
|
21704
|
+
unitPrice: amount,
|
|
21705
|
+
quantity: 1,
|
|
21706
|
+
seats: value.seats,
|
|
21707
|
+
total: amount * value.seats
|
|
21708
|
+
}
|
|
21709
|
+
]
|
|
21710
|
+
};
|
|
21711
|
+
await addInvoice(invoiceData, session);
|
|
21712
|
+
await incrementByType("invoice", session);
|
|
21713
|
+
await addPayment(
|
|
21714
|
+
{
|
|
21715
|
+
invoiceId: invoiceNumber,
|
|
21716
|
+
amount,
|
|
21717
|
+
paymentMethod: "PAYPAL",
|
|
21718
|
+
status: "completed",
|
|
21719
|
+
metadata: {
|
|
21720
|
+
userId: value.user,
|
|
21721
|
+
orgId: orgId.toString(),
|
|
21722
|
+
currency: value.currency,
|
|
21723
|
+
payment: value.transactionId,
|
|
21724
|
+
subscriptionId: subscription.toString()
|
|
21725
|
+
}
|
|
21726
|
+
},
|
|
21727
|
+
session
|
|
21728
|
+
);
|
|
21729
|
+
await session?.commitTransaction();
|
|
21730
|
+
return {
|
|
21731
|
+
message: "Subscription created successfully.",
|
|
21732
|
+
data: { org: orgId.toString() }
|
|
21733
|
+
};
|
|
21734
|
+
} catch (error) {
|
|
21735
|
+
await session?.abortTransaction();
|
|
21736
|
+
throw error;
|
|
21737
|
+
} finally {
|
|
21738
|
+
session?.endSession();
|
|
21739
|
+
}
|
|
21740
|
+
}
|
|
21525
21741
|
async function createOrgSubscription(value) {
|
|
21526
21742
|
const session = import_utils69.useAtlas.getClient()?.startSession();
|
|
21527
21743
|
session?.startTransaction();
|
|
@@ -21530,11 +21746,9 @@ function useSubscriptionService() {
|
|
|
21530
21746
|
if (!_user) {
|
|
21531
21747
|
throw new import_utils69.BadRequestError("User not found.");
|
|
21532
21748
|
}
|
|
21533
|
-
|
|
21534
|
-
await addOrg(value.organization, session);
|
|
21535
|
-
console.log("value.organization._id", value.organization._id);
|
|
21749
|
+
const orgId = await addOrg(value.organization, session);
|
|
21536
21750
|
const customerData = {
|
|
21537
|
-
reference_id:
|
|
21751
|
+
reference_id: orgId.toString(),
|
|
21538
21752
|
type: value.organization.type === "business" ? "BUSINESS" : "INDIVIDUAL",
|
|
21539
21753
|
email: value.organization.email
|
|
21540
21754
|
};
|
|
@@ -21555,7 +21769,7 @@ function useSubscriptionService() {
|
|
|
21555
21769
|
}
|
|
21556
21770
|
const role = await addRole(
|
|
21557
21771
|
{
|
|
21558
|
-
org:
|
|
21772
|
+
org: orgId.toString(),
|
|
21559
21773
|
name: "owner",
|
|
21560
21774
|
permissions: ["*"],
|
|
21561
21775
|
type: "organization",
|
|
@@ -21565,7 +21779,7 @@ function useSubscriptionService() {
|
|
|
21565
21779
|
);
|
|
21566
21780
|
await addMember(
|
|
21567
21781
|
{
|
|
21568
|
-
org:
|
|
21782
|
+
org: orgId.toString(),
|
|
21569
21783
|
orgName: value.organization.name,
|
|
21570
21784
|
user: value.user,
|
|
21571
21785
|
name: `${_user.firstName} ${_user.lastName}`,
|
|
@@ -21579,7 +21793,7 @@ function useSubscriptionService() {
|
|
|
21579
21793
|
{
|
|
21580
21794
|
_id: value.user,
|
|
21581
21795
|
field: "defaultOrg",
|
|
21582
|
-
value:
|
|
21796
|
+
value: orgId.toString()
|
|
21583
21797
|
},
|
|
21584
21798
|
session
|
|
21585
21799
|
);
|
|
@@ -21588,7 +21802,7 @@ function useSubscriptionService() {
|
|
|
21588
21802
|
if (!customer.id) {
|
|
21589
21803
|
throw new import_utils69.BadRequestError("Xendit customer account required.");
|
|
21590
21804
|
}
|
|
21591
|
-
value.billingAddress.org =
|
|
21805
|
+
value.billingAddress.org = orgId.toString();
|
|
21592
21806
|
await addAddress(value.billingAddress, session);
|
|
21593
21807
|
const description = "GoWeekdays Organization Monthly Subscription.";
|
|
21594
21808
|
if (value.promoCode) {
|
|
@@ -21637,7 +21851,7 @@ function useSubscriptionService() {
|
|
|
21637
21851
|
}
|
|
21638
21852
|
const subscription = await add(
|
|
21639
21853
|
{
|
|
21640
|
-
org:
|
|
21854
|
+
org: orgId.toString(),
|
|
21641
21855
|
customerId,
|
|
21642
21856
|
paymentMethodId: value.payment_method_id,
|
|
21643
21857
|
amount,
|
|
@@ -21668,7 +21882,7 @@ function useSubscriptionService() {
|
|
|
21668
21882
|
amount,
|
|
21669
21883
|
dueDate: /* @__PURE__ */ new Date(),
|
|
21670
21884
|
metadata: {
|
|
21671
|
-
orgId:
|
|
21885
|
+
orgId: orgId.toString(),
|
|
21672
21886
|
currency: value.currency,
|
|
21673
21887
|
subscriptionId: subscription.toString(),
|
|
21674
21888
|
description: `Initial invoice for ${value.seats.toLocaleString()} seats`
|
|
@@ -21704,7 +21918,7 @@ function useSubscriptionService() {
|
|
|
21704
21918
|
status: "completed",
|
|
21705
21919
|
metadata: {
|
|
21706
21920
|
userId: value.user,
|
|
21707
|
-
orgId:
|
|
21921
|
+
orgId: orgId.toString(),
|
|
21708
21922
|
currency: value.currency,
|
|
21709
21923
|
paymentMethod: value.payment_method_channel,
|
|
21710
21924
|
paymentMethodType: value.payment_method_type,
|
|
@@ -21718,7 +21932,7 @@ function useSubscriptionService() {
|
|
|
21718
21932
|
await session?.commitTransaction();
|
|
21719
21933
|
return {
|
|
21720
21934
|
message: "Subscription created successfully.",
|
|
21721
|
-
data: { org:
|
|
21935
|
+
data: { org: orgId.toString() }
|
|
21722
21936
|
};
|
|
21723
21937
|
} catch (error) {
|
|
21724
21938
|
await session?.abortTransaction();
|
|
@@ -21984,8 +22198,8 @@ function useSubscriptionService() {
|
|
|
21984
22198
|
session?.startTransaction();
|
|
21985
22199
|
try {
|
|
21986
22200
|
const payment = await pay({
|
|
21987
|
-
customer_id: sub.customerId,
|
|
21988
|
-
payment_method_id: sub.paymentMethodId,
|
|
22201
|
+
customer_id: sub.customerId ?? "",
|
|
22202
|
+
payment_method_id: sub.paymentMethodId ?? "",
|
|
21989
22203
|
amount: sub.amount,
|
|
21990
22204
|
currency: sub.currency,
|
|
21991
22205
|
description
|
|
@@ -21994,7 +22208,7 @@ function useSubscriptionService() {
|
|
|
21994
22208
|
throw new import_utils69.BadRequestError("Failed to process payment.");
|
|
21995
22209
|
}
|
|
21996
22210
|
const customerPaymentMethod = await getPaymentMethodById(
|
|
21997
|
-
sub.paymentMethodId
|
|
22211
|
+
sub.paymentMethodId ?? ""
|
|
21998
22212
|
);
|
|
21999
22213
|
const paymentData = {
|
|
22000
22214
|
invoiceId: invoiceNumber,
|
|
@@ -22286,15 +22500,15 @@ function useSubscriptionService() {
|
|
|
22286
22500
|
let payment = {};
|
|
22287
22501
|
if (amount) {
|
|
22288
22502
|
payment = await pay({
|
|
22289
|
-
customer_id: subscription.customerId,
|
|
22290
|
-
payment_method_id: subscription.paymentMethodId,
|
|
22503
|
+
customer_id: subscription.customerId ?? "",
|
|
22504
|
+
payment_method_id: subscription.paymentMethodId ?? "",
|
|
22291
22505
|
amount: formatAmount(amount),
|
|
22292
22506
|
currency: subscription.currency,
|
|
22293
22507
|
description: "GoWeekdays Organization Monthly Subscription."
|
|
22294
22508
|
});
|
|
22295
22509
|
}
|
|
22296
22510
|
const paymentMethod = await getPaymentMethodById(
|
|
22297
|
-
subscription.paymentMethodId
|
|
22511
|
+
subscription.paymentMethodId ?? ""
|
|
22298
22512
|
);
|
|
22299
22513
|
if (!paymentMethod) {
|
|
22300
22514
|
throw new import_utils69.BadRequestError("Payment method not found.");
|
|
@@ -22371,13 +22585,116 @@ function useSubscriptionService() {
|
|
|
22371
22585
|
session?.endSession();
|
|
22372
22586
|
}
|
|
22373
22587
|
}
|
|
22588
|
+
async function processSubscriptionPayment(invoiceNumber, subscriptionId) {
|
|
22589
|
+
const invoice = await getByNumber(invoiceNumber);
|
|
22590
|
+
if (!invoice) {
|
|
22591
|
+
throw new import_utils69.BadRequestError("Invoice not found.");
|
|
22592
|
+
}
|
|
22593
|
+
if (invoice.status === "paid") {
|
|
22594
|
+
throw new import_utils69.BadRequestError("Invoice already paid.");
|
|
22595
|
+
}
|
|
22596
|
+
if (!invoice._id) {
|
|
22597
|
+
throw new import_utils69.BadRequestError("Invoice ID is missing.");
|
|
22598
|
+
}
|
|
22599
|
+
if (!invoice.metadata?.subscriptionId) {
|
|
22600
|
+
throw new import_utils69.BadRequestError("Subscription ID is missing.");
|
|
22601
|
+
}
|
|
22602
|
+
if (invoice.metadata.subscriptionId.toString() !== subscriptionId) {
|
|
22603
|
+
throw new import_utils69.BadRequestError("Subscription ID does not match invoice.");
|
|
22604
|
+
}
|
|
22605
|
+
const subscription = await _getById(invoice.metadata.subscriptionId);
|
|
22606
|
+
if (!subscription) {
|
|
22607
|
+
throw new import_utils69.BadRequestError("Subscription not found.");
|
|
22608
|
+
}
|
|
22609
|
+
if (!subscription._id) {
|
|
22610
|
+
throw new import_utils69.BadRequestError("Subscription ID is missing.");
|
|
22611
|
+
}
|
|
22612
|
+
if (!subscription.customerId) {
|
|
22613
|
+
throw new import_utils69.BadRequestError("Customer ID is missing.");
|
|
22614
|
+
}
|
|
22615
|
+
if (!subscription.paymentMethodId) {
|
|
22616
|
+
throw new import_utils69.BadRequestError("Payment method ID is missing.");
|
|
22617
|
+
}
|
|
22618
|
+
if (!subscription.amount) {
|
|
22619
|
+
throw new import_utils69.BadRequestError("Subscription amount is missing.");
|
|
22620
|
+
}
|
|
22621
|
+
if (!subscription.currency) {
|
|
22622
|
+
throw new import_utils69.BadRequestError("Subscription currency is missing.");
|
|
22623
|
+
}
|
|
22624
|
+
const session = import_utils69.useAtlas.getClient()?.startSession();
|
|
22625
|
+
try {
|
|
22626
|
+
session?.startTransaction();
|
|
22627
|
+
const payment = await pay({
|
|
22628
|
+
customer_id: subscription.customerId,
|
|
22629
|
+
payment_method_id: subscription.paymentMethodId,
|
|
22630
|
+
amount: subscription.amount,
|
|
22631
|
+
currency: subscription.currency,
|
|
22632
|
+
description: "GoWeekdays Subscription Payment"
|
|
22633
|
+
});
|
|
22634
|
+
if (!payment.id) {
|
|
22635
|
+
throw new import_utils69.BadRequestError("Failed to process payment.");
|
|
22636
|
+
}
|
|
22637
|
+
const paymentMethod = await getPaymentMethodById(
|
|
22638
|
+
subscription.paymentMethodId
|
|
22639
|
+
);
|
|
22640
|
+
if (!paymentMethod) {
|
|
22641
|
+
throw new import_utils69.BadRequestError("Payment method not found.");
|
|
22642
|
+
}
|
|
22643
|
+
const paymentData = {
|
|
22644
|
+
invoiceId: invoiceNumber,
|
|
22645
|
+
amount: subscription.amount,
|
|
22646
|
+
paymentMethod: paymentMethod.type,
|
|
22647
|
+
status: "completed",
|
|
22648
|
+
metadata: {
|
|
22649
|
+
userId: String(subscription.user),
|
|
22650
|
+
orgId: String(subscription.org),
|
|
22651
|
+
currency: subscription.currency,
|
|
22652
|
+
paymentMethod: paymentMethod.type === "EWALLET" ? paymentMethod.ewallet.channel_code : paymentMethod.type === "DIRECT_DEBIT" ? paymentMethod.direct_debit.channel_code : "",
|
|
22653
|
+
paymentMethodType: paymentMethod.type,
|
|
22654
|
+
paymentMethodId: subscription.paymentMethodId,
|
|
22655
|
+
payment: payment.id,
|
|
22656
|
+
subscriptionId: subscription._id.toString()
|
|
22657
|
+
}
|
|
22658
|
+
};
|
|
22659
|
+
if (!paymentData.metadata.userId) {
|
|
22660
|
+
delete paymentData.metadata.userId;
|
|
22661
|
+
}
|
|
22662
|
+
if (!paymentData.metadata.orgId) {
|
|
22663
|
+
delete paymentData.metadata.orgId;
|
|
22664
|
+
}
|
|
22665
|
+
await addPayment(paymentData, session);
|
|
22666
|
+
await updateStatusByInvoiceNumber(invoiceNumber, "paid", session);
|
|
22667
|
+
await processSuccessfulPayment(
|
|
22668
|
+
{
|
|
22669
|
+
_id: subscription._id.toString(),
|
|
22670
|
+
nextBillingDate: subscription.nextBillingDate
|
|
22671
|
+
},
|
|
22672
|
+
session
|
|
22673
|
+
);
|
|
22674
|
+
await session?.commitTransaction();
|
|
22675
|
+
} catch (error) {
|
|
22676
|
+
await session?.abortTransaction();
|
|
22677
|
+
import_utils69.logger.log({
|
|
22678
|
+
level: "error",
|
|
22679
|
+
message: `Failed to process subscription payment: ${error}`
|
|
22680
|
+
});
|
|
22681
|
+
if (error instanceof import_utils69.AppError) {
|
|
22682
|
+
throw error;
|
|
22683
|
+
}
|
|
22684
|
+
throw new import_utils69.BadRequestError("Failed to process subscription payment.");
|
|
22685
|
+
} finally {
|
|
22686
|
+
session?.endSession();
|
|
22687
|
+
}
|
|
22688
|
+
}
|
|
22374
22689
|
return {
|
|
22690
|
+
subscribe,
|
|
22375
22691
|
getByUserId,
|
|
22376
22692
|
getStatusByUser,
|
|
22377
22693
|
createAffiliateSubscription,
|
|
22378
22694
|
createOrgSubscription,
|
|
22379
22695
|
processSubscriptions,
|
|
22380
|
-
updateSeatsById
|
|
22696
|
+
updateSeatsById,
|
|
22697
|
+
processSubscriptionPayment
|
|
22381
22698
|
};
|
|
22382
22699
|
}
|
|
22383
22700
|
|
|
@@ -22445,8 +22762,39 @@ function useSubscriptionController() {
|
|
|
22445
22762
|
getStatusByUser: _getStatusByUser,
|
|
22446
22763
|
createAffiliateSubscription: _createAffiliateSubscription,
|
|
22447
22764
|
createOrgSubscription: _createOrgSubscription,
|
|
22448
|
-
updateSeatsById: _updateSubscriptionSeats
|
|
22765
|
+
updateSeatsById: _updateSubscriptionSeats,
|
|
22766
|
+
processSubscriptionPayment: _processSubscriptionPayment,
|
|
22767
|
+
subscribe: _subscribe
|
|
22449
22768
|
} = useSubscriptionService();
|
|
22769
|
+
async function subscribe(req, res, next) {
|
|
22770
|
+
const value = req.body;
|
|
22771
|
+
const validation = import_joi20.default.object({
|
|
22772
|
+
user: import_joi20.default.string().hex().required(),
|
|
22773
|
+
transactionId: import_joi20.default.string().required(),
|
|
22774
|
+
promoCode: import_joi20.default.string().optional().allow("", null),
|
|
22775
|
+
seats: import_joi20.default.number().min(1).required(),
|
|
22776
|
+
perSeatPrice: import_joi20.default.number().min(0).required(),
|
|
22777
|
+
currency: import_joi20.default.string().required(),
|
|
22778
|
+
org: import_joi20.default.object({
|
|
22779
|
+
name: import_joi20.default.string().required(),
|
|
22780
|
+
email: import_joi20.default.string().email().required(),
|
|
22781
|
+
contact: import_joi20.default.string().optional().allow("", null),
|
|
22782
|
+
busInst: import_joi20.default.string().optional().allow("", null),
|
|
22783
|
+
type: import_joi20.default.string().valid("personal", "business").required()
|
|
22784
|
+
})
|
|
22785
|
+
});
|
|
22786
|
+
const { error } = validation.validate(value);
|
|
22787
|
+
if (error) {
|
|
22788
|
+
next(new import_utils70.BadRequestError(error.message));
|
|
22789
|
+
}
|
|
22790
|
+
try {
|
|
22791
|
+
const id = await _subscribe(value);
|
|
22792
|
+
res.json({ message: "Successfully subscribed.", id });
|
|
22793
|
+
return;
|
|
22794
|
+
} catch (error2) {
|
|
22795
|
+
next(error2);
|
|
22796
|
+
}
|
|
22797
|
+
}
|
|
22450
22798
|
async function add(req, res, next) {
|
|
22451
22799
|
const value = req.body;
|
|
22452
22800
|
const validation = import_joi20.default.object({
|
|
@@ -22576,7 +22924,6 @@ function useSubscriptionController() {
|
|
|
22576
22924
|
res.json({ message: "Successfully added subscription.", id });
|
|
22577
22925
|
return;
|
|
22578
22926
|
} catch (error2) {
|
|
22579
|
-
console.log(error2);
|
|
22580
22927
|
next(error2);
|
|
22581
22928
|
return;
|
|
22582
22929
|
}
|
|
@@ -22744,7 +23091,28 @@ function useSubscriptionController() {
|
|
|
22744
23091
|
return;
|
|
22745
23092
|
}
|
|
22746
23093
|
}
|
|
23094
|
+
async function processSubscriptionPayment(req, res, next) {
|
|
23095
|
+
const id = req.params.id ?? "";
|
|
23096
|
+
const invoiceNumber = req.body.invoice ?? "";
|
|
23097
|
+
const { error } = import_joi20.default.object({
|
|
23098
|
+
id: import_joi20.default.string().hex().required(),
|
|
23099
|
+
invoiceNumber: import_joi20.default.string().required()
|
|
23100
|
+
}).validate({ id, invoiceNumber });
|
|
23101
|
+
if (error) {
|
|
23102
|
+
next(new import_utils70.BadRequestError(error.message));
|
|
23103
|
+
return;
|
|
23104
|
+
}
|
|
23105
|
+
try {
|
|
23106
|
+
const payment = await _processSubscriptionPayment(invoiceNumber, id);
|
|
23107
|
+
res.json(payment);
|
|
23108
|
+
return;
|
|
23109
|
+
} catch (error2) {
|
|
23110
|
+
next(error2);
|
|
23111
|
+
return;
|
|
23112
|
+
}
|
|
23113
|
+
}
|
|
22747
23114
|
return {
|
|
23115
|
+
subscribe,
|
|
22748
23116
|
add,
|
|
22749
23117
|
getByUserId,
|
|
22750
23118
|
getByOrgId,
|
|
@@ -22760,30 +23128,31 @@ function useSubscriptionController() {
|
|
|
22760
23128
|
updatePaymentMethodById,
|
|
22761
23129
|
addBillingContactById,
|
|
22762
23130
|
updateBillingContactByAddedAt,
|
|
22763
|
-
deleteBillingContactByAddedAt
|
|
23131
|
+
deleteBillingContactByAddedAt,
|
|
23132
|
+
processSubscriptionPayment
|
|
22764
23133
|
};
|
|
22765
23134
|
}
|
|
22766
23135
|
|
|
22767
23136
|
// src/models/payment-method.model.ts
|
|
22768
23137
|
var import_utils71 = require("@goweekdays/utils");
|
|
22769
|
-
var
|
|
23138
|
+
var import_mongodb35 = require("mongodb");
|
|
22770
23139
|
function MPaymentMethod(value) {
|
|
22771
23140
|
if (value.user) {
|
|
22772
23141
|
try {
|
|
22773
|
-
value.user = new
|
|
23142
|
+
value.user = new import_mongodb35.ObjectId(value.user);
|
|
22774
23143
|
} catch (error) {
|
|
22775
23144
|
throw new import_utils71.BadRequestError("Invalid user ID.");
|
|
22776
23145
|
}
|
|
22777
23146
|
}
|
|
22778
23147
|
if (value.org) {
|
|
22779
23148
|
try {
|
|
22780
|
-
value.org = new
|
|
23149
|
+
value.org = new import_mongodb35.ObjectId(value.org);
|
|
22781
23150
|
} catch (error) {
|
|
22782
23151
|
throw new import_utils71.BadRequestError("Invalid org ID.");
|
|
22783
23152
|
}
|
|
22784
23153
|
}
|
|
22785
23154
|
return {
|
|
22786
|
-
_id: value._id ?? new
|
|
23155
|
+
_id: value._id ?? new import_mongodb35.ObjectId(),
|
|
22787
23156
|
user: value.user ?? "",
|
|
22788
23157
|
org: value.org ?? "",
|
|
22789
23158
|
name: value.name,
|
|
@@ -22803,7 +23172,7 @@ function MPaymentMethod(value) {
|
|
|
22803
23172
|
|
|
22804
23173
|
// src/repositories/payment-method.repository.ts
|
|
22805
23174
|
var import_utils72 = require("@goweekdays/utils");
|
|
22806
|
-
var
|
|
23175
|
+
var import_mongodb36 = require("mongodb");
|
|
22807
23176
|
function usePaymentMethodRepo() {
|
|
22808
23177
|
const db = import_utils72.useAtlas.getDb();
|
|
22809
23178
|
if (!db) {
|
|
@@ -22856,7 +23225,7 @@ function usePaymentMethodRepo() {
|
|
|
22856
23225
|
}
|
|
22857
23226
|
function getByUser(user) {
|
|
22858
23227
|
try {
|
|
22859
|
-
user = new
|
|
23228
|
+
user = new import_mongodb36.ObjectId(user);
|
|
22860
23229
|
} catch (error) {
|
|
22861
23230
|
throw new import_utils72.BadRequestError("Invalid user ID.");
|
|
22862
23231
|
}
|
|
@@ -22881,7 +23250,7 @@ function usePaymentMethodRepo() {
|
|
|
22881
23250
|
}
|
|
22882
23251
|
function getByOrg(org) {
|
|
22883
23252
|
try {
|
|
22884
|
-
org = new
|
|
23253
|
+
org = new import_mongodb36.ObjectId(org);
|
|
22885
23254
|
} catch (error) {
|
|
22886
23255
|
throw new import_utils72.BadRequestError("Invalid org ID.");
|
|
22887
23256
|
}
|
|
@@ -22916,7 +23285,7 @@ function usePaymentMethodRepo() {
|
|
|
22916
23285
|
}
|
|
22917
23286
|
async function deleteById(_id) {
|
|
22918
23287
|
try {
|
|
22919
|
-
_id = new
|
|
23288
|
+
_id = new import_mongodb36.ObjectId(_id);
|
|
22920
23289
|
} catch (error) {
|
|
22921
23290
|
throw new import_utils72.BadRequestError("Invalid payment method ID.");
|
|
22922
23291
|
}
|
|
@@ -23060,7 +23429,6 @@ function usePaymentMethodService() {
|
|
|
23060
23429
|
await session?.commitTransaction();
|
|
23061
23430
|
return result;
|
|
23062
23431
|
} catch (error) {
|
|
23063
|
-
console.log(error);
|
|
23064
23432
|
await session?.abortTransaction();
|
|
23065
23433
|
throw error;
|
|
23066
23434
|
} finally {
|
|
@@ -23082,7 +23450,9 @@ function usePaymentMethodController() {
|
|
|
23082
23450
|
cardLinkOnly,
|
|
23083
23451
|
directDebitLinkOnly,
|
|
23084
23452
|
eWalletLinkOnly,
|
|
23085
|
-
getPaymentMethodById: _getPaymentMethodById
|
|
23453
|
+
getPaymentMethodById: _getPaymentMethodById,
|
|
23454
|
+
getPaymentMethodsByCustomerId: _getPaymentMethodsByCustomerId,
|
|
23455
|
+
updatePaymentMethodStatusById: _updatePaymentMethodStatusById
|
|
23086
23456
|
} = useXenditService();
|
|
23087
23457
|
async function linkEWallet(req, res, next) {
|
|
23088
23458
|
const type = req.body.type ?? "";
|
|
@@ -23232,7 +23602,7 @@ function usePaymentMethodController() {
|
|
|
23232
23602
|
const type = req.body.type ?? "";
|
|
23233
23603
|
if (type === "CARD") {
|
|
23234
23604
|
try {
|
|
23235
|
-
|
|
23605
|
+
CardPaymentSchema.parse(req.body);
|
|
23236
23606
|
} catch (error) {
|
|
23237
23607
|
next(new import_utils74.BadRequestError(error.issues[0].message));
|
|
23238
23608
|
return;
|
|
@@ -23281,13 +23651,49 @@ function usePaymentMethodController() {
|
|
|
23281
23651
|
next(new import_utils74.BadRequestError("Invalid type"));
|
|
23282
23652
|
return;
|
|
23283
23653
|
}
|
|
23654
|
+
async function getPaymentMethodsByCustomerId(req, res, next) {
|
|
23655
|
+
const id = req.params.id ?? "";
|
|
23656
|
+
const validation = import_joi21.default.object({
|
|
23657
|
+
id: import_joi21.default.string().required()
|
|
23658
|
+
});
|
|
23659
|
+
const { error } = validation.validate({ id });
|
|
23660
|
+
if (error) {
|
|
23661
|
+
next(new import_utils74.BadRequestError(error.message));
|
|
23662
|
+
}
|
|
23663
|
+
try {
|
|
23664
|
+
const result = await _getPaymentMethodsByCustomerId(id);
|
|
23665
|
+
res.json(result);
|
|
23666
|
+
} catch (error2) {
|
|
23667
|
+
next(error2);
|
|
23668
|
+
}
|
|
23669
|
+
}
|
|
23670
|
+
async function updatePaymentMethodStatusById(req, res, next) {
|
|
23671
|
+
const id = req.params.id ?? "";
|
|
23672
|
+
const status = req.body.status ?? "";
|
|
23673
|
+
const validation = import_joi21.default.object({
|
|
23674
|
+
id: import_joi21.default.string().required(),
|
|
23675
|
+
status: import_joi21.default.string().valid("ACTIVE", "INACTIVE").required()
|
|
23676
|
+
});
|
|
23677
|
+
const { error } = validation.validate({ id, status });
|
|
23678
|
+
if (error) {
|
|
23679
|
+
next(new import_utils74.BadRequestError(error.message));
|
|
23680
|
+
}
|
|
23681
|
+
try {
|
|
23682
|
+
const result = await _updatePaymentMethodStatusById(id, status);
|
|
23683
|
+
res.json(result);
|
|
23684
|
+
} catch (error2) {
|
|
23685
|
+
next(error2);
|
|
23686
|
+
}
|
|
23687
|
+
}
|
|
23284
23688
|
return {
|
|
23285
23689
|
linkEWallet,
|
|
23286
23690
|
linkCard,
|
|
23287
23691
|
getByUser,
|
|
23288
23692
|
getByOrg,
|
|
23289
23693
|
linkOnly,
|
|
23290
|
-
getPaymentMethodById
|
|
23694
|
+
getPaymentMethodById,
|
|
23695
|
+
getPaymentMethodsByCustomerId,
|
|
23696
|
+
updatePaymentMethodStatusById
|
|
23291
23697
|
};
|
|
23292
23698
|
}
|
|
23293
23699
|
|
|
@@ -23339,7 +23745,8 @@ function useAddressController() {
|
|
|
23339
23745
|
city: import_joi22.default.string().required(),
|
|
23340
23746
|
province: import_joi22.default.string().required(),
|
|
23341
23747
|
postalCode: import_joi22.default.string().required(),
|
|
23342
|
-
taxId: import_joi22.default.string().optional().allow("", null)
|
|
23748
|
+
taxId: import_joi22.default.string().optional().allow("", null),
|
|
23749
|
+
org: import_joi22.default.string().hex().optional().allow("", null)
|
|
23343
23750
|
});
|
|
23344
23751
|
const { error } = validation.validate({ id, ...value });
|
|
23345
23752
|
if (error) {
|
|
@@ -23785,7 +24192,7 @@ function usePromoCodeController() {
|
|
|
23785
24192
|
}
|
|
23786
24193
|
|
|
23787
24194
|
// src/models/order.model.ts
|
|
23788
|
-
var
|
|
24195
|
+
var import_mongodb37 = require("mongodb");
|
|
23789
24196
|
|
|
23790
24197
|
// src/validations/order.schema.ts
|
|
23791
24198
|
var import_joi26 = __toESM(require("joi"));
|
|
@@ -23819,28 +24226,28 @@ function MOrder(value) {
|
|
|
23819
24226
|
}
|
|
23820
24227
|
if (value._id) {
|
|
23821
24228
|
try {
|
|
23822
|
-
value._id = new
|
|
24229
|
+
value._id = new import_mongodb37.ObjectId(value._id);
|
|
23823
24230
|
} catch (error2) {
|
|
23824
24231
|
throw new import_utils80.BadRequestError("Invalid ID.");
|
|
23825
24232
|
}
|
|
23826
24233
|
}
|
|
23827
24234
|
if (value.user) {
|
|
23828
24235
|
try {
|
|
23829
|
-
value.user = new
|
|
24236
|
+
value.user = new import_mongodb37.ObjectId(value.user);
|
|
23830
24237
|
} catch (error2) {
|
|
23831
24238
|
throw new import_utils80.BadRequestError("Invalid user ID.");
|
|
23832
24239
|
}
|
|
23833
24240
|
}
|
|
23834
24241
|
if (value.org) {
|
|
23835
24242
|
try {
|
|
23836
|
-
value.org = new
|
|
24243
|
+
value.org = new import_mongodb37.ObjectId(value.org);
|
|
23837
24244
|
} catch (error2) {
|
|
23838
24245
|
throw new import_utils80.BadRequestError("Invalid org ID.");
|
|
23839
24246
|
}
|
|
23840
24247
|
}
|
|
23841
24248
|
if (value.metadata?.subscriptionId) {
|
|
23842
24249
|
try {
|
|
23843
|
-
value.metadata.subscriptionId = new
|
|
24250
|
+
value.metadata.subscriptionId = new import_mongodb37.ObjectId(
|
|
23844
24251
|
value.metadata.subscriptionId
|
|
23845
24252
|
);
|
|
23846
24253
|
} catch (error2) {
|
|
@@ -23866,7 +24273,7 @@ function MOrder(value) {
|
|
|
23866
24273
|
|
|
23867
24274
|
// src/repositories/order.repository.ts
|
|
23868
24275
|
var import_utils81 = require("@goweekdays/utils");
|
|
23869
|
-
var
|
|
24276
|
+
var import_mongodb38 = require("mongodb");
|
|
23870
24277
|
function useOrderRepo() {
|
|
23871
24278
|
const db = import_utils81.useAtlas.getDb();
|
|
23872
24279
|
if (!db) {
|
|
@@ -23916,7 +24323,7 @@ function useOrderRepo() {
|
|
|
23916
24323
|
}
|
|
23917
24324
|
if (id) {
|
|
23918
24325
|
try {
|
|
23919
|
-
query["metadata.subscriptionId"] = new
|
|
24326
|
+
query["metadata.subscriptionId"] = new import_mongodb38.ObjectId(id);
|
|
23920
24327
|
} catch (error) {
|
|
23921
24328
|
throw new import_utils81.BadRequestError("Invalid subscription ID.");
|
|
23922
24329
|
}
|
|
@@ -23987,7 +24394,7 @@ function useOrderController() {
|
|
|
23987
24394
|
// src/services/invoice.service.ts
|
|
23988
24395
|
var import_utils83 = require("@goweekdays/utils");
|
|
23989
24396
|
function useInvoiceService() {
|
|
23990
|
-
const { getOverdueInvoices, updateStatusByInvoiceNumber } = useInvoiceRepo();
|
|
24397
|
+
const { getOverdueInvoices, updateStatusByInvoiceNumber, getByNumber } = useInvoiceRepo();
|
|
23991
24398
|
const {
|
|
23992
24399
|
getById,
|
|
23993
24400
|
processSuccessfulPayment,
|
|
@@ -24056,8 +24463,8 @@ function useInvoiceService() {
|
|
|
24056
24463
|
const internalPayment = await getByInvoiceId(invoice.invoiceNumber);
|
|
24057
24464
|
if (!internalPayment) {
|
|
24058
24465
|
const payment = await pay({
|
|
24059
|
-
customer_id: subscription.customerId,
|
|
24060
|
-
payment_method_id: subscription.paymentMethodId,
|
|
24466
|
+
customer_id: subscription.customerId ?? "",
|
|
24467
|
+
payment_method_id: subscription.paymentMethodId ?? "",
|
|
24061
24468
|
amount: invoice.amount,
|
|
24062
24469
|
currency: invoice.metadata?.currency,
|
|
24063
24470
|
description: invoice.metadata?.description
|
|
@@ -24066,7 +24473,7 @@ function useInvoiceService() {
|
|
|
24066
24473
|
throw new import_utils83.BadRequestError("Failed to process payment.");
|
|
24067
24474
|
}
|
|
24068
24475
|
const customerPaymentMethod = await getPaymentMethodById(
|
|
24069
|
-
subscription.paymentMethodId
|
|
24476
|
+
subscription.paymentMethodId ?? ""
|
|
24070
24477
|
);
|
|
24071
24478
|
const paymentData = {
|
|
24072
24479
|
invoiceId: invoice.invoiceNumber,
|