profiles => format clean archi
This commit is contained in:
35
src/app/infrastructure/profiles/pb-profile.repository.ts
Normal file
35
src/app/infrastructure/profiles/pb-profile.repository.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { ProfileRepository } from '@app/domain/profiles/profile.repository';
|
||||
import { from, Observable } from 'rxjs';
|
||||
import { Profile } from '@app/domain/profiles/profile.model';
|
||||
import { Injectable } from '@angular/core';
|
||||
import PocketBase from 'pocketbase';
|
||||
import { environment } from '@env/environment';
|
||||
|
||||
interface ProfileDTO {
|
||||
profession: string;
|
||||
utilisateur: string;
|
||||
reseaux: any;
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PbProfileRepository implements ProfileRepository {
|
||||
private pb = new PocketBase(environment.baseUrl);
|
||||
|
||||
list(): Observable<Profile[]> {
|
||||
return from(this.pb.collection('profiles').getFullList<Profile>({ sort: 'profession' }));
|
||||
}
|
||||
|
||||
getByUserId(userId: string): Observable<Profile | null> {
|
||||
return from(
|
||||
this.pb.collection('profiles').getFirstListItem<Profile>(`utilisateur="${userId}"`)
|
||||
);
|
||||
}
|
||||
|
||||
create(profile: ProfileDTO): Observable<Profile> {
|
||||
return from(this.pb.collection('profiles').create<Profile>(profile));
|
||||
}
|
||||
|
||||
update(id: string, data: Partial<Profile>): Observable<Profile> {
|
||||
return from(this.pb.collection('profiles').update<Profile>(id, data));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user