Bugs in settings fixed, profile added

This commit is contained in:
Torsten Schulz
2024-09-21 00:25:42 +02:00
parent c5a72d57d8
commit e494fe41db
65 changed files with 3121 additions and 7478 deletions

View File

@@ -1,4 +1,5 @@
import AdminService from '../services/adminService.js';
import Joi from 'joi';
export const getOpenInterests = async (req, res) => {
try {
@@ -51,4 +52,28 @@ export const getOpenContacts = async (req, res) => {
} catch (error) {
res.status(403).json({ error: error.message });
}
}
}
export const answerContact = async (req, res) => {
try {
const schema = Joi.object({
id: Joi.number().integer().required(),
answer: Joi.string().min(1).required()
});
const { error, value } = schema.validate(req.body);
if (error) {
return res.status(400).json({ error: error.details[0].message });
}
const { id, answer } = value;
await AdminService.answerContact(id, answer);
res.status(200).json({ status: 'ok' });
} catch (error) {
console.error('Error in answerContact:', error);
res.status(error.status || 500).json({ error: error.message || 'Internal Server Error' });
}
};

View File

@@ -162,6 +162,10 @@ const menuStructure = {
visible: ["all"],
path: "/settings/interests"
},
flirt: {
visible: ["over14"],
path: "/settings/flirt"
},
sexuality: {
visible: ["over14"],
path: "/settings/sexuality"

View File

@@ -133,3 +133,25 @@ export const removeInterest = async (req, res) => {
res.status(500).json({ error: 'Internal server error' });
}
}
export const getVisibilities = async (req, res) => {
try {
const visibilities = await settingsService.getVisibilities();
res.status(200).json(visibilities);
} catch (error) {
console.error('Error retrieving visibilities:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
export const updateVisibility = async (req, res) => {
const { userParamTypeId, visibilityId } = req.body;
const hashedUserId = req.headers.userid;
try {
await settingsService.updateVisibility(hashedUserId, userParamTypeId, visibilityId);
res.status(200).json({ message: 'Visibility updated successfully' });
} catch (error) {
console.error('Error updating visibility:', error);
res.status(500).json({ error: 'Internal server error' });
}
};

View File

@@ -0,0 +1,37 @@
import SocialNetworkService from '../services/socialnetworkService.js';
class SocialNetworkController {
constructor() {
this.socialNetworkService = new SocialNetworkService();
this.userSearch = this.userSearch.bind(this);
this.profile = this.profile.bind(this);
}
async userSearch(req, res) {
try {
const { username, ageFrom, ageTo, genders } = req.body;
const users = await this.socialNetworkService.searchUsers({ username, ageFrom, ageTo, genders });
res.status(200).json(users);
} catch (error) {
console.error('Error in userSearch:', error);
res.status(500).json({ error: error.message });
}
}
async profile(req, res) {
try {
const { userId } = req.params;
const requestingUserId = req.headers.userid;
if (!userId || !requestingUserId) {
return res.status(400).json({ error: 'Invalid user or requesting user ID.' });
}
const profile = await this.socialNetworkService.getProfile(userId, requestingUserId);
res.status(200).json(profile);
} catch (error) {
console.error('Error in profile:', error);
res.status(500).json({ error: error.message });
}
}
}
export default SocialNetworkController;