diff --git a/src/users/controllers/users.controller.ts b/src/users/controllers/users.controller.ts index 8b618c1..a1e82c9 100644 --- a/src/users/controllers/users.controller.ts +++ b/src/users/controllers/users.controller.ts @@ -251,148 +251,4 @@ export class UsersController { throw new HttpException(error.message || "Failed to assign roles", HttpStatus.BAD_REQUEST); } } - - // ============================================= - // === ROUTES SPECIFIQUES POUR LES MARCHANDS === - // ============================================= - - // === CREER UN UTILISATEUR DANS L'EQUIPE MARCHAND === - @Post('merchant/team') - @Scopes(SCOPES.WRITE) - async createMerchantTeamUser( - @AuthenticatedUser() user: any, - @Body() createMerchantUserDto: any - ): Promise { - this.logger.log(`Merchant ${user.sub} creating team user: ${createMerchantUserDto.username}`); - try { - const createdUser = await this.merchantTeamService.createMerchantUser( - createMerchantUserDto, - user.sub - ); - return createdUser; - } catch (error: any) { - this.logger.error(`Failed to create merchant team user: ${error.message}`); - throw new HttpException(error.message || "Failed to create merchant team user", HttpStatus.BAD_REQUEST); - } - } - - // === OBTENIR L'EQUIPE DU MARCHAND === - @Get('merchant/team') - @Scopes(SCOPES.READ) - async getMerchantTeam(@AuthenticatedUser() user: any): Promise { - this.logger.log(`Merchant ${user.sub} fetching team`); - try { - const team = await this.merchantTeamService.getMerchantTeam(user.sub); - return team; - } catch (error: any) { - this.logger.error(`Failed to fetch merchant team: ${error.message}`); - throw new HttpException(error.message || "Failed to fetch merchant team", HttpStatus.BAD_REQUEST); - } - } - - // === METTRE A JOUR UN MEMBRE DE L'EQUIPE === - @Put('merchant/team/:userId') - @Scopes(SCOPES.WRITE) - async updateMerchantTeamUser( - @AuthenticatedUser() user: any, - @Param('userId') userId: string, - @Body() updateData: any - ): Promise { - this.logger.log(`Merchant ${user.sub} updating team user: ${userId}`); - try { - const updatedUser = await this.merchantTeamService.updateMerchantUser( - userId, - updateData, - user.sub - ); - return updatedUser; - } catch (error: any) { - this.logger.error(`Failed to update merchant team user ${userId}: ${error.message}`); - throw new HttpException(error.message || "Failed to update merchant team user", HttpStatus.BAD_REQUEST); - } - } - - // === RETIRER UN MEMBRE DE L'EQUIPE === - @Delete('merchant/team/:userId') - @Scopes(SCOPES.DELETE) - async removeMerchantTeamUser( - @AuthenticatedUser() user: any, - @Param('userId') userId: string - ): Promise<{ message: string }> { - this.logger.log(`Merchant ${user.sub} removing team user: ${userId}`); - try { - await this.merchantTeamService.removeMerchantUser(userId, user.sub); - return { message: 'Team member removed successfully' }; - } catch (error: any) { - this.logger.error(`Failed to remove merchant team user ${userId}: ${error.message}`); - throw new HttpException(error.message || "Failed to remove merchant team user", HttpStatus.BAD_REQUEST); - } - } - - // === AJOUTER UN ROLE A UN MEMBRE === - @Post('merchant/team/:userId/roles/:role') - @Scopes(SCOPES.WRITE) - async addMerchantRole( - @AuthenticatedUser() user: any, - @Param('userId') userId: string, - @Param('role') role: string - ): Promise<{ message: string }> { - this.logger.log(`Merchant ${user.sub} adding role ${role} to user ${userId}`); - try { - const result = await this.merchantTeamService.addMerchantRole(userId, role, user.sub); - return result; - } catch (error: any) { - this.logger.error(`Failed to add merchant role to user ${userId}: ${error.message}`); - throw new HttpException(error.message || "Failed to add merchant role", HttpStatus.BAD_REQUEST); - } - } - - // === RETIRER UN ROLE D'UN MEMBRE === - @Delete('merchant/team/:userId/roles/:role') - @Scopes(SCOPES.WRITE) - async removeMerchantRole( - @AuthenticatedUser() user: any, - @Param('userId') userId: string, - @Param('role') role: string - ): Promise<{ message: string }> { - this.logger.log(`Merchant ${user.sub} removing role ${role} from user ${userId}`); - try { - const result = await this.merchantTeamService.removeMerchantRole(userId, role, user.sub); - return result; - } catch (error: any) { - this.logger.error(`Failed to remove merchant role from user ${userId}: ${error.message}`); - throw new HttpException(error.message || "Failed to remove merchant role", HttpStatus.BAD_REQUEST); - } - } - - // === OBTENIR LES ROLES MARCHANDS DISPONIBLES === - @Get('merchant/roles/available') - @Scopes(SCOPES.READ) - async getAvailableMerchantRoles(): Promise<{ roles: string[] }> { - this.logger.log('Fetching available merchant roles'); - try { - const roles = this.merchantTeamService.getAvailableMerchantRoles(); - return { roles }; - } catch (error: any) { - this.logger.error(`Failed to fetch available merchant roles: ${error.message}`); - throw new HttpException(error.message || "Failed to fetch available merchant roles", HttpStatus.BAD_REQUEST); - } - } - - // === VERIFIER SI UN UTILISATEUR EST DANS L'EQUIPE === - @Get('merchant/team/:userId/check') - @Scopes(SCOPES.READ) - async checkUserInTeam( - @AuthenticatedUser() user: any, - @Param('userId') userId: string - ): Promise<{ isInTeam: boolean }> { - this.logger.log(`Checking if user ${userId} is in merchant ${user.sub} team`); - try { - const isInTeam = await this.merchantTeamService.isUserInMerchantTeam(userId, user.sub); - return { isInTeam }; - } catch (error: any) { - this.logger.error(`Failed to check team membership: ${error.message}`); - throw new HttpException(error.message || "Failed to check team membership", HttpStatus.BAD_REQUEST); - } - } } \ No newline at end of file