+ Catégorie : Association +
++
+ +L\'association est ....
'; + isEditMode: boolean = false; + isAuthenticated: boolean = false; + private subscriptions = new Subscription(); + + constructor( + private route: ActivatedRoute, + private appService: AppService, + private sanitizer: DomSanitizer, + private toastr: ToastrService, + public auth: AuthService, + @Inject(DOCUMENT) private doc: Document, + public userService: UserService, + ) {} + + async ngOnInit() { + this.isAuthenticated = await firstValueFrom(this.auth.isAuthenticated$); + this.getAsso(); + } + + sanitizeUrl(url: string): SafeHtml { + return this.sanitizer.bypassSecurityTrustUrl(url); + } + sanitizeHtml(html: string): SafeHtml { + return this.sanitizer.bypassSecurityTrustHtml(html); + } + + toggleEditMode() { + this.isEditMode = !this.isEditMode; + } + + getAsso() { + this.route.params.subscribe((params) => { + if (params['id']) { + this.appService.getByIdAsso(params['id']).subscribe((asso) => { + this.asso = asso; + console.log('asso:', asso); + }); + } + }); + } + + updateAsso() { + this.appService.updateAsso(this.asso!).subscribe({ + error: (error) => { + console.error('error:', error); + if (error?.error?.message) { + this.toastr.error( + error.error.message, + 'Erreur de mise à jour de l\'association' + ); + } else { + this.toastr.error('Erreur de mise à jour de l\'association'); + } + }, + complete: () => { + this.toastr.success('Association mis à jour avec succès'); + this.isEditMode = false; + }, + }); + } + + ngOnDestroy() { + this.subscriptions.unsubscribe(); + } + +} diff --git a/src/app/interfaces/interfaces.ts b/src/app/interfaces/interfaces.ts index 75ef3a2..9403e57 100644 --- a/src/app/interfaces/interfaces.ts +++ b/src/app/interfaces/interfaces.ts @@ -37,8 +37,10 @@ export interface Photo { id: number; createdAt: string; url: string; - chatId: number; - chat: Chat; + chatId?: number; + chat?: Chat; + associationId?: number; + association?: Association; } export interface Video { @@ -69,13 +71,13 @@ export interface Utilisateur { export interface Association { id: number; nom: string; - url?: string; + url: string; ville: string; - urlImage?: string; description?: string; tel?: string; chats: Chat[]; utilisateurs: Utilisateur[]; + photos: Photo[]; } export interface Favori { diff --git a/src/app/services/app.service.ts b/src/app/services/app.service.ts index 474c1c9..2028fe3 100644 --- a/src/app/services/app.service.ts +++ b/src/app/services/app.service.ts @@ -1,7 +1,7 @@ import { Inject, Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable, map, share, take } from 'rxjs'; -import { Chat, Favori } from '../interfaces/interfaces'; +import { Association, Chat, Favori } from '../interfaces/interfaces'; import { environment } from 'src/environments/environment'; import { DOCUMENT } from '@angular/common'; @@ -58,6 +58,30 @@ export class AppService { ); } + getAllAsso(): Observable