Erster Aufbau Forum
This commit is contained in:
@@ -4,6 +4,8 @@ import UserParamType from '../models/type/user_param.js';
|
||||
import UserParamVisibility from '../models/community/user_param_visibility.js';
|
||||
import UserParamVisibilityType from '../models/type/user_param_visibility.js';
|
||||
import { Op } from 'sequelize';
|
||||
import UserRight from '../models/community/user_right.js';
|
||||
import UserRightType from '../models/type/user_right.js';
|
||||
|
||||
class BaseService {
|
||||
async getUserByHashedId(hashedId) {
|
||||
@@ -63,6 +65,33 @@ class BaseService {
|
||||
return age >= 18;
|
||||
}
|
||||
|
||||
async checkUserAccess(hashedId) {
|
||||
const user = await this.getUserByHashedId(hashedId);
|
||||
if (!user || !user.active) throw new Error('Access denied: User not found or inactive');
|
||||
return user.id;
|
||||
}
|
||||
|
||||
async getUserRights(userId) {
|
||||
const userRights = await UserRight.findAll({
|
||||
where: { userId },
|
||||
include: [
|
||||
{
|
||||
model: UserRightType,
|
||||
as: 'rightType',
|
||||
attributes: ['title']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
return userRights.map((right) => right.rightType.title);
|
||||
}
|
||||
|
||||
async hasUserRight(userId, requiredRights) {
|
||||
console.log(requiredRights);
|
||||
const userRights = await this.getUserRights(userId);
|
||||
return userRights.some((right) => requiredRights.includes(right));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default BaseService;
|
||||
|
||||
Reference in New Issue
Block a user