fix(api-profile-filter): Fix filtering data in profile requests

This commit is contained in:
tecc 2023-06-01 23:50:55 +02:00
parent b1f9f39ca7
commit 8bb0a7fde0
No known key found for this signature in database
GPG Key ID: 400AAD881FCC028B

View File

@ -78,20 +78,26 @@ class ProfileOptions {
};
constructor(query_obj, locales) {
if (query_obj == null) return;
const default_props = query_obj["props"];
this.default_props = ProfileOptions._parse_props(default_props)
for (const key of Object.keys(locales)) {
const lprops_obj = query_obj["lprops"];
let props;
if (typeof lprops_obj === "object") {
props = lprops_obj[key];
} else {
props = query_obj[`lprops.${key.toLowerCase()}`];
}
if (props != null) {
this.locale_specific_props[key] = ProfileOptions._parse_props(props);
if (locales != null) {
for (const key of Object.keys(locales)) {
const lprops_obj = query_obj["lprops"];
let props;
if (typeof lprops_obj === "object") {
props = lprops_obj[key];
} else {
props = query_obj[`lprops.${key.toLowerCase()}`];
}
if (props != null) {
this.locale_specific_props[key] = ProfileOptions._parse_props(props);
}
}
} else {
console.warn("ProfileOptions object was constructed without specifying locales parameter - not providing locale-specific data");
}
}
@ -698,7 +704,7 @@ router.post('/profile/save', handleErrorAsync(async (req, res) => {
await req.db.get(SQL`UPDATE users SET inactiveWarning = null WHERE id = ${req.user.id}`);
return res.json(await fetchProfiles(req.db, req.user.username, true));
return res.json(await fetchProfiles(req.db, req.user.username, true, new ProfileOptions({})));
}));
router.post('/profile/delete/:locale', handleErrorAsync(async (req, res) => {