feat: Manage Images using Minio Service
This commit is contained in:
parent
4ceba378f0
commit
33a9dbde36
@ -194,31 +194,27 @@ export class ImageController {
|
|||||||
* DELETE /merchants/:merchantId/logos/:fileName
|
* DELETE /merchants/:merchantId/logos/:fileName
|
||||||
* Supprime un logo
|
* Supprime un logo
|
||||||
*/
|
*/
|
||||||
@Delete(':fileName')
|
@Delete('merchants/:merchantId/logos/url')
|
||||||
async deleteLogo(
|
async deleteLogo(
|
||||||
@Param('merchantId') merchantId: string,
|
@Param('merchantId') merchantId: string,
|
||||||
@Param('fileName') fileName: string,
|
@Query('fileName') fileName: string
|
||||||
@Body() body: { merchantName?: string },
|
|
||||||
@Request() req
|
|
||||||
) {
|
) {
|
||||||
const userId = req.user?.sub || req.user?.userId;
|
if (!fileName) {
|
||||||
|
throw new BadRequestException('fileName requis');
|
||||||
if (!userId) {
|
|
||||||
throw new BadRequestException('Utilisateur non identifié');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const merchantName = body.merchantName;
|
// Sécurité minimale : vérifier que le fichier appartient bien au merchant
|
||||||
|
if (!fileName.startsWith(`merchants/${merchantId}_`)) {
|
||||||
|
throw new BadRequestException('Accès non autorisé à ce fichier');
|
||||||
|
}
|
||||||
|
|
||||||
await this.imageService.deleteMerchantLogo(fileName);
|
await this.imageService.deleteMerchantLogo(fileName);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: 'Logo supprimé avec succès',
|
message: 'Logo supprimé avec succès',
|
||||||
merchant: {
|
merchantId: merchantId,
|
||||||
id: merchantId,
|
|
||||||
name: merchantName
|
|
||||||
},
|
|
||||||
deletedFile: fileName
|
deletedFile: fileName
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -81,22 +81,64 @@ export class HttpUserServiceClient implements UserServiceClient {
|
|||||||
|
|
||||||
async verifyUserExists(userId: string): Promise<boolean> {
|
async verifyUserExists(userId: string): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
|
console.log(`🔍 [verifyUserExists] Vérification de l'utilisateur: ${userId}`);
|
||||||
|
console.log(` Type de userId: ${typeof userId}`);
|
||||||
|
console.log(` Valeur de userId: "${userId}"`);
|
||||||
|
|
||||||
const headers = await this.getAuthHeaders();
|
const headers = await this.getAuthHeaders();
|
||||||
|
|
||||||
|
const url = `${this.baseUrl}/merchant-users/${userId}`;
|
||||||
|
|
||||||
const response = await firstValueFrom(
|
const response = await firstValueFrom(
|
||||||
this.httpService.get(`${this.baseUrl}/users/${userId}/exists`, { headers }),
|
this.httpService.get(url, { headers }),
|
||||||
);
|
);
|
||||||
return response.data.exists === true;
|
|
||||||
} catch (error) {
|
console.log(`✅ [verifyUserExists] Réponse complète:`, JSON.stringify(response.data, null, 2));
|
||||||
if (error.response?.status === 404) {
|
|
||||||
|
// Vérifier si on a reçu une réponse valide
|
||||||
|
if (!response.data) {
|
||||||
|
console.log(` ❌ Aucune donnée dans la réponse`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// L'utilisateur existe si on a reçu une réponse 200 avec des données
|
||||||
|
const exists = response.data && response.data.id === userId;
|
||||||
|
console.log(` Résultat: ${exists ? '✅ Utilisateur existe' : '❌ Utilisateur non trouvé'}`);
|
||||||
|
|
||||||
|
return exists;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`❌ [verifyUserExists] Erreur détaillée:`, {
|
||||||
|
name: error.name,
|
||||||
|
message: error.message,
|
||||||
|
status: error.response?.status,
|
||||||
|
statusText: error.response?.statusText,
|
||||||
|
data: error.response?.data,
|
||||||
|
code: error.code
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error.response?.status === 404) {
|
||||||
|
console.log(` 📭 Utilisateur ${userId} non trouvé (404)`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 401) {
|
||||||
// Token invalide, réessayer une fois après rafraîchissement
|
console.log(` 🔄 Token invalide (401), rafraîchissement...`);
|
||||||
this.accessToken = null;
|
this.accessToken = null;
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
return this.verifyUserExists(userId);
|
return this.verifyUserExists(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Autres erreurs HTTP
|
||||||
|
if (error.response?.status) {
|
||||||
|
console.log(` ⚠️ Erreur HTTP ${error.response.status}: ${error.response.statusText}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erreur réseau ou autre
|
||||||
|
console.log(` 🚨 Erreur non-HTTP: ${error.message}`);
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
'Failed to verify user existence',
|
`Failed to verify user existence: ${error.message}`,
|
||||||
HttpStatus.SERVICE_UNAVAILABLE,
|
HttpStatus.SERVICE_UNAVAILABLE,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user