feat: add DCB User Service API - Authentication system with KEYCLOAK - Modular architecture with services for each feature

This commit is contained in:
diallolatoile 2025-11-10 20:18:34 +00:00
parent cbdfdfa297
commit 403baaa0ef

View File

@ -154,6 +154,23 @@ export class HubUsersService {
}
}
/**
* Vérifie si un utilisateur est Hub Admin ou Support
*/
async isUserMerchantPartner(userId: string): Promise<boolean> {
try {
const userRoles = await this.keycloakApi.getUserClientRoles(userId);
const hubMerchantPartnerRoles = [UserRole.DCB_PARTNER];
return userRoles.some(role =>
hubMerchantPartnerRoles.includes(role.name as UserRole)
);
} catch (error) {
this.logger.error(`Error checking Merchant Partner status for user ${userId}:`, error);
return false;
}
}
/**
* Récupère les utilisateurs marchands selon les permissions de l'utilisateur
* - Hub Admin/Support: tous les utilisateurs marchands de tous les merchants
@ -170,7 +187,7 @@ export class HubUsersService {
}
// Pour les autres utilisateurs (DCB_PARTNER, DCB_PARTNER_ADMIN, etc.)
return await this.getMerchantUsersForRegularUser(userId);
return await this.getUsersForMerchants(userId);
} catch (error) {
this.logger.error(`Error in getMyMerchantUsers for user ${userId}:`, error);
@ -221,9 +238,16 @@ export class HubUsersService {
/**
* Récupère les utilisateurs marchands pour les utilisateurs réguliers (non Hub Admin/Support)
*/
private async getMerchantUsersForRegularUser(userId: string): Promise<User[]> {
private async getUsersForMerchants(userId: string): Promise<User[]> {
// Récupérer le merchantPartnerId de l'utilisateur
const userMerchantId = await this.getUserMerchantPartnerId(userId);
let userMerchantId = await this.getUserMerchantPartnerId(userId);
// Vérifier si l'utilisateur est un admin ou support Hub
const isUserMerchantPartner = await this.isUserMerchantPartner(userId);
if(isUserMerchantPartner){
userMerchantId = userId;
}
if (!userMerchantId) {
throw new BadRequestException('Current user is not associated with a merchant partner');
@ -236,6 +260,7 @@ export class HubUsersService {
this.logger.log(`User ${userId} retrieved ${users.length} merchant users for partner ${userMerchantId}`);
return users;
}
async getMerchantUsersByPartner(merchantPartnerId: string, requesterId: string): Promise<User[]> {