fix(settings): enhance user parameter handling and add special user parameter types

- Introduced a new method to ensure special user parameter types for adult verification settings, improving data integrity and handling.
- Updated the upsertUserParam method to utilize the new special parameter type handling, ensuring robust user parameter management.
- Updated package dependencies in package.json and package-lock.json for consistency and to address potential vulnerabilities.
This commit is contained in:
Torsten Schulz (local)
2026-03-27 10:38:42 +01:00
parent 1a86061680
commit cf6d72385e
4 changed files with 263 additions and 194 deletions

View File

@@ -31,6 +31,38 @@ function encryptUserParamValue(plain) {
}
class SettingsService extends BaseService{
async ensureSpecialUserParamType(description) {
const specialTypes = {
adult_verification_status: { datatype: 'string', setting: 'account', orderId: 910, minAge: 18 },
adult_verification_request: { datatype: 'string', setting: 'account', orderId: 911, minAge: 18 },
adult_upload_blocked: { datatype: 'bool', setting: 'account', orderId: 912, minAge: 18 },
};
const definition = specialTypes[description];
if (!definition) {
return null;
}
const settingsType = await SettingsType.findOne({
where: { name: definition.setting }
});
if (!settingsType) {
throw new Error(`Missing settings type: ${definition.setting}`);
}
const [paramType] = await UserParamType.findOrCreate({
where: { description },
defaults: {
description,
datatype: definition.datatype,
settingsId: settingsType.id,
orderId: definition.orderId,
minAge: definition.minAge,
immutable: false
}
});
return paramType;
}
parseAdultVerificationRequest(value) {
if (!value) return null;
try {
@@ -97,7 +129,10 @@ class SettingsService extends BaseService{
}
async upsertUserParam(userId, description, value) {
const paramType = await UserParamType.findOne({ where: { description } });
let paramType = await UserParamType.findOne({ where: { description } });
if (!paramType) {
paramType = await this.ensureSpecialUserParamType(description);
}
if (!paramType) {
throw new Error(`Missing user param type: ${description}`);
}