@eeplatform/core 1.4.4 → 1.4.5
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 +6 -0
- package/dist/index.d.ts +41 -18
- package/dist/index.js +897 -248
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +897 -248
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -1
package/dist/index.js
CHANGED
|
@@ -10384,7 +10384,7 @@ var require_ms = __commonJS({
|
|
|
10384
10384
|
options = options || {};
|
|
10385
10385
|
var type = typeof val;
|
|
10386
10386
|
if (type === "string" && val.length > 0) {
|
|
10387
|
-
return
|
|
10387
|
+
return parse3(val);
|
|
10388
10388
|
} else if (type === "number" && isNaN(val) === false) {
|
|
10389
10389
|
return options.long ? fmtLong(val) : fmtShort(val);
|
|
10390
10390
|
}
|
|
@@ -10392,7 +10392,7 @@ var require_ms = __commonJS({
|
|
|
10392
10392
|
"val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
|
|
10393
10393
|
);
|
|
10394
10394
|
};
|
|
10395
|
-
function
|
|
10395
|
+
function parse3(str) {
|
|
10396
10396
|
str = String(str);
|
|
10397
10397
|
if (str.length > 100) {
|
|
10398
10398
|
return;
|
|
@@ -10839,7 +10839,7 @@ var require_follow_redirects = __commonJS({
|
|
|
10839
10839
|
(function detectUnsupportedEnvironment() {
|
|
10840
10840
|
var looksLikeNode = typeof process !== "undefined";
|
|
10841
10841
|
var looksLikeBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
10842
|
-
var looksLikeV8 =
|
|
10842
|
+
var looksLikeV8 = isFunction3(Error.captureStackTrace);
|
|
10843
10843
|
if (!looksLikeNode && (looksLikeBrowser || !looksLikeV8)) {
|
|
10844
10844
|
console.warn("The follow-redirects package should be excluded from browser builds.");
|
|
10845
10845
|
}
|
|
@@ -10934,7 +10934,7 @@ var require_follow_redirects = __commonJS({
|
|
|
10934
10934
|
if (!isString2(data) && !isBuffer2(data)) {
|
|
10935
10935
|
throw new TypeError("data should be a string, Buffer or Uint8Array");
|
|
10936
10936
|
}
|
|
10937
|
-
if (
|
|
10937
|
+
if (isFunction3(encoding)) {
|
|
10938
10938
|
callback = encoding;
|
|
10939
10939
|
encoding = null;
|
|
10940
10940
|
}
|
|
@@ -10954,10 +10954,10 @@ var require_follow_redirects = __commonJS({
|
|
|
10954
10954
|
}
|
|
10955
10955
|
};
|
|
10956
10956
|
RedirectableRequest.prototype.end = function(data, encoding, callback) {
|
|
10957
|
-
if (
|
|
10957
|
+
if (isFunction3(data)) {
|
|
10958
10958
|
callback = data;
|
|
10959
10959
|
data = encoding = null;
|
|
10960
|
-
} else if (
|
|
10960
|
+
} else if (isFunction3(encoding)) {
|
|
10961
10961
|
callback = encoding;
|
|
10962
10962
|
encoding = null;
|
|
10963
10963
|
}
|
|
@@ -11158,7 +11158,7 @@ var require_follow_redirects = __commonJS({
|
|
|
11158
11158
|
if (redirectUrl.protocol !== currentUrlParts.protocol && redirectUrl.protocol !== "https:" || redirectUrl.host !== currentHost && !isSubdomain(redirectUrl.host, currentHost)) {
|
|
11159
11159
|
removeMatchingHeaders(/^(?:(?:proxy-)?authorization|cookie)$/i, this._options.headers);
|
|
11160
11160
|
}
|
|
11161
|
-
if (
|
|
11161
|
+
if (isFunction3(beforeRedirect)) {
|
|
11162
11162
|
var responseDetails = {
|
|
11163
11163
|
headers: response.headers,
|
|
11164
11164
|
statusCode
|
|
@@ -11193,7 +11193,7 @@ var require_follow_redirects = __commonJS({
|
|
|
11193
11193
|
options = validateUrl(input);
|
|
11194
11194
|
input = { protocol };
|
|
11195
11195
|
}
|
|
11196
|
-
if (
|
|
11196
|
+
if (isFunction3(options)) {
|
|
11197
11197
|
callback = options;
|
|
11198
11198
|
options = null;
|
|
11199
11199
|
}
|
|
@@ -11273,7 +11273,7 @@ var require_follow_redirects = __commonJS({
|
|
|
11273
11273
|
}
|
|
11274
11274
|
function createErrorType(code, message, baseClass) {
|
|
11275
11275
|
function CustomError(properties) {
|
|
11276
|
-
if (
|
|
11276
|
+
if (isFunction3(Error.captureStackTrace)) {
|
|
11277
11277
|
Error.captureStackTrace(this, this.constructor);
|
|
11278
11278
|
}
|
|
11279
11279
|
Object.assign(this, properties || {});
|
|
@@ -11308,7 +11308,7 @@ var require_follow_redirects = __commonJS({
|
|
|
11308
11308
|
function isString2(value) {
|
|
11309
11309
|
return typeof value === "string" || value instanceof String;
|
|
11310
11310
|
}
|
|
11311
|
-
function
|
|
11311
|
+
function isFunction3(value) {
|
|
11312
11312
|
return typeof value === "function";
|
|
11313
11313
|
}
|
|
11314
11314
|
function isBuffer2(value) {
|
|
@@ -13652,7 +13652,7 @@ var _global = (() => {
|
|
|
13652
13652
|
})();
|
|
13653
13653
|
var isContextDefined = (context) => !isUndefined(context) && context !== _global;
|
|
13654
13654
|
function merge() {
|
|
13655
|
-
const { caseless } = isContextDefined(this) && this || {};
|
|
13655
|
+
const { caseless, skipUndefined } = isContextDefined(this) && this || {};
|
|
13656
13656
|
const result = {};
|
|
13657
13657
|
const assignValue = (val, key) => {
|
|
13658
13658
|
const targetKey = caseless && findKey(result, key) || key;
|
|
@@ -13662,7 +13662,7 @@ function merge() {
|
|
|
13662
13662
|
result[targetKey] = merge({}, val);
|
|
13663
13663
|
} else if (isArray(val)) {
|
|
13664
13664
|
result[targetKey] = val.slice();
|
|
13665
|
-
} else {
|
|
13665
|
+
} else if (!skipUndefined || !isUndefined(val)) {
|
|
13666
13666
|
result[targetKey] = val;
|
|
13667
13667
|
}
|
|
13668
13668
|
};
|
|
@@ -13998,9 +13998,13 @@ AxiosError.from = (error, code, config2, request, response, customProps) => {
|
|
|
13998
13998
|
}, (prop) => {
|
|
13999
13999
|
return prop !== "isAxiosError";
|
|
14000
14000
|
});
|
|
14001
|
-
|
|
14002
|
-
|
|
14003
|
-
axiosError
|
|
14001
|
+
const msg = error && error.message ? error.message : "Error";
|
|
14002
|
+
const errCode = code == null && error ? error.code : code;
|
|
14003
|
+
AxiosError.call(axiosError, msg, errCode, config2, request, response);
|
|
14004
|
+
if (error && axiosError.cause == null) {
|
|
14005
|
+
Object.defineProperty(axiosError, "cause", { value: error, configurable: true });
|
|
14006
|
+
}
|
|
14007
|
+
axiosError.name = error && error.name || "Error";
|
|
14004
14008
|
customProps && Object.assign(axiosError, customProps);
|
|
14005
14009
|
return axiosError;
|
|
14006
14010
|
};
|
|
@@ -14163,7 +14167,7 @@ var AxiosURLSearchParams_default = AxiosURLSearchParams;
|
|
|
14163
14167
|
|
|
14164
14168
|
// node_modules/axios/lib/helpers/buildURL.js
|
|
14165
14169
|
function encode2(val) {
|
|
14166
|
-
return encodeURIComponent(val).replace(/%3A/gi, ":").replace(/%24/g, "$").replace(/%2C/gi, ",").replace(/%20/g, "+")
|
|
14170
|
+
return encodeURIComponent(val).replace(/%3A/gi, ":").replace(/%24/g, "$").replace(/%2C/gi, ",").replace(/%20/g, "+");
|
|
14167
14171
|
}
|
|
14168
14172
|
function buildURL(url2, params, options) {
|
|
14169
14173
|
if (!params) {
|
|
@@ -14461,7 +14465,7 @@ var defaults = {
|
|
|
14461
14465
|
const silentJSONParsing = transitional2 && transitional2.silentJSONParsing;
|
|
14462
14466
|
const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
|
14463
14467
|
try {
|
|
14464
|
-
return JSON.parse(data);
|
|
14468
|
+
return JSON.parse(data, this.parseReviver);
|
|
14465
14469
|
} catch (e) {
|
|
14466
14470
|
if (strictJSONParsing) {
|
|
14467
14471
|
if (e.name === "SyntaxError") {
|
|
@@ -14848,7 +14852,7 @@ var import_follow_redirects = __toESM(require_follow_redirects(), 1);
|
|
|
14848
14852
|
var import_zlib = __toESM(require("zlib"), 1);
|
|
14849
14853
|
|
|
14850
14854
|
// node_modules/axios/lib/env/data.js
|
|
14851
|
-
var VERSION = "1.
|
|
14855
|
+
var VERSION = "1.12.2";
|
|
14852
14856
|
|
|
14853
14857
|
// node_modules/axios/lib/helpers/parseProtocol.js
|
|
14854
14858
|
function parseProtocol(url2) {
|
|
@@ -15247,6 +15251,60 @@ var progressEventDecorator = (total, throttled) => {
|
|
|
15247
15251
|
};
|
|
15248
15252
|
var asyncDecorator = (fn) => (...args) => utils_default.asap(() => fn(...args));
|
|
15249
15253
|
|
|
15254
|
+
// node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js
|
|
15255
|
+
function estimateDataURLDecodedBytes(url2) {
|
|
15256
|
+
if (!url2 || typeof url2 !== "string")
|
|
15257
|
+
return 0;
|
|
15258
|
+
if (!url2.startsWith("data:"))
|
|
15259
|
+
return 0;
|
|
15260
|
+
const comma = url2.indexOf(",");
|
|
15261
|
+
if (comma < 0)
|
|
15262
|
+
return 0;
|
|
15263
|
+
const meta = url2.slice(5, comma);
|
|
15264
|
+
const body = url2.slice(comma + 1);
|
|
15265
|
+
const isBase64 = /;base64/i.test(meta);
|
|
15266
|
+
if (isBase64) {
|
|
15267
|
+
let effectiveLen = body.length;
|
|
15268
|
+
const len = body.length;
|
|
15269
|
+
for (let i = 0; i < len; i++) {
|
|
15270
|
+
if (body.charCodeAt(i) === 37 && i + 2 < len) {
|
|
15271
|
+
const a = body.charCodeAt(i + 1);
|
|
15272
|
+
const b = body.charCodeAt(i + 2);
|
|
15273
|
+
const isHex = (a >= 48 && a <= 57 || a >= 65 && a <= 70 || a >= 97 && a <= 102) && (b >= 48 && b <= 57 || b >= 65 && b <= 70 || b >= 97 && b <= 102);
|
|
15274
|
+
if (isHex) {
|
|
15275
|
+
effectiveLen -= 2;
|
|
15276
|
+
i += 2;
|
|
15277
|
+
}
|
|
15278
|
+
}
|
|
15279
|
+
}
|
|
15280
|
+
let pad = 0;
|
|
15281
|
+
let idx = len - 1;
|
|
15282
|
+
const tailIsPct3D = (j) => j >= 2 && body.charCodeAt(j - 2) === 37 && // '%'
|
|
15283
|
+
body.charCodeAt(j - 1) === 51 && // '3'
|
|
15284
|
+
(body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100);
|
|
15285
|
+
if (idx >= 0) {
|
|
15286
|
+
if (body.charCodeAt(idx) === 61) {
|
|
15287
|
+
pad++;
|
|
15288
|
+
idx--;
|
|
15289
|
+
} else if (tailIsPct3D(idx)) {
|
|
15290
|
+
pad++;
|
|
15291
|
+
idx -= 3;
|
|
15292
|
+
}
|
|
15293
|
+
}
|
|
15294
|
+
if (pad === 1 && idx >= 0) {
|
|
15295
|
+
if (body.charCodeAt(idx) === 61) {
|
|
15296
|
+
pad++;
|
|
15297
|
+
} else if (tailIsPct3D(idx)) {
|
|
15298
|
+
pad++;
|
|
15299
|
+
}
|
|
15300
|
+
}
|
|
15301
|
+
const groups = Math.floor(effectiveLen / 4);
|
|
15302
|
+
const bytes = groups * 3 - (pad || 0);
|
|
15303
|
+
return bytes > 0 ? bytes : 0;
|
|
15304
|
+
}
|
|
15305
|
+
return Buffer.byteLength(body, "utf8");
|
|
15306
|
+
}
|
|
15307
|
+
|
|
15250
15308
|
// node_modules/axios/lib/adapters/http.js
|
|
15251
15309
|
var zlibOptions = {
|
|
15252
15310
|
flush: import_zlib.default.constants.Z_SYNC_FLUSH,
|
|
@@ -15390,6 +15448,17 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config2) {
|
|
|
15390
15448
|
const parsed = new URL(fullPath, platform_default.hasBrowserEnv ? platform_default.origin : void 0);
|
|
15391
15449
|
const protocol = parsed.protocol || supportedProtocols[0];
|
|
15392
15450
|
if (protocol === "data:") {
|
|
15451
|
+
if (config2.maxContentLength > -1) {
|
|
15452
|
+
const dataUrl = String(config2.url || fullPath || "");
|
|
15453
|
+
const estimated = estimateDataURLDecodedBytes(dataUrl);
|
|
15454
|
+
if (estimated > config2.maxContentLength) {
|
|
15455
|
+
return reject(new AxiosError_default(
|
|
15456
|
+
"maxContentLength size of " + config2.maxContentLength + " exceeded",
|
|
15457
|
+
AxiosError_default.ERR_BAD_RESPONSE,
|
|
15458
|
+
config2
|
|
15459
|
+
));
|
|
15460
|
+
}
|
|
15461
|
+
}
|
|
15393
15462
|
let convertedData;
|
|
15394
15463
|
if (method !== "GET") {
|
|
15395
15464
|
return settle(resolve, reject, {
|
|
@@ -15885,13 +15954,17 @@ var resolveConfig_default = (config2) => {
|
|
|
15885
15954
|
"Basic " + btoa((auth.username || "") + ":" + (auth.password ? unescape(encodeURIComponent(auth.password)) : ""))
|
|
15886
15955
|
);
|
|
15887
15956
|
}
|
|
15888
|
-
let contentType;
|
|
15889
15957
|
if (utils_default.isFormData(data)) {
|
|
15890
15958
|
if (platform_default.hasStandardBrowserEnv || platform_default.hasStandardBrowserWebWorkerEnv) {
|
|
15891
15959
|
headers.setContentType(void 0);
|
|
15892
|
-
} else if ((
|
|
15893
|
-
const
|
|
15894
|
-
|
|
15960
|
+
} else if (utils_default.isFunction(data.getHeaders)) {
|
|
15961
|
+
const formHeaders = data.getHeaders();
|
|
15962
|
+
const allowedHeaders = ["content-type", "content-length"];
|
|
15963
|
+
Object.entries(formHeaders).forEach(([key, val]) => {
|
|
15964
|
+
if (allowedHeaders.includes(key.toLowerCase())) {
|
|
15965
|
+
headers.set(key, val);
|
|
15966
|
+
}
|
|
15967
|
+
});
|
|
15895
15968
|
}
|
|
15896
15969
|
}
|
|
15897
15970
|
if (platform_default.hasStandardBrowserEnv) {
|
|
@@ -15971,8 +16044,11 @@ var xhr_default = isXHRAdapterSupported && function(config2) {
|
|
|
15971
16044
|
reject(new AxiosError_default("Request aborted", AxiosError_default.ECONNABORTED, config2, request));
|
|
15972
16045
|
request = null;
|
|
15973
16046
|
};
|
|
15974
|
-
request.onerror = function handleError() {
|
|
15975
|
-
|
|
16047
|
+
request.onerror = function handleError(event) {
|
|
16048
|
+
const msg = event && event.message ? event.message : "Network Error";
|
|
16049
|
+
const err = new AxiosError_default(msg, AxiosError_default.ERR_NETWORK, config2, request);
|
|
16050
|
+
err.event = event || null;
|
|
16051
|
+
reject(err);
|
|
15976
16052
|
request = null;
|
|
15977
16053
|
};
|
|
15978
16054
|
request.ontimeout = function handleTimeout() {
|
|
@@ -16147,9 +16223,16 @@ var trackStream = (stream4, chunkSize, onProgress, onFinish) => {
|
|
|
16147
16223
|
};
|
|
16148
16224
|
|
|
16149
16225
|
// node_modules/axios/lib/adapters/fetch.js
|
|
16150
|
-
var
|
|
16151
|
-
var
|
|
16152
|
-
var
|
|
16226
|
+
var DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
16227
|
+
var { isFunction: isFunction2 } = utils_default;
|
|
16228
|
+
var globalFetchAPI = (({ Request, Response }) => ({
|
|
16229
|
+
Request,
|
|
16230
|
+
Response
|
|
16231
|
+
}))(utils_default.global);
|
|
16232
|
+
var {
|
|
16233
|
+
ReadableStream: ReadableStream2,
|
|
16234
|
+
TextEncoder: TextEncoder2
|
|
16235
|
+
} = utils_default.global;
|
|
16153
16236
|
var test = (fn, ...args) => {
|
|
16154
16237
|
try {
|
|
16155
16238
|
return !!fn(...args);
|
|
@@ -16157,164 +16240,204 @@ var test = (fn, ...args) => {
|
|
|
16157
16240
|
return false;
|
|
16158
16241
|
}
|
|
16159
16242
|
};
|
|
16160
|
-
var
|
|
16161
|
-
|
|
16162
|
-
|
|
16163
|
-
|
|
16164
|
-
|
|
16165
|
-
|
|
16166
|
-
|
|
16167
|
-
|
|
16168
|
-
|
|
16169
|
-
|
|
16170
|
-
return duplexAccessed && !hasContentType;
|
|
16171
|
-
});
|
|
16172
|
-
var DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
16173
|
-
var supportsResponseStream = isReadableStreamSupported && test(() => utils_default.isReadableStream(new Response("").body));
|
|
16174
|
-
var resolvers = {
|
|
16175
|
-
stream: supportsResponseStream && ((res) => res.body)
|
|
16176
|
-
};
|
|
16177
|
-
isFetchSupported && ((res) => {
|
|
16178
|
-
["text", "arrayBuffer", "blob", "formData", "stream"].forEach((type) => {
|
|
16179
|
-
!resolvers[type] && (resolvers[type] = utils_default.isFunction(res[type]) ? (res2) => res2[type]() : (_, config2) => {
|
|
16180
|
-
throw new AxiosError_default(`Response type '${type}' is not supported`, AxiosError_default.ERR_NOT_SUPPORT, config2);
|
|
16181
|
-
});
|
|
16182
|
-
});
|
|
16183
|
-
})(new Response());
|
|
16184
|
-
var getBodyLength = async (body) => {
|
|
16185
|
-
if (body == null) {
|
|
16186
|
-
return 0;
|
|
16187
|
-
}
|
|
16188
|
-
if (utils_default.isBlob(body)) {
|
|
16189
|
-
return body.size;
|
|
16243
|
+
var factory = (env) => {
|
|
16244
|
+
env = utils_default.merge.call({
|
|
16245
|
+
skipUndefined: true
|
|
16246
|
+
}, globalFetchAPI, env);
|
|
16247
|
+
const { fetch: envFetch, Request, Response } = env;
|
|
16248
|
+
const isFetchSupported = envFetch ? isFunction2(envFetch) : typeof fetch === "function";
|
|
16249
|
+
const isRequestSupported = isFunction2(Request);
|
|
16250
|
+
const isResponseSupported = isFunction2(Response);
|
|
16251
|
+
if (!isFetchSupported) {
|
|
16252
|
+
return false;
|
|
16190
16253
|
}
|
|
16191
|
-
|
|
16192
|
-
|
|
16254
|
+
const isReadableStreamSupported = isFetchSupported && isFunction2(ReadableStream2);
|
|
16255
|
+
const encodeText = isFetchSupported && (typeof TextEncoder2 === "function" ? ((encoder) => (str) => encoder.encode(str))(new TextEncoder2()) : async (str) => new Uint8Array(await new Request(str).arrayBuffer()));
|
|
16256
|
+
const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
|
|
16257
|
+
let duplexAccessed = false;
|
|
16258
|
+
const hasContentType = new Request(platform_default.origin, {
|
|
16259
|
+
body: new ReadableStream2(),
|
|
16193
16260
|
method: "POST",
|
|
16194
|
-
|
|
16195
|
-
|
|
16196
|
-
|
|
16197
|
-
|
|
16198
|
-
|
|
16199
|
-
return
|
|
16200
|
-
}
|
|
16201
|
-
if (utils_default.isURLSearchParams(body)) {
|
|
16202
|
-
body = body + "";
|
|
16203
|
-
}
|
|
16204
|
-
if (utils_default.isString(body)) {
|
|
16205
|
-
return (await encodeText(body)).byteLength;
|
|
16206
|
-
}
|
|
16207
|
-
};
|
|
16208
|
-
var resolveBodyLength = async (headers, body) => {
|
|
16209
|
-
const length = utils_default.toFiniteNumber(headers.getContentLength());
|
|
16210
|
-
return length == null ? getBodyLength(body) : length;
|
|
16211
|
-
};
|
|
16212
|
-
var fetch_default = isFetchSupported && (async (config2) => {
|
|
16213
|
-
let {
|
|
16214
|
-
url: url2,
|
|
16215
|
-
method,
|
|
16216
|
-
data,
|
|
16217
|
-
signal,
|
|
16218
|
-
cancelToken,
|
|
16219
|
-
timeout,
|
|
16220
|
-
onDownloadProgress,
|
|
16221
|
-
onUploadProgress,
|
|
16222
|
-
responseType,
|
|
16223
|
-
headers,
|
|
16224
|
-
withCredentials = "same-origin",
|
|
16225
|
-
fetchOptions
|
|
16226
|
-
} = resolveConfig_default(config2);
|
|
16227
|
-
responseType = responseType ? (responseType + "").toLowerCase() : "text";
|
|
16228
|
-
let composedSignal = composeSignals_default([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
|
16229
|
-
let request;
|
|
16230
|
-
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
|
16231
|
-
composedSignal.unsubscribe();
|
|
16261
|
+
get duplex() {
|
|
16262
|
+
duplexAccessed = true;
|
|
16263
|
+
return "half";
|
|
16264
|
+
}
|
|
16265
|
+
}).headers.has("Content-Type");
|
|
16266
|
+
return duplexAccessed && !hasContentType;
|
|
16232
16267
|
});
|
|
16233
|
-
|
|
16234
|
-
|
|
16235
|
-
|
|
16236
|
-
|
|
16237
|
-
|
|
16238
|
-
|
|
16239
|
-
|
|
16268
|
+
const supportsResponseStream = isResponseSupported && isReadableStreamSupported && test(() => utils_default.isReadableStream(new Response("").body));
|
|
16269
|
+
const resolvers = {
|
|
16270
|
+
stream: supportsResponseStream && ((res) => res.body)
|
|
16271
|
+
};
|
|
16272
|
+
isFetchSupported && (() => {
|
|
16273
|
+
["text", "arrayBuffer", "blob", "formData", "stream"].forEach((type) => {
|
|
16274
|
+
!resolvers[type] && (resolvers[type] = (res, config2) => {
|
|
16275
|
+
let method = res && res[type];
|
|
16276
|
+
if (method) {
|
|
16277
|
+
return method.call(res);
|
|
16278
|
+
}
|
|
16279
|
+
throw new AxiosError_default(`Response type '${type}' is not supported`, AxiosError_default.ERR_NOT_SUPPORT, config2);
|
|
16240
16280
|
});
|
|
16241
|
-
|
|
16242
|
-
|
|
16243
|
-
|
|
16244
|
-
|
|
16245
|
-
|
|
16246
|
-
const [onProgress, flush] = progressEventDecorator(
|
|
16247
|
-
requestContentLength,
|
|
16248
|
-
progressEventReducer(asyncDecorator(onUploadProgress))
|
|
16249
|
-
);
|
|
16250
|
-
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
|
|
16251
|
-
}
|
|
16281
|
+
});
|
|
16282
|
+
})();
|
|
16283
|
+
const getBodyLength = async (body) => {
|
|
16284
|
+
if (body == null) {
|
|
16285
|
+
return 0;
|
|
16252
16286
|
}
|
|
16253
|
-
if (
|
|
16254
|
-
|
|
16287
|
+
if (utils_default.isBlob(body)) {
|
|
16288
|
+
return body.size;
|
|
16255
16289
|
}
|
|
16256
|
-
|
|
16257
|
-
|
|
16258
|
-
|
|
16259
|
-
|
|
16260
|
-
method: method.toUpperCase(),
|
|
16261
|
-
headers: headers.normalize().toJSON(),
|
|
16262
|
-
body: data,
|
|
16263
|
-
duplex: "half",
|
|
16264
|
-
credentials: isCredentialsSupported ? withCredentials : void 0
|
|
16265
|
-
});
|
|
16266
|
-
let response = await fetch(request, fetchOptions);
|
|
16267
|
-
const isStreamResponse = supportsResponseStream && (responseType === "stream" || responseType === "response");
|
|
16268
|
-
if (supportsResponseStream && (onDownloadProgress || isStreamResponse && unsubscribe)) {
|
|
16269
|
-
const options = {};
|
|
16270
|
-
["status", "statusText", "headers"].forEach((prop) => {
|
|
16271
|
-
options[prop] = response[prop];
|
|
16290
|
+
if (utils_default.isSpecCompliantForm(body)) {
|
|
16291
|
+
const _request = new Request(platform_default.origin, {
|
|
16292
|
+
method: "POST",
|
|
16293
|
+
body
|
|
16272
16294
|
});
|
|
16273
|
-
|
|
16274
|
-
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
|
16275
|
-
responseContentLength,
|
|
16276
|
-
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
|
16277
|
-
) || [];
|
|
16278
|
-
response = new Response(
|
|
16279
|
-
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
|
16280
|
-
flush && flush();
|
|
16281
|
-
unsubscribe && unsubscribe();
|
|
16282
|
-
}),
|
|
16283
|
-
options
|
|
16284
|
-
);
|
|
16295
|
+
return (await _request.arrayBuffer()).byteLength;
|
|
16285
16296
|
}
|
|
16286
|
-
|
|
16287
|
-
|
|
16288
|
-
|
|
16289
|
-
|
|
16290
|
-
|
|
16291
|
-
|
|
16292
|
-
|
|
16293
|
-
|
|
16294
|
-
|
|
16295
|
-
|
|
16296
|
-
|
|
16297
|
-
|
|
16297
|
+
if (utils_default.isArrayBufferView(body) || utils_default.isArrayBuffer(body)) {
|
|
16298
|
+
return body.byteLength;
|
|
16299
|
+
}
|
|
16300
|
+
if (utils_default.isURLSearchParams(body)) {
|
|
16301
|
+
body = body + "";
|
|
16302
|
+
}
|
|
16303
|
+
if (utils_default.isString(body)) {
|
|
16304
|
+
return (await encodeText(body)).byteLength;
|
|
16305
|
+
}
|
|
16306
|
+
};
|
|
16307
|
+
const resolveBodyLength = async (headers, body) => {
|
|
16308
|
+
const length = utils_default.toFiniteNumber(headers.getContentLength());
|
|
16309
|
+
return length == null ? getBodyLength(body) : length;
|
|
16310
|
+
};
|
|
16311
|
+
return async (config2) => {
|
|
16312
|
+
let {
|
|
16313
|
+
url: url2,
|
|
16314
|
+
method,
|
|
16315
|
+
data,
|
|
16316
|
+
signal,
|
|
16317
|
+
cancelToken,
|
|
16318
|
+
timeout,
|
|
16319
|
+
onDownloadProgress,
|
|
16320
|
+
onUploadProgress,
|
|
16321
|
+
responseType,
|
|
16322
|
+
headers,
|
|
16323
|
+
withCredentials = "same-origin",
|
|
16324
|
+
fetchOptions
|
|
16325
|
+
} = resolveConfig_default(config2);
|
|
16326
|
+
let _fetch = envFetch || fetch;
|
|
16327
|
+
responseType = responseType ? (responseType + "").toLowerCase() : "text";
|
|
16328
|
+
let composedSignal = composeSignals_default([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
|
16329
|
+
let request = null;
|
|
16330
|
+
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
|
16331
|
+
composedSignal.unsubscribe();
|
|
16298
16332
|
});
|
|
16299
|
-
|
|
16300
|
-
|
|
16301
|
-
|
|
16302
|
-
|
|
16303
|
-
|
|
16304
|
-
|
|
16305
|
-
|
|
16333
|
+
let requestContentLength;
|
|
16334
|
+
try {
|
|
16335
|
+
if (onUploadProgress && supportsRequestStream && method !== "get" && method !== "head" && (requestContentLength = await resolveBodyLength(headers, data)) !== 0) {
|
|
16336
|
+
let _request = new Request(url2, {
|
|
16337
|
+
method: "POST",
|
|
16338
|
+
body: data,
|
|
16339
|
+
duplex: "half"
|
|
16340
|
+
});
|
|
16341
|
+
let contentTypeHeader;
|
|
16342
|
+
if (utils_default.isFormData(data) && (contentTypeHeader = _request.headers.get("content-type"))) {
|
|
16343
|
+
headers.setContentType(contentTypeHeader);
|
|
16306
16344
|
}
|
|
16307
|
-
|
|
16345
|
+
if (_request.body) {
|
|
16346
|
+
const [onProgress, flush] = progressEventDecorator(
|
|
16347
|
+
requestContentLength,
|
|
16348
|
+
progressEventReducer(asyncDecorator(onUploadProgress))
|
|
16349
|
+
);
|
|
16350
|
+
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
|
|
16351
|
+
}
|
|
16352
|
+
}
|
|
16353
|
+
if (!utils_default.isString(withCredentials)) {
|
|
16354
|
+
withCredentials = withCredentials ? "include" : "omit";
|
|
16355
|
+
}
|
|
16356
|
+
const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
|
|
16357
|
+
const resolvedOptions = {
|
|
16358
|
+
...fetchOptions,
|
|
16359
|
+
signal: composedSignal,
|
|
16360
|
+
method: method.toUpperCase(),
|
|
16361
|
+
headers: headers.normalize().toJSON(),
|
|
16362
|
+
body: data,
|
|
16363
|
+
duplex: "half",
|
|
16364
|
+
credentials: isCredentialsSupported ? withCredentials : void 0
|
|
16365
|
+
};
|
|
16366
|
+
request = isRequestSupported && new Request(url2, resolvedOptions);
|
|
16367
|
+
let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url2, resolvedOptions));
|
|
16368
|
+
const isStreamResponse = supportsResponseStream && (responseType === "stream" || responseType === "response");
|
|
16369
|
+
if (supportsResponseStream && (onDownloadProgress || isStreamResponse && unsubscribe)) {
|
|
16370
|
+
const options = {};
|
|
16371
|
+
["status", "statusText", "headers"].forEach((prop) => {
|
|
16372
|
+
options[prop] = response[prop];
|
|
16373
|
+
});
|
|
16374
|
+
const responseContentLength = utils_default.toFiniteNumber(response.headers.get("content-length"));
|
|
16375
|
+
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
|
16376
|
+
responseContentLength,
|
|
16377
|
+
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
|
16378
|
+
) || [];
|
|
16379
|
+
response = new Response(
|
|
16380
|
+
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
|
16381
|
+
flush && flush();
|
|
16382
|
+
unsubscribe && unsubscribe();
|
|
16383
|
+
}),
|
|
16384
|
+
options
|
|
16385
|
+
);
|
|
16386
|
+
}
|
|
16387
|
+
responseType = responseType || "text";
|
|
16388
|
+
let responseData = await resolvers[utils_default.findKey(resolvers, responseType) || "text"](response, config2);
|
|
16389
|
+
!isStreamResponse && unsubscribe && unsubscribe();
|
|
16390
|
+
return await new Promise((resolve, reject) => {
|
|
16391
|
+
settle(resolve, reject, {
|
|
16392
|
+
data: responseData,
|
|
16393
|
+
headers: AxiosHeaders_default.from(response.headers),
|
|
16394
|
+
status: response.status,
|
|
16395
|
+
statusText: response.statusText,
|
|
16396
|
+
config: config2,
|
|
16397
|
+
request
|
|
16398
|
+
});
|
|
16399
|
+
});
|
|
16400
|
+
} catch (err) {
|
|
16401
|
+
unsubscribe && unsubscribe();
|
|
16402
|
+
if (err && err.name === "TypeError" && /Load failed|fetch/i.test(err.message)) {
|
|
16403
|
+
throw Object.assign(
|
|
16404
|
+
new AxiosError_default("Network Error", AxiosError_default.ERR_NETWORK, config2, request),
|
|
16405
|
+
{
|
|
16406
|
+
cause: err.cause || err
|
|
16407
|
+
}
|
|
16408
|
+
);
|
|
16409
|
+
}
|
|
16410
|
+
throw AxiosError_default.from(err, err && err.code, config2, request);
|
|
16308
16411
|
}
|
|
16309
|
-
|
|
16310
|
-
|
|
16311
|
-
|
|
16412
|
+
};
|
|
16413
|
+
};
|
|
16414
|
+
var seedCache = /* @__PURE__ */ new Map();
|
|
16415
|
+
var getFetch = (config2) => {
|
|
16416
|
+
let env = config2 ? config2.env : {};
|
|
16417
|
+
const { fetch: fetch2, Request, Response } = env;
|
|
16418
|
+
const seeds = [
|
|
16419
|
+
Request,
|
|
16420
|
+
Response,
|
|
16421
|
+
fetch2
|
|
16422
|
+
];
|
|
16423
|
+
let len = seeds.length, i = len, seed, target, map = seedCache;
|
|
16424
|
+
while (i--) {
|
|
16425
|
+
seed = seeds[i];
|
|
16426
|
+
target = map.get(seed);
|
|
16427
|
+
target === void 0 && map.set(seed, target = i ? /* @__PURE__ */ new Map() : factory(env));
|
|
16428
|
+
map = target;
|
|
16429
|
+
}
|
|
16430
|
+
return target;
|
|
16431
|
+
};
|
|
16432
|
+
var adapter = getFetch();
|
|
16312
16433
|
|
|
16313
16434
|
// node_modules/axios/lib/adapters/adapters.js
|
|
16314
16435
|
var knownAdapters = {
|
|
16315
16436
|
http: http_default,
|
|
16316
16437
|
xhr: xhr_default,
|
|
16317
|
-
fetch:
|
|
16438
|
+
fetch: {
|
|
16439
|
+
get: getFetch
|
|
16440
|
+
}
|
|
16318
16441
|
};
|
|
16319
16442
|
utils_default.forEach(knownAdapters, (fn, value) => {
|
|
16320
16443
|
if (fn) {
|
|
@@ -16326,30 +16449,30 @@ utils_default.forEach(knownAdapters, (fn, value) => {
|
|
|
16326
16449
|
}
|
|
16327
16450
|
});
|
|
16328
16451
|
var renderReason = (reason) => `- ${reason}`;
|
|
16329
|
-
var isResolvedHandle = (
|
|
16452
|
+
var isResolvedHandle = (adapter2) => utils_default.isFunction(adapter2) || adapter2 === null || adapter2 === false;
|
|
16330
16453
|
var adapters_default = {
|
|
16331
|
-
getAdapter: (adapters) => {
|
|
16454
|
+
getAdapter: (adapters, config2) => {
|
|
16332
16455
|
adapters = utils_default.isArray(adapters) ? adapters : [adapters];
|
|
16333
16456
|
const { length } = adapters;
|
|
16334
16457
|
let nameOrAdapter;
|
|
16335
|
-
let
|
|
16458
|
+
let adapter2;
|
|
16336
16459
|
const rejectedReasons = {};
|
|
16337
16460
|
for (let i = 0; i < length; i++) {
|
|
16338
16461
|
nameOrAdapter = adapters[i];
|
|
16339
16462
|
let id;
|
|
16340
|
-
|
|
16463
|
+
adapter2 = nameOrAdapter;
|
|
16341
16464
|
if (!isResolvedHandle(nameOrAdapter)) {
|
|
16342
|
-
|
|
16343
|
-
if (
|
|
16465
|
+
adapter2 = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
|
|
16466
|
+
if (adapter2 === void 0) {
|
|
16344
16467
|
throw new AxiosError_default(`Unknown adapter '${id}'`);
|
|
16345
16468
|
}
|
|
16346
16469
|
}
|
|
16347
|
-
if (
|
|
16470
|
+
if (adapter2 && (utils_default.isFunction(adapter2) || (adapter2 = adapter2.get(config2)))) {
|
|
16348
16471
|
break;
|
|
16349
16472
|
}
|
|
16350
|
-
rejectedReasons[id || "#" + i] =
|
|
16473
|
+
rejectedReasons[id || "#" + i] = adapter2;
|
|
16351
16474
|
}
|
|
16352
|
-
if (!
|
|
16475
|
+
if (!adapter2) {
|
|
16353
16476
|
const reasons = Object.entries(rejectedReasons).map(
|
|
16354
16477
|
([id, state]) => `adapter ${id} ` + (state === false ? "is not supported by the environment" : "is not available in the build")
|
|
16355
16478
|
);
|
|
@@ -16359,7 +16482,7 @@ var adapters_default = {
|
|
|
16359
16482
|
"ERR_NOT_SUPPORT"
|
|
16360
16483
|
);
|
|
16361
16484
|
}
|
|
16362
|
-
return
|
|
16485
|
+
return adapter2;
|
|
16363
16486
|
},
|
|
16364
16487
|
adapters: knownAdapters
|
|
16365
16488
|
};
|
|
@@ -16383,8 +16506,8 @@ function dispatchRequest(config2) {
|
|
|
16383
16506
|
if (["post", "put", "patch"].indexOf(config2.method) !== -1) {
|
|
16384
16507
|
config2.headers.setContentType("application/x-www-form-urlencoded", false);
|
|
16385
16508
|
}
|
|
16386
|
-
const
|
|
16387
|
-
return
|
|
16509
|
+
const adapter2 = adapters_default.getAdapter(config2.adapter || defaults_default.adapter, config2);
|
|
16510
|
+
return adapter2(config2).then(function onAdapterResolution(response) {
|
|
16388
16511
|
throwIfCancellationRequested(config2);
|
|
16389
16512
|
response.data = transformData.call(
|
|
16390
16513
|
config2,
|
|
@@ -16590,7 +16713,6 @@ var Axios = class {
|
|
|
16590
16713
|
}
|
|
16591
16714
|
len = requestInterceptorChain.length;
|
|
16592
16715
|
let newConfig = config2;
|
|
16593
|
-
i = 0;
|
|
16594
16716
|
while (i < len) {
|
|
16595
16717
|
const onFulfilled = requestInterceptorChain[i++];
|
|
16596
16718
|
const onRejected = requestInterceptorChain[i++];
|
|
@@ -26312,11 +26434,8 @@ function useDivisionController() {
|
|
|
26312
26434
|
return;
|
|
26313
26435
|
}
|
|
26314
26436
|
try {
|
|
26315
|
-
const
|
|
26316
|
-
res.json(
|
|
26317
|
-
message: "Successfully retrieved division.",
|
|
26318
|
-
data: { division }
|
|
26319
|
-
});
|
|
26437
|
+
const data = await _getById(id);
|
|
26438
|
+
res.json(data);
|
|
26320
26439
|
return;
|
|
26321
26440
|
} catch (error2) {
|
|
26322
26441
|
next(error2);
|
|
@@ -26403,16 +26522,17 @@ var import_joi31 = __toESM(require("joi"));
|
|
|
26403
26522
|
var import_mongodb37 = require("mongodb");
|
|
26404
26523
|
var schemaSchool = import_joi31.default.object({
|
|
26405
26524
|
_id: import_joi31.default.string().hex().optional().allow("", null),
|
|
26406
|
-
id: import_joi31.default.string().
|
|
26407
|
-
name: import_joi31.default.string().
|
|
26408
|
-
country: import_joi31.default.string().
|
|
26409
|
-
address: import_joi31.default.string().
|
|
26525
|
+
id: import_joi31.default.string().optional().allow("", null),
|
|
26526
|
+
name: import_joi31.default.string().optional().allow("", null),
|
|
26527
|
+
country: import_joi31.default.string().optional().allow("", null),
|
|
26528
|
+
address: import_joi31.default.string().optional().allow("", null),
|
|
26410
26529
|
continuedAddress: import_joi31.default.string().optional().allow("", null),
|
|
26411
|
-
city: import_joi31.default.string().required(),
|
|
26412
|
-
province: import_joi31.default.string().required(),
|
|
26413
|
-
|
|
26414
|
-
|
|
26415
|
-
|
|
26530
|
+
city: import_joi31.default.string().required().allow("", null),
|
|
26531
|
+
province: import_joi31.default.string().required().allow("", null),
|
|
26532
|
+
district: import_joi31.default.string().optional().allow("", null),
|
|
26533
|
+
postalCode: import_joi31.default.string().required().allow("", null),
|
|
26534
|
+
courses: import_joi31.default.array().items(import_joi31.default.string()).optional(),
|
|
26535
|
+
principalName: import_joi31.default.string().required().allow("", null),
|
|
26416
26536
|
principalEmail: import_joi31.default.string().email().optional().allow("", null),
|
|
26417
26537
|
principalNumber: import_joi31.default.string().optional().allow("", null),
|
|
26418
26538
|
region: import_joi31.default.string().hex().required(),
|
|
@@ -26422,7 +26542,7 @@ var schemaSchool = import_joi31.default.object({
|
|
|
26422
26542
|
status: import_joi31.default.string().optional().allow(null, ""),
|
|
26423
26543
|
createdAt: import_joi31.default.date().optional().allow("", null),
|
|
26424
26544
|
updatedAt: import_joi31.default.date().optional().allow("", null),
|
|
26425
|
-
createdBy: import_joi31.default.string().hex().
|
|
26545
|
+
createdBy: import_joi31.default.string().hex().optional().allow("", null)
|
|
26426
26546
|
});
|
|
26427
26547
|
function MSchool(value) {
|
|
26428
26548
|
const { error } = schemaSchool.validate(value);
|
|
@@ -26461,15 +26581,15 @@ function MSchool(value) {
|
|
|
26461
26581
|
_id: value._id ? value._id : new import_mongodb37.ObjectId(),
|
|
26462
26582
|
id: value.id,
|
|
26463
26583
|
name: value.name,
|
|
26464
|
-
country: value.country,
|
|
26465
|
-
address: value.address,
|
|
26584
|
+
country: value.country ?? "",
|
|
26585
|
+
address: value.address ?? "",
|
|
26466
26586
|
continuedAddress: value.continuedAddress ?? "",
|
|
26467
|
-
city: value.city,
|
|
26468
|
-
province: value.province,
|
|
26469
|
-
postalCode: value.postalCode,
|
|
26587
|
+
city: value.city ?? "",
|
|
26588
|
+
province: value.province ?? "",
|
|
26589
|
+
postalCode: value.postalCode ?? "",
|
|
26470
26590
|
courses: value.courses || [],
|
|
26471
|
-
principalName: value.principalName,
|
|
26472
|
-
principalEmail: value.principalEmail,
|
|
26591
|
+
principalName: value.principalName ?? "",
|
|
26592
|
+
principalEmail: value.principalEmail ?? "",
|
|
26473
26593
|
principalNumber: value.principalNumber ?? "",
|
|
26474
26594
|
region: value.region,
|
|
26475
26595
|
regionName: value.regionName ?? "",
|
|
@@ -26478,7 +26598,7 @@ function MSchool(value) {
|
|
|
26478
26598
|
createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
26479
26599
|
updatedAt: value.updatedAt ?? "",
|
|
26480
26600
|
status: value.status ?? "pending",
|
|
26481
|
-
createdBy: value.createdBy
|
|
26601
|
+
createdBy: value.createdBy ?? ""
|
|
26482
26602
|
};
|
|
26483
26603
|
}
|
|
26484
26604
|
|
|
@@ -26746,8 +26866,16 @@ function useSchoolRepo() {
|
|
|
26746
26866
|
|
|
26747
26867
|
// src/services/school.service.ts
|
|
26748
26868
|
var import_nodejs_utils64 = require("@eeplatform/nodejs-utils");
|
|
26869
|
+
var XLSX = __toESM(require("xlsx"));
|
|
26870
|
+
var Papa = __toESM(require("papaparse"));
|
|
26871
|
+
var BSON = __toESM(require("bson"));
|
|
26749
26872
|
function useSchoolService() {
|
|
26750
|
-
const {
|
|
26873
|
+
const {
|
|
26874
|
+
add: addSchool,
|
|
26875
|
+
getPendingByCreatedBy,
|
|
26876
|
+
updateStatusById,
|
|
26877
|
+
getPendingById
|
|
26878
|
+
} = useSchoolRepo();
|
|
26751
26879
|
const { addRole } = useRoleRepo();
|
|
26752
26880
|
const { getUserById } = useUserRepo();
|
|
26753
26881
|
const { add: addMember } = useMemberRepo();
|
|
@@ -26764,7 +26892,7 @@ function useSchoolService() {
|
|
|
26764
26892
|
}
|
|
26765
26893
|
try {
|
|
26766
26894
|
value.status = "pending";
|
|
26767
|
-
await
|
|
26895
|
+
await addSchool(value);
|
|
26768
26896
|
return "Request to register school has been sent successfully. Please wait for approval.";
|
|
26769
26897
|
} catch (error2) {
|
|
26770
26898
|
throw error2;
|
|
@@ -26783,7 +26911,7 @@ function useSchoolService() {
|
|
|
26783
26911
|
session.startTransaction();
|
|
26784
26912
|
school.status = "approved";
|
|
26785
26913
|
await updateStatusById(id, "active", session);
|
|
26786
|
-
const roleType = "school";
|
|
26914
|
+
const roleType = "basic-edu-school";
|
|
26787
26915
|
const roleName = "Admin";
|
|
26788
26916
|
const roleId = await addRole(
|
|
26789
26917
|
{
|
|
@@ -26828,9 +26956,245 @@ function useSchoolService() {
|
|
|
26828
26956
|
await session.endSession();
|
|
26829
26957
|
}
|
|
26830
26958
|
}
|
|
26959
|
+
async function add(value) {
|
|
26960
|
+
const { error } = schemaSchool.validate(value);
|
|
26961
|
+
if (error) {
|
|
26962
|
+
throw new import_nodejs_utils64.BadRequestError(error.message);
|
|
26963
|
+
}
|
|
26964
|
+
const session = import_nodejs_utils64.useAtlas.getClient()?.startSession();
|
|
26965
|
+
if (!session) {
|
|
26966
|
+
throw new Error("Unable to start session for school service.");
|
|
26967
|
+
}
|
|
26968
|
+
try {
|
|
26969
|
+
session.startTransaction();
|
|
26970
|
+
value.status = "active";
|
|
26971
|
+
const schoolId = await addSchool(value, session);
|
|
26972
|
+
const roleType = "basic-edu-school";
|
|
26973
|
+
const roleName = "Admin";
|
|
26974
|
+
const roleId = await addRole(
|
|
26975
|
+
{
|
|
26976
|
+
id: schoolId.toString(),
|
|
26977
|
+
type: roleType,
|
|
26978
|
+
name: roleName,
|
|
26979
|
+
permissions: ["*"],
|
|
26980
|
+
status: "active",
|
|
26981
|
+
default: true
|
|
26982
|
+
},
|
|
26983
|
+
session
|
|
26984
|
+
);
|
|
26985
|
+
if (!value.createdBy) {
|
|
26986
|
+
throw new import_nodejs_utils64.BadRequestError("School must have a creator.");
|
|
26987
|
+
}
|
|
26988
|
+
const user = await getUserById(value.createdBy ?? "");
|
|
26989
|
+
if (!user) {
|
|
26990
|
+
throw new import_nodejs_utils64.BadRequestError("User not found for the school creator.");
|
|
26991
|
+
}
|
|
26992
|
+
await addMember(
|
|
26993
|
+
{
|
|
26994
|
+
org: schoolId.toString(),
|
|
26995
|
+
orgName: value.name,
|
|
26996
|
+
user: value.createdBy.toString(),
|
|
26997
|
+
name: `${user.firstName} ${user.lastName}`,
|
|
26998
|
+
role: roleId.toString(),
|
|
26999
|
+
roleName,
|
|
27000
|
+
type: roleType
|
|
27001
|
+
},
|
|
27002
|
+
session
|
|
27003
|
+
);
|
|
27004
|
+
await session.commitTransaction();
|
|
27005
|
+
return "School has been added and activated successfully.";
|
|
27006
|
+
} catch (error2) {
|
|
27007
|
+
import_nodejs_utils64.logger.log({
|
|
27008
|
+
level: "error",
|
|
27009
|
+
message: `Error adding school: ${error2.message}`
|
|
27010
|
+
});
|
|
27011
|
+
await session.abortTransaction();
|
|
27012
|
+
throw error2;
|
|
27013
|
+
} finally {
|
|
27014
|
+
await session.endSession();
|
|
27015
|
+
}
|
|
27016
|
+
}
|
|
27017
|
+
async function addBulk(file, region, division) {
|
|
27018
|
+
const MAX_SIZE = 16 * 1024 * 1024;
|
|
27019
|
+
if (file.size > MAX_SIZE) {
|
|
27020
|
+
throw new import_nodejs_utils64.BadRequestError(
|
|
27021
|
+
"File size exceeds 16MB limit. Please use a smaller file to ensure transaction compatibility."
|
|
27022
|
+
);
|
|
27023
|
+
}
|
|
27024
|
+
let schools = [];
|
|
27025
|
+
const validatedSchools = [];
|
|
27026
|
+
const totalSize = validatedSchools.reduce(
|
|
27027
|
+
(sum, school) => sum + BSON.calculateObjectSize(school),
|
|
27028
|
+
0
|
|
27029
|
+
);
|
|
27030
|
+
try {
|
|
27031
|
+
if (file.mimetype.includes("sheet") || file.originalname.endsWith(".xlsx") || file.originalname.endsWith(".xls")) {
|
|
27032
|
+
const workbook = XLSX.read(file.buffer);
|
|
27033
|
+
const sheetName = workbook.SheetNames[0];
|
|
27034
|
+
const worksheet = workbook.Sheets[sheetName];
|
|
27035
|
+
schools = XLSX.utils.sheet_to_json(worksheet);
|
|
27036
|
+
} else if (file.mimetype.includes("csv") || file.originalname.endsWith(".csv")) {
|
|
27037
|
+
const csvText = file.buffer.toString("utf8");
|
|
27038
|
+
const parseResult = Papa.parse(csvText, {
|
|
27039
|
+
header: true,
|
|
27040
|
+
skipEmptyLines: true,
|
|
27041
|
+
transformHeader: (header) => header.trim()
|
|
27042
|
+
});
|
|
27043
|
+
if (parseResult.errors.length > 0) {
|
|
27044
|
+
throw new import_nodejs_utils64.BadRequestError(
|
|
27045
|
+
`CSV parsing error: ${parseResult.errors[0].message}`
|
|
27046
|
+
);
|
|
27047
|
+
}
|
|
27048
|
+
schools = parseResult.data;
|
|
27049
|
+
} else {
|
|
27050
|
+
throw new import_nodejs_utils64.BadRequestError(
|
|
27051
|
+
"Unsupported file type. Please upload an Excel (.xlsx, .xls) or CSV (.csv) file."
|
|
27052
|
+
);
|
|
27053
|
+
}
|
|
27054
|
+
if (!schools || schools.length === 0) {
|
|
27055
|
+
throw new import_nodejs_utils64.BadRequestError("No data found in the uploaded file.");
|
|
27056
|
+
}
|
|
27057
|
+
const errors = [];
|
|
27058
|
+
for (let i = 0; i < schools.length; i++) {
|
|
27059
|
+
const schoolData = schools[i];
|
|
27060
|
+
const rowNumber = i + 1;
|
|
27061
|
+
try {
|
|
27062
|
+
const schoolName = schoolData.schoolName || schoolData.name || "";
|
|
27063
|
+
const schoolId = schoolData.schoolId || schoolData.id || "";
|
|
27064
|
+
const district = schoolData.district || "";
|
|
27065
|
+
if (!schoolName.trim()) {
|
|
27066
|
+
errors.push(`Row ${rowNumber}: School name is required`);
|
|
27067
|
+
continue;
|
|
27068
|
+
}
|
|
27069
|
+
if (!schoolId.trim()) {
|
|
27070
|
+
errors.push(`Row ${rowNumber}: School ID is required`);
|
|
27071
|
+
continue;
|
|
27072
|
+
}
|
|
27073
|
+
if (!district.trim()) {
|
|
27074
|
+
errors.push(`Row ${rowNumber}: District is required`);
|
|
27075
|
+
continue;
|
|
27076
|
+
}
|
|
27077
|
+
const school = {
|
|
27078
|
+
id: schoolId.trim(),
|
|
27079
|
+
name: schoolName.trim(),
|
|
27080
|
+
country: "Philippines",
|
|
27081
|
+
// Default country
|
|
27082
|
+
address: district.trim(),
|
|
27083
|
+
// Use district as address
|
|
27084
|
+
continuedAddress: "",
|
|
27085
|
+
city: district.trim(),
|
|
27086
|
+
// Use district as city
|
|
27087
|
+
province: "",
|
|
27088
|
+
// Will need to be set based on region/division
|
|
27089
|
+
postalCode: "",
|
|
27090
|
+
courses: [],
|
|
27091
|
+
// Empty array for courses
|
|
27092
|
+
principalName: "",
|
|
27093
|
+
principalEmail: "",
|
|
27094
|
+
principalNumber: "",
|
|
27095
|
+
region,
|
|
27096
|
+
regionName: "",
|
|
27097
|
+
// Will be populated from region lookup
|
|
27098
|
+
division,
|
|
27099
|
+
divisionName: "",
|
|
27100
|
+
// Will be populated from division lookup
|
|
27101
|
+
status: "active"
|
|
27102
|
+
};
|
|
27103
|
+
const { error } = schemaSchool.validate(school);
|
|
27104
|
+
if (error) {
|
|
27105
|
+
errors.push(`Row ${rowNumber}: ${error.message}`);
|
|
27106
|
+
continue;
|
|
27107
|
+
}
|
|
27108
|
+
validatedSchools.push(school);
|
|
27109
|
+
} catch (error) {
|
|
27110
|
+
errors.push(
|
|
27111
|
+
`Row ${rowNumber}: ${error.message || "Invalid data format"}`
|
|
27112
|
+
);
|
|
27113
|
+
}
|
|
27114
|
+
}
|
|
27115
|
+
if (errors.length > 0) {
|
|
27116
|
+
throw new import_nodejs_utils64.BadRequestError(
|
|
27117
|
+
`Validation errors found:
|
|
27118
|
+
${errors.slice(0, 10).join("\n")}${errors.length > 10 ? `
|
|
27119
|
+
... and ${errors.length - 10} more errors` : ""}`
|
|
27120
|
+
);
|
|
27121
|
+
}
|
|
27122
|
+
if (validatedSchools.length === 0) {
|
|
27123
|
+
throw new import_nodejs_utils64.BadRequestError(
|
|
27124
|
+
"No valid school records found after validation."
|
|
27125
|
+
);
|
|
27126
|
+
}
|
|
27127
|
+
if (totalSize > MAX_SIZE) {
|
|
27128
|
+
throw new import_nodejs_utils64.BadRequestError(
|
|
27129
|
+
`Data payload (${Math.round(
|
|
27130
|
+
totalSize / 1024 / 1024
|
|
27131
|
+
)}MB) exceeds MongoDB transaction limit of 16MB. Please reduce the number of records or split into smaller files.`
|
|
27132
|
+
);
|
|
27133
|
+
}
|
|
27134
|
+
} catch (error) {
|
|
27135
|
+
if (error instanceof import_nodejs_utils64.BadRequestError) {
|
|
27136
|
+
throw error;
|
|
27137
|
+
}
|
|
27138
|
+
throw new import_nodejs_utils64.BadRequestError(`File processing error: ${error.message}`);
|
|
27139
|
+
}
|
|
27140
|
+
const session = import_nodejs_utils64.useAtlas.getClient()?.startSession();
|
|
27141
|
+
if (!session) {
|
|
27142
|
+
throw new Error("Unable to start session for bulk school upload.");
|
|
27143
|
+
}
|
|
27144
|
+
try {
|
|
27145
|
+
session.startTransaction();
|
|
27146
|
+
const results = {
|
|
27147
|
+
successful: 0,
|
|
27148
|
+
failed: 0,
|
|
27149
|
+
errors: []
|
|
27150
|
+
};
|
|
27151
|
+
for (const school of validatedSchools) {
|
|
27152
|
+
try {
|
|
27153
|
+
const schoolId = await addSchool(school, session);
|
|
27154
|
+
await addRole(
|
|
27155
|
+
{
|
|
27156
|
+
id: schoolId.toString(),
|
|
27157
|
+
type: "basic-edu-school",
|
|
27158
|
+
name: "Admin",
|
|
27159
|
+
permissions: ["*"],
|
|
27160
|
+
status: "active",
|
|
27161
|
+
default: true
|
|
27162
|
+
},
|
|
27163
|
+
session
|
|
27164
|
+
);
|
|
27165
|
+
results.successful++;
|
|
27166
|
+
} catch (error) {
|
|
27167
|
+
results.failed++;
|
|
27168
|
+
results.errors.push(`School "${school.name}": ${error.message}`);
|
|
27169
|
+
}
|
|
27170
|
+
}
|
|
27171
|
+
await session.commitTransaction();
|
|
27172
|
+
return {
|
|
27173
|
+
message: `Bulk upload completed. ${results.successful} schools added successfully.`,
|
|
27174
|
+
details: {
|
|
27175
|
+
successful: results.successful,
|
|
27176
|
+
failed: results.failed,
|
|
27177
|
+
total: validatedSchools.length,
|
|
27178
|
+
totalSizeMB: Math.round(totalSize / 1024 / 1024 * 100) / 100,
|
|
27179
|
+
errors: results.errors
|
|
27180
|
+
}
|
|
27181
|
+
};
|
|
27182
|
+
} catch (error) {
|
|
27183
|
+
import_nodejs_utils64.logger.log({
|
|
27184
|
+
level: "error",
|
|
27185
|
+
message: `Error in bulk school upload: ${error.message}`
|
|
27186
|
+
});
|
|
27187
|
+
await session.abortTransaction();
|
|
27188
|
+
throw error;
|
|
27189
|
+
} finally {
|
|
27190
|
+
await session.endSession();
|
|
27191
|
+
}
|
|
27192
|
+
}
|
|
26831
27193
|
return {
|
|
26832
27194
|
register,
|
|
26833
|
-
approve
|
|
27195
|
+
approve,
|
|
27196
|
+
add,
|
|
27197
|
+
addBulk
|
|
26834
27198
|
};
|
|
26835
27199
|
}
|
|
26836
27200
|
|
|
@@ -26839,11 +27203,16 @@ var import_nodejs_utils65 = require("@eeplatform/nodejs-utils");
|
|
|
26839
27203
|
var import_joi32 = __toESM(require("joi"));
|
|
26840
27204
|
function useSchoolController() {
|
|
26841
27205
|
const {
|
|
26842
|
-
add: _add,
|
|
26843
27206
|
getAll: _getAll,
|
|
26844
27207
|
getPendingByCreatedBy: _getPendingByCreatedBy,
|
|
26845
27208
|
updateStatusById: _updateStatusById
|
|
26846
27209
|
} = useSchoolRepo();
|
|
27210
|
+
const {
|
|
27211
|
+
add: _addSchool,
|
|
27212
|
+
register: _registerSchool,
|
|
27213
|
+
approve,
|
|
27214
|
+
addBulk: _addBulk
|
|
27215
|
+
} = useSchoolService();
|
|
26847
27216
|
async function add(req, res, next) {
|
|
26848
27217
|
const payload = req.body;
|
|
26849
27218
|
const { error } = schemaSchool.validate(payload);
|
|
@@ -26852,8 +27221,8 @@ function useSchoolController() {
|
|
|
26852
27221
|
return;
|
|
26853
27222
|
}
|
|
26854
27223
|
try {
|
|
26855
|
-
const
|
|
26856
|
-
res.status(201).json(
|
|
27224
|
+
const result = await _addSchool(payload);
|
|
27225
|
+
res.status(201).json({ message: result });
|
|
26857
27226
|
return;
|
|
26858
27227
|
} catch (error2) {
|
|
26859
27228
|
next(error2);
|
|
@@ -26943,7 +27312,6 @@ function useSchoolController() {
|
|
|
26943
27312
|
next(error2);
|
|
26944
27313
|
}
|
|
26945
27314
|
}
|
|
26946
|
-
const { register: _registerSchool, approve } = useSchoolService();
|
|
26947
27315
|
async function registerSchool(req, res, next) {
|
|
26948
27316
|
const payload = req.body;
|
|
26949
27317
|
const { error } = schemaSchool.validate(payload);
|
|
@@ -26978,13 +27346,38 @@ function useSchoolController() {
|
|
|
26978
27346
|
next(error2);
|
|
26979
27347
|
}
|
|
26980
27348
|
}
|
|
27349
|
+
async function addBulk(req, res, next) {
|
|
27350
|
+
if (!req.file) {
|
|
27351
|
+
res.status(400).send("File is required!");
|
|
27352
|
+
return;
|
|
27353
|
+
}
|
|
27354
|
+
const { region, division } = req.body;
|
|
27355
|
+
const validation = import_joi32.default.object({
|
|
27356
|
+
region: import_joi32.default.string().hex().required(),
|
|
27357
|
+
division: import_joi32.default.string().hex().required()
|
|
27358
|
+
});
|
|
27359
|
+
const { error } = validation.validate({ region, division });
|
|
27360
|
+
if (error) {
|
|
27361
|
+
next(new import_nodejs_utils65.BadRequestError(`Validation error: ${error.message}`));
|
|
27362
|
+
return;
|
|
27363
|
+
}
|
|
27364
|
+
try {
|
|
27365
|
+
const result = await _addBulk(req.file, region, division);
|
|
27366
|
+
res.status(201).json(result);
|
|
27367
|
+
return;
|
|
27368
|
+
} catch (error2) {
|
|
27369
|
+
next(error2);
|
|
27370
|
+
return;
|
|
27371
|
+
}
|
|
27372
|
+
}
|
|
26981
27373
|
return {
|
|
26982
27374
|
add,
|
|
26983
27375
|
getAll,
|
|
26984
27376
|
getByCreatedBy,
|
|
26985
27377
|
updateStatusById,
|
|
26986
27378
|
registerSchool,
|
|
26987
|
-
approveSchool
|
|
27379
|
+
approveSchool,
|
|
27380
|
+
addBulk
|
|
26988
27381
|
};
|
|
26989
27382
|
}
|
|
26990
27383
|
|
|
@@ -29429,10 +29822,18 @@ var schemaPlantilla = import_joi41.default.object({
|
|
|
29429
29822
|
_id: import_joi41.default.string().hex().optional().allow(null, ""),
|
|
29430
29823
|
itemNumber: import_joi41.default.string().required(),
|
|
29431
29824
|
positionTitle: import_joi41.default.string().required(),
|
|
29432
|
-
|
|
29433
|
-
|
|
29825
|
+
positionCategory: import_joi41.default.string().required(),
|
|
29826
|
+
region: import_joi41.default.string().hex().optional().allow(null, ""),
|
|
29827
|
+
regionName: import_joi41.default.string().optional().allow(null, ""),
|
|
29828
|
+
division: import_joi41.default.string().hex().optional().allow(null, ""),
|
|
29829
|
+
divisionName: import_joi41.default.string().optional().allow(null, ""),
|
|
29830
|
+
salaryGrade: import_joi41.default.number().required(),
|
|
29831
|
+
step: import_joi41.default.number().optional().allow(null, 0),
|
|
29832
|
+
incumbent: import_joi41.default.string().optional().allow(null, ""),
|
|
29833
|
+
annualSalary: import_joi41.default.number().optional().allow(null, 0),
|
|
29834
|
+
monthlySalary: import_joi41.default.number().optional().allow(null, 0),
|
|
29434
29835
|
status: import_joi41.default.string().required(),
|
|
29435
|
-
|
|
29836
|
+
employee: import_joi41.default.string().hex().optional().allow(null, ""),
|
|
29436
29837
|
createdAt: import_joi41.default.date().iso().optional().allow(null, ""),
|
|
29437
29838
|
updatedAt: import_joi41.default.date().iso().optional().allow(null, ""),
|
|
29438
29839
|
deletedAt: import_joi41.default.date().iso().optional().allow(null, "")
|
|
@@ -29449,21 +29850,21 @@ function MPlantilla(data) {
|
|
|
29449
29850
|
throw new import_nodejs_utils82.BadRequestError("Invalid _id.");
|
|
29450
29851
|
}
|
|
29451
29852
|
}
|
|
29452
|
-
if (data.employeeId && typeof data.employeeId === "string") {
|
|
29453
|
-
try {
|
|
29454
|
-
data.employeeId = new import_mongodb46.ObjectId(data.employeeId);
|
|
29455
|
-
} catch (error2) {
|
|
29456
|
-
throw new import_nodejs_utils82.BadRequestError("Invalid employeeId.");
|
|
29457
|
-
}
|
|
29458
|
-
}
|
|
29459
29853
|
return {
|
|
29460
29854
|
_id: data._id,
|
|
29461
29855
|
itemNumber: data.itemNumber ?? "",
|
|
29462
29856
|
positionTitle: data.positionTitle ?? "",
|
|
29463
|
-
|
|
29464
|
-
officeAssignment: data.officeAssignment ?? "",
|
|
29857
|
+
positionCategory: data.positionCategory ?? "",
|
|
29465
29858
|
status: data.status ?? "active",
|
|
29466
|
-
|
|
29859
|
+
salaryGrade: data.salaryGrade ?? 0,
|
|
29860
|
+
step: data.step ?? 0,
|
|
29861
|
+
monthlySalary: data.monthlySalary ?? 0,
|
|
29862
|
+
annualSalary: data.annualSalary ?? 0,
|
|
29863
|
+
region: data.region ?? "",
|
|
29864
|
+
regionName: data.regionName ?? "",
|
|
29865
|
+
division: data.division ?? "",
|
|
29866
|
+
divisionName: data.divisionName ?? "",
|
|
29867
|
+
incumbent: data.incumbent ?? "",
|
|
29467
29868
|
createdAt: data.createdAt ? new Date(data.createdAt) : /* @__PURE__ */ new Date(),
|
|
29468
29869
|
updatedAt: data.updatedAt ? new Date(data.updatedAt) : "",
|
|
29469
29870
|
deletedAt: data.deletedAt ? new Date(data.deletedAt) : ""
|
|
@@ -29492,11 +29893,14 @@ function usePlantillaRepo() {
|
|
|
29492
29893
|
throw new Error("Failed to create index on plantillas.");
|
|
29493
29894
|
}
|
|
29494
29895
|
}
|
|
29495
|
-
async function add(value, session) {
|
|
29896
|
+
async function add(value, session, clearCache = true) {
|
|
29897
|
+
console.log(value);
|
|
29496
29898
|
try {
|
|
29497
29899
|
value = MPlantilla(value);
|
|
29498
29900
|
const res = await collection.insertOne(value, { session });
|
|
29499
|
-
|
|
29901
|
+
if (clearCache) {
|
|
29902
|
+
delCachedData();
|
|
29903
|
+
}
|
|
29500
29904
|
return res.insertedId;
|
|
29501
29905
|
} catch (error) {
|
|
29502
29906
|
import_nodejs_utils83.logger.log({
|
|
@@ -29697,13 +30101,225 @@ function usePlantillaRepo() {
|
|
|
29697
30101
|
getAll,
|
|
29698
30102
|
getById,
|
|
29699
30103
|
updateById,
|
|
29700
|
-
deleteById
|
|
30104
|
+
deleteById,
|
|
30105
|
+
delCachedData
|
|
29701
30106
|
};
|
|
29702
30107
|
}
|
|
29703
30108
|
|
|
29704
30109
|
// src/controllers/plantilla.controller.ts
|
|
29705
|
-
var
|
|
30110
|
+
var import_nodejs_utils85 = require("@eeplatform/nodejs-utils");
|
|
29706
30111
|
var import_joi42 = __toESM(require("joi"));
|
|
30112
|
+
|
|
30113
|
+
// src/services/plantilla.service.ts
|
|
30114
|
+
var import_nodejs_utils84 = require("@eeplatform/nodejs-utils");
|
|
30115
|
+
var XLSX2 = __toESM(require("xlsx"));
|
|
30116
|
+
var Papa2 = __toESM(require("papaparse"));
|
|
30117
|
+
function usePlantillaService() {
|
|
30118
|
+
const { add: addPlantilla, delCachedData } = usePlantillaRepo();
|
|
30119
|
+
async function addBulk(file, region, division) {
|
|
30120
|
+
import_nodejs_utils84.logger.log({
|
|
30121
|
+
level: "info",
|
|
30122
|
+
message: `Starting plantilla bulk upload. File: ${file.originalname}, Size: ${file.size} bytes`
|
|
30123
|
+
});
|
|
30124
|
+
const MAX_SIZE = 16 * 1024 * 1024;
|
|
30125
|
+
let plantillas = [];
|
|
30126
|
+
let totalSize = 0;
|
|
30127
|
+
let validatedPlantillas = [];
|
|
30128
|
+
if (!file.buffer) {
|
|
30129
|
+
throw new import_nodejs_utils84.BadRequestError("File buffer is empty or corrupted");
|
|
30130
|
+
}
|
|
30131
|
+
try {
|
|
30132
|
+
const fileExtension = file.originalname.split(".").pop()?.toLowerCase();
|
|
30133
|
+
if (fileExtension === "csv") {
|
|
30134
|
+
const csvData = file.buffer.toString("utf-8");
|
|
30135
|
+
totalSize = Buffer.byteLength(csvData, "utf8");
|
|
30136
|
+
const parseResult = Papa2.parse(csvData, {
|
|
30137
|
+
header: true,
|
|
30138
|
+
skipEmptyLines: true,
|
|
30139
|
+
transformHeader: (header) => {
|
|
30140
|
+
return header.toLowerCase().replace(/\s+/g, "").replace(/[^\w]/g, "");
|
|
30141
|
+
}
|
|
30142
|
+
});
|
|
30143
|
+
if (parseResult.errors.length > 0) {
|
|
30144
|
+
throw new import_nodejs_utils84.BadRequestError(
|
|
30145
|
+
`CSV parsing errors: ${parseResult.errors.map((e) => e.message).join(", ")}`
|
|
30146
|
+
);
|
|
30147
|
+
}
|
|
30148
|
+
plantillas = parseResult.data;
|
|
30149
|
+
} else if (fileExtension === "xlsx" || fileExtension === "xls") {
|
|
30150
|
+
totalSize = file.buffer.length;
|
|
30151
|
+
const workbook = XLSX2.read(file.buffer, { type: "buffer" });
|
|
30152
|
+
const sheetName = workbook.SheetNames[0];
|
|
30153
|
+
const worksheet = workbook.Sheets[sheetName];
|
|
30154
|
+
plantillas = XLSX2.utils.sheet_to_json(worksheet, {
|
|
30155
|
+
header: 1,
|
|
30156
|
+
defval: ""
|
|
30157
|
+
});
|
|
30158
|
+
if (plantillas.length === 0) {
|
|
30159
|
+
throw new import_nodejs_utils84.BadRequestError("Excel file is empty.");
|
|
30160
|
+
}
|
|
30161
|
+
const headers = plantillas[0];
|
|
30162
|
+
const normalizedHeaders = headers.map(
|
|
30163
|
+
(header) => header.toLowerCase().replace(/\s+/g, "").replace(/[^\w]/g, "")
|
|
30164
|
+
);
|
|
30165
|
+
plantillas = plantillas.slice(1).map((row) => {
|
|
30166
|
+
const obj = {};
|
|
30167
|
+
normalizedHeaders.forEach((header, index) => {
|
|
30168
|
+
obj[header] = row[index] || "";
|
|
30169
|
+
});
|
|
30170
|
+
return obj;
|
|
30171
|
+
});
|
|
30172
|
+
} else {
|
|
30173
|
+
throw new import_nodejs_utils84.BadRequestError(
|
|
30174
|
+
"Unsupported file type. Please upload an Excel (.xlsx, .xls) or CSV (.csv) file."
|
|
30175
|
+
);
|
|
30176
|
+
}
|
|
30177
|
+
if (!plantillas || plantillas.length === 0) {
|
|
30178
|
+
throw new import_nodejs_utils84.BadRequestError("No data found in the uploaded file.");
|
|
30179
|
+
}
|
|
30180
|
+
const errors = [];
|
|
30181
|
+
for (let i = 0; i < plantillas.length; i++) {
|
|
30182
|
+
const plantillaData = plantillas[i];
|
|
30183
|
+
const rowNumber = i + 1;
|
|
30184
|
+
try {
|
|
30185
|
+
const itemNumber = plantillaData.itemnumber || plantillaData.item_number || "";
|
|
30186
|
+
const positionTitle = plantillaData.positiontitle || plantillaData.position_title || plantillaData.title || "";
|
|
30187
|
+
const positionCategory = plantillaData.positioncategory || plantillaData.position_category || "";
|
|
30188
|
+
const status = plantillaData.status || "active";
|
|
30189
|
+
if (!itemNumber.trim()) {
|
|
30190
|
+
errors.push(`Row ${rowNumber}: Item Number is required`);
|
|
30191
|
+
continue;
|
|
30192
|
+
}
|
|
30193
|
+
if (!positionTitle.trim()) {
|
|
30194
|
+
errors.push(`Row ${rowNumber}: Position Title is required`);
|
|
30195
|
+
continue;
|
|
30196
|
+
}
|
|
30197
|
+
if (!positionCategory.trim()) {
|
|
30198
|
+
errors.push(`Row ${rowNumber}: Position Category is required`);
|
|
30199
|
+
continue;
|
|
30200
|
+
}
|
|
30201
|
+
const plantilla = {
|
|
30202
|
+
itemNumber: itemNumber.trim(),
|
|
30203
|
+
positionTitle: positionTitle.trim(),
|
|
30204
|
+
positionCategory: positionCategory.trim(),
|
|
30205
|
+
salaryGrade: parseInt(
|
|
30206
|
+
plantillaData.salarygrade || plantillaData.salary_grade || "1"
|
|
30207
|
+
) || 1,
|
|
30208
|
+
step: parseInt(plantillaData.step || "1") || 1,
|
|
30209
|
+
status: status.trim() || "active"
|
|
30210
|
+
};
|
|
30211
|
+
if (region)
|
|
30212
|
+
plantilla.region = region;
|
|
30213
|
+
if (division)
|
|
30214
|
+
plantilla.division = division;
|
|
30215
|
+
if (plantillaData.regionname || plantillaData.region_name) {
|
|
30216
|
+
plantilla.regionName = plantillaData.regionname || plantillaData.region_name;
|
|
30217
|
+
}
|
|
30218
|
+
if (plantillaData.divisionname || plantillaData.division_name) {
|
|
30219
|
+
plantilla.divisionName = plantillaData.divisionname || plantillaData.division_name;
|
|
30220
|
+
}
|
|
30221
|
+
if (plantillaData.incumbent) {
|
|
30222
|
+
plantilla.incumbent = plantillaData.incumbent;
|
|
30223
|
+
}
|
|
30224
|
+
if (plantillaData.employee) {
|
|
30225
|
+
plantilla.employee = plantillaData.employee;
|
|
30226
|
+
}
|
|
30227
|
+
if (plantillaData.annualsalary || plantillaData.annual_salary) {
|
|
30228
|
+
plantilla.annualSalary = parseFloat(
|
|
30229
|
+
plantillaData.annualsalary || plantillaData.annual_salary
|
|
30230
|
+
) || void 0;
|
|
30231
|
+
}
|
|
30232
|
+
if (plantillaData.monthlysalary || plantillaData.monthly_salary) {
|
|
30233
|
+
plantilla.monthlySalary = parseFloat(
|
|
30234
|
+
plantillaData.monthlysalary || plantillaData.monthly_salary
|
|
30235
|
+
) || void 0;
|
|
30236
|
+
}
|
|
30237
|
+
if (!plantilla.itemNumber || !plantilla.positionTitle || !plantilla.positionCategory) {
|
|
30238
|
+
errors.push(`Row ${rowNumber}: Missing required fields`);
|
|
30239
|
+
continue;
|
|
30240
|
+
}
|
|
30241
|
+
validatedPlantillas.push(plantilla);
|
|
30242
|
+
} catch (error) {
|
|
30243
|
+
errors.push(
|
|
30244
|
+
`Row ${rowNumber}: ${error.message || "Invalid data format"}`
|
|
30245
|
+
);
|
|
30246
|
+
}
|
|
30247
|
+
}
|
|
30248
|
+
if (errors.length > 0) {
|
|
30249
|
+
throw new import_nodejs_utils84.BadRequestError(
|
|
30250
|
+
`Validation errors found:
|
|
30251
|
+
${errors.slice(0, 10).join("\n")}${errors.length > 10 ? `
|
|
30252
|
+
... and ${errors.length - 10} more errors` : ""}`
|
|
30253
|
+
);
|
|
30254
|
+
}
|
|
30255
|
+
if (validatedPlantillas.length === 0) {
|
|
30256
|
+
throw new import_nodejs_utils84.BadRequestError(
|
|
30257
|
+
"No valid plantilla records found after validation."
|
|
30258
|
+
);
|
|
30259
|
+
}
|
|
30260
|
+
if (totalSize > MAX_SIZE) {
|
|
30261
|
+
throw new import_nodejs_utils84.BadRequestError(
|
|
30262
|
+
`Data payload (${Math.round(
|
|
30263
|
+
totalSize / 1024 / 1024
|
|
30264
|
+
)}MB) exceeds MongoDB transaction limit of 16MB. Please reduce the number of records or split into smaller files.`
|
|
30265
|
+
);
|
|
30266
|
+
}
|
|
30267
|
+
} catch (error) {
|
|
30268
|
+
if (error instanceof import_nodejs_utils84.BadRequestError) {
|
|
30269
|
+
throw error;
|
|
30270
|
+
}
|
|
30271
|
+
throw new import_nodejs_utils84.BadRequestError(`File processing error: ${error.message}`);
|
|
30272
|
+
}
|
|
30273
|
+
const session = import_nodejs_utils84.useAtlas.getClient()?.startSession();
|
|
30274
|
+
if (!session) {
|
|
30275
|
+
throw new Error("Unable to start session for bulk plantilla upload.");
|
|
30276
|
+
}
|
|
30277
|
+
import_nodejs_utils84.logger.log({
|
|
30278
|
+
level: "info",
|
|
30279
|
+
message: `Starting bulk plantilla upload with ${validatedPlantillas.length} records`
|
|
30280
|
+
});
|
|
30281
|
+
try {
|
|
30282
|
+
session.startTransaction();
|
|
30283
|
+
const results = {
|
|
30284
|
+
successful: 0,
|
|
30285
|
+
failed: 0,
|
|
30286
|
+
errors: []
|
|
30287
|
+
};
|
|
30288
|
+
const promises = [];
|
|
30289
|
+
for (let i = 0; i < validatedPlantillas.length; i++) {
|
|
30290
|
+
const plantilla = validatedPlantillas[i];
|
|
30291
|
+
promises.push(addPlantilla(plantilla, session, false));
|
|
30292
|
+
}
|
|
30293
|
+
await Promise.all(promises);
|
|
30294
|
+
await delCachedData();
|
|
30295
|
+
await session.commitTransaction();
|
|
30296
|
+
return {
|
|
30297
|
+
message: `Bulk upload completed. ${results.successful} plantillas added successfully.`,
|
|
30298
|
+
details: {
|
|
30299
|
+
successful: results.successful,
|
|
30300
|
+
failed: results.failed,
|
|
30301
|
+
total: validatedPlantillas.length,
|
|
30302
|
+
totalSizeMB: Math.round(totalSize / 1024 / 1024 * 100) / 100,
|
|
30303
|
+
errors: results.errors
|
|
30304
|
+
}
|
|
30305
|
+
};
|
|
30306
|
+
} catch (error) {
|
|
30307
|
+
import_nodejs_utils84.logger.log({
|
|
30308
|
+
level: "error",
|
|
30309
|
+
message: `Error in bulk plantilla upload: ${error.message}`
|
|
30310
|
+
});
|
|
30311
|
+
await session.abortTransaction();
|
|
30312
|
+
throw error;
|
|
30313
|
+
} finally {
|
|
30314
|
+
await session.endSession();
|
|
30315
|
+
}
|
|
30316
|
+
}
|
|
30317
|
+
return {
|
|
30318
|
+
addBulk
|
|
30319
|
+
};
|
|
30320
|
+
}
|
|
30321
|
+
|
|
30322
|
+
// src/controllers/plantilla.controller.ts
|
|
29707
30323
|
function usePlantillaController() {
|
|
29708
30324
|
const {
|
|
29709
30325
|
add: _addPlantilla,
|
|
@@ -29712,19 +30328,18 @@ function usePlantillaController() {
|
|
|
29712
30328
|
updateById: _updatePlantillaById,
|
|
29713
30329
|
deleteById: _deletePlantillaById
|
|
29714
30330
|
} = usePlantillaRepo();
|
|
30331
|
+
const { addBulk: _addBulk } = usePlantillaService();
|
|
29715
30332
|
async function createPlantilla(req, res, next) {
|
|
29716
30333
|
const value = req.body;
|
|
29717
30334
|
const validation = import_joi42.default.object({
|
|
29718
30335
|
itemNumber: import_joi42.default.string().required(),
|
|
29719
30336
|
positionTitle: import_joi42.default.string().required(),
|
|
29720
|
-
|
|
29721
|
-
|
|
29722
|
-
status: import_joi42.default.string().required(),
|
|
29723
|
-
employeeId: import_joi42.default.string().hex().optional().allow(null, "")
|
|
30337
|
+
positionCategory: import_joi42.default.string().required(),
|
|
30338
|
+
status: import_joi42.default.string().required()
|
|
29724
30339
|
});
|
|
29725
30340
|
const { error } = validation.validate(value);
|
|
29726
30341
|
if (error) {
|
|
29727
|
-
next(new
|
|
30342
|
+
next(new import_nodejs_utils85.BadRequestError(error.message));
|
|
29728
30343
|
return;
|
|
29729
30344
|
}
|
|
29730
30345
|
try {
|
|
@@ -29742,12 +30357,12 @@ function usePlantillaController() {
|
|
|
29742
30357
|
const org = req.query.org ?? "";
|
|
29743
30358
|
const isPageNumber = isFinite(page);
|
|
29744
30359
|
if (!isPageNumber) {
|
|
29745
|
-
next(new
|
|
30360
|
+
next(new import_nodejs_utils85.BadRequestError("Invalid page number."));
|
|
29746
30361
|
return;
|
|
29747
30362
|
}
|
|
29748
30363
|
const isLimitNumber = isFinite(limit);
|
|
29749
30364
|
if (!isLimitNumber) {
|
|
29750
|
-
next(new
|
|
30365
|
+
next(new import_nodejs_utils85.BadRequestError("Invalid limit number."));
|
|
29751
30366
|
return;
|
|
29752
30367
|
}
|
|
29753
30368
|
const validation = import_joi42.default.object({
|
|
@@ -29758,7 +30373,7 @@ function usePlantillaController() {
|
|
|
29758
30373
|
});
|
|
29759
30374
|
const { error } = validation.validate({ page, limit, search, org });
|
|
29760
30375
|
if (error) {
|
|
29761
|
-
next(new
|
|
30376
|
+
next(new import_nodejs_utils85.BadRequestError(error.message));
|
|
29762
30377
|
return;
|
|
29763
30378
|
}
|
|
29764
30379
|
try {
|
|
@@ -29781,13 +30396,13 @@ function usePlantillaController() {
|
|
|
29781
30396
|
});
|
|
29782
30397
|
const { error } = validation.validate({ id });
|
|
29783
30398
|
if (error) {
|
|
29784
|
-
next(new
|
|
30399
|
+
next(new import_nodejs_utils85.BadRequestError(error.message));
|
|
29785
30400
|
return;
|
|
29786
30401
|
}
|
|
29787
30402
|
try {
|
|
29788
30403
|
const plantilla = await _getPlantillaById(id);
|
|
29789
30404
|
if (!plantilla) {
|
|
29790
|
-
next(new
|
|
30405
|
+
next(new import_nodejs_utils85.BadRequestError("Plantilla not found."));
|
|
29791
30406
|
return;
|
|
29792
30407
|
}
|
|
29793
30408
|
res.json(plantilla);
|
|
@@ -29801,19 +30416,20 @@ function usePlantillaController() {
|
|
|
29801
30416
|
const value = req.body;
|
|
29802
30417
|
const validation = import_joi42.default.object({
|
|
29803
30418
|
id: import_joi42.default.string().hex().required(),
|
|
29804
|
-
|
|
30419
|
+
employee: import_joi42.default.string().hex().optional().allow(null, ""),
|
|
29805
30420
|
status: import_joi42.default.string().optional(),
|
|
29806
|
-
positionTitle: import_joi42.default.string().optional()
|
|
30421
|
+
positionTitle: import_joi42.default.string().optional(),
|
|
30422
|
+
positionCategory: import_joi42.default.string().optional()
|
|
29807
30423
|
});
|
|
29808
30424
|
const { error } = validation.validate({ id, ...value });
|
|
29809
30425
|
if (error) {
|
|
29810
|
-
next(new
|
|
30426
|
+
next(new import_nodejs_utils85.BadRequestError(error.message));
|
|
29811
30427
|
return;
|
|
29812
30428
|
}
|
|
29813
30429
|
try {
|
|
29814
30430
|
const result = await _updatePlantillaById(id, value);
|
|
29815
30431
|
if (result.matchedCount === 0) {
|
|
29816
|
-
next(new
|
|
30432
|
+
next(new import_nodejs_utils85.BadRequestError("Plantilla not found."));
|
|
29817
30433
|
return;
|
|
29818
30434
|
}
|
|
29819
30435
|
res.json({ message: "Plantilla updated successfully" });
|
|
@@ -29829,13 +30445,13 @@ function usePlantillaController() {
|
|
|
29829
30445
|
});
|
|
29830
30446
|
const { error } = validation.validate({ id });
|
|
29831
30447
|
if (error) {
|
|
29832
|
-
next(new
|
|
30448
|
+
next(new import_nodejs_utils85.BadRequestError(error.message));
|
|
29833
30449
|
return;
|
|
29834
30450
|
}
|
|
29835
30451
|
try {
|
|
29836
30452
|
const result = await _deletePlantillaById(id);
|
|
29837
30453
|
if (result.matchedCount === 0) {
|
|
29838
|
-
next(new
|
|
30454
|
+
next(new import_nodejs_utils85.BadRequestError("Plantilla not found."));
|
|
29839
30455
|
return;
|
|
29840
30456
|
}
|
|
29841
30457
|
res.json({ message: "Plantilla deleted successfully" });
|
|
@@ -29844,12 +30460,45 @@ function usePlantillaController() {
|
|
|
29844
30460
|
next(error2);
|
|
29845
30461
|
}
|
|
29846
30462
|
}
|
|
30463
|
+
async function bulkAddPlantillas(req, res, next) {
|
|
30464
|
+
if (!req.file) {
|
|
30465
|
+
res.status(400).send("File is required!");
|
|
30466
|
+
return;
|
|
30467
|
+
}
|
|
30468
|
+
const { region, division } = req.body;
|
|
30469
|
+
const validation = import_joi42.default.object({
|
|
30470
|
+
region: import_joi42.default.string().hex().optional(),
|
|
30471
|
+
division: import_joi42.default.string().hex().optional()
|
|
30472
|
+
});
|
|
30473
|
+
const { error } = validation.validate({ region, division });
|
|
30474
|
+
if (error) {
|
|
30475
|
+
next(new import_nodejs_utils85.BadRequestError(`Validation error: ${error.message}`));
|
|
30476
|
+
return;
|
|
30477
|
+
}
|
|
30478
|
+
if (!region && !division) {
|
|
30479
|
+
next(
|
|
30480
|
+
new import_nodejs_utils85.BadRequestError(
|
|
30481
|
+
"At least one of region or division must be provided"
|
|
30482
|
+
)
|
|
30483
|
+
);
|
|
30484
|
+
return;
|
|
30485
|
+
}
|
|
30486
|
+
try {
|
|
30487
|
+
const result = await _addBulk(req.file, region, division);
|
|
30488
|
+
res.status(201).json(result);
|
|
30489
|
+
return;
|
|
30490
|
+
} catch (error2) {
|
|
30491
|
+
next(error2);
|
|
30492
|
+
return;
|
|
30493
|
+
}
|
|
30494
|
+
}
|
|
29847
30495
|
return {
|
|
29848
30496
|
createPlantilla,
|
|
29849
30497
|
getAllPlantillas,
|
|
29850
30498
|
getPlantillaById,
|
|
29851
30499
|
updatePlantilla,
|
|
29852
|
-
deletePlantilla
|
|
30500
|
+
deletePlantilla,
|
|
30501
|
+
bulkAddPlantillas
|
|
29853
30502
|
};
|
|
29854
30503
|
}
|
|
29855
30504
|
// Annotate the CommonJS export names for ESM import in node:
|