User search and creation

This commit is contained in:
buzz-lightsnack-2007 2025-04-07 22:24:00 +08:00
parent 5fa9e6efd6
commit 0458e11267
7 changed files with 109 additions and 42 deletions

View file

@ -2,9 +2,6 @@
Modify data returned by the database connector scripts. s
*/
class DBParser {
mappings;
data;
constructor(DATA = {}, MAPPINGS = {}) {
this.data = DATA;
this.mappings = MAPPINGS;
@ -20,28 +17,27 @@ class DBParser {
/*
Map certain new keys to their orignal counterparts.
*/
const map = (ROW) => {
function mapKeys (ORIGINAL = {}, MAPPINGS) {
let RESULT = {};
Object.entries(this.mappings).forEach(([NEW, OLD]) => {
if (Object.keys(ROW).includes(OLD)) {
RESULT[NEW] = (typeof ROW[OLD]).includes(`str`) ? ROW[OLD].trim() : ROW[OLD];
}
Object.entries(MAPPINGS).forEach(([NEW, OLD]) => {
RESULT[NEW] = (ORIGINAL[OLD] != null ? (typeof ORIGINAL[OLD]).includes(`str`) : false) ? ORIGINAL[OLD].trim() : ORIGINAL[OLD];
});
return RESULT;
};
}
if (this.data instanceof Array) {
ENTRIES = [];
(this.data.length) ? this.data.forEach((SELECTED) => {
if (SELECTED) {
let CLEANED = map(SELECTED);
let CLEANED = mapKeys(SELECTED, this.mappings);
(Object.keys(CLEANED).length) ? ENTRIES.push(CLEANED) : false;
};
}) : false;
} else if (this.data && this.data instanceof Object) {
ENTRIES = map(this.data);
ENTRIES = mapKeys(this.data, this.mappings);
};
this.cleaned = ENTRIES;