En-/decryption fixed
This commit is contained in:
@@ -3,10 +3,40 @@ import SettingsType from '../models/type/settings.js';
|
||||
import UserParam from '../models/community/user_param.js';
|
||||
import User from '../models/community/user.js';
|
||||
import UserParamValue from '../models/type/user_param_value.js';
|
||||
import { calculateAge } from '../utils/userdata.js';
|
||||
import { DataTypes, Op } from 'sequelize';
|
||||
import { decrypt } from '../utils/encryption.js';
|
||||
|
||||
export const filterSettings = async (req, res) => {
|
||||
const { userid, type } = req.body;
|
||||
try {
|
||||
const user = await User.findOne({ where: { hashedId: userid } });
|
||||
if (!user) {
|
||||
return res.status(404).json({ error: 'User not found' });
|
||||
}
|
||||
const userParams = await UserParam.findAll({
|
||||
where: { userId: user.id },
|
||||
include: [
|
||||
{
|
||||
model: UserParamType,
|
||||
as: 'paramType'
|
||||
}
|
||||
]
|
||||
});
|
||||
let birthdate = null;
|
||||
let gender = null;
|
||||
|
||||
for (const param of userParams) {
|
||||
console.log(param.paramType.description);
|
||||
if (param.paramType.description === 'birthdate') {
|
||||
birthdate = param.value;
|
||||
}
|
||||
if (param.paramType.description === 'gender') {
|
||||
const genderResult = await UserParamValue.findOne({ where: { id: param.value } });
|
||||
gender = genderResult.dataValues.value;
|
||||
}
|
||||
}
|
||||
const age = birthdate ? calculateAge(birthdate) : null;
|
||||
const fields = await UserParamType.findAll({
|
||||
include: [
|
||||
{
|
||||
@@ -26,9 +56,14 @@ export const filterSettings = async (req, res) => {
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
where: {
|
||||
[Op.and]: [
|
||||
{ minAge: { [Op.or]: [null, { [Op.lte]: age }] } },
|
||||
{ gender: { [Op.or]: [null, gender] } }
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
const responseFields = await Promise.all(fields.map(async (field) => {
|
||||
const options = ['singleselect', 'multiselect'].includes(field.datatype) ? await UserParamValue.findAll({
|
||||
where: { userParamTypeId: field.id }
|
||||
@@ -44,11 +79,10 @@ export const filterSettings = async (req, res) => {
|
||||
options: options.map(opt => ({ id: opt.id, value: opt.value }))
|
||||
};
|
||||
}));
|
||||
|
||||
res.status(200).json(responseFields);
|
||||
} catch (error) {
|
||||
console.error('Error fetching settings:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
console.error('Error filtering settings:', error);
|
||||
res.status(500).json({ error: 'An error occurred while filtering the settings' });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -108,4 +142,33 @@ export const getTypeParamValue = async(req, res) => {
|
||||
return;
|
||||
}
|
||||
res.status(200).json({ paramValueId: userParamValueObject.value });
|
||||
};
|
||||
};
|
||||
|
||||
export const getAccountSettings = async (req, res) => {
|
||||
try {
|
||||
const user = await User.findOne({ where: { hashedId: req.body.userId } });
|
||||
if (!user) {
|
||||
return res.status(404).json({ error: 'User not found' });
|
||||
}
|
||||
const email = user.email;
|
||||
res.status(200).json({ username: user.username, email, showinsearch: user.searchable });
|
||||
} catch (error) {
|
||||
console.error('Error retrieving account settings:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
};
|
||||
|
||||
export const setAccountSettings = async(req, res) => {
|
||||
const { userid: userId, username, email, searchable, oldpassword, newpassword, newpasswordrepeat } = req.body;
|
||||
const user = await User.findOne({ where: { hashedId: userId }});
|
||||
if (!user) {
|
||||
res.status(404).json({ error: 'User not found' });
|
||||
return;
|
||||
}
|
||||
user.searchable = searchable;
|
||||
if (user.password !== oldpassword) {
|
||||
res.status(401).json({error: 'Wrong password'});
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user