File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { Result } from "@/patterns/result" ;
2+ import { AxiosInstance } from "axios" ;
3+ import { AuthenticationCredentials , AuthenticationResult , UserScheme } from "../contracts/identity-schemes" ;
4+
5+ export class IdentityClient {
6+ private readonly httpClient : AxiosInstance ;
7+
8+ public constructor ( httpClient : AxiosInstance ) {
9+ this . httpClient = httpClient ;
10+ }
11+
12+ public async register ( parameters : AuthenticationCredentials ) : Promise < Result < UserScheme > > {
13+ var response = await this . httpClient . post ( "/api/v1/identity" , parameters ) ;
14+ if ( response . status < 200 || response . status >= 300 ) {
15+ return Result . failure < UserScheme > ( response . data ) ;
16+ }
17+
18+ return Result . success < UserScheme > ( response . data ) ;
19+ }
20+
21+ public async authenticate ( parameters : AuthenticationCredentials ) : Promise < Result < AuthenticationResult > > {
22+ var response = await this . httpClient . post ( "/api/v1/identity/authenticate" , parameters ) ;
23+ if ( response . status < 200 || response . status >= 300 ) {
24+ return Result . failure < AuthenticationResult > ( response . data ) ;
25+ }
26+
27+ return Result . success < AuthenticationResult > ( response . data ) ;
28+ }
29+ }
Original file line number Diff line number Diff line change 1+ import { AxiosInstance } from "axios" ;
2+ import { OwnerScheme , ProfileCreationScheme } from "../contracts/profiles-schemes" ;
3+ import { Result } from "@/patterns/result" ;
4+
5+ export class ProfilesClient {
6+ private readonly httpClient : AxiosInstance ;
7+
8+ public constructor ( httpClient : AxiosInstance ) {
9+ this . httpClient = httpClient ;
10+ }
11+
12+ public async createOwner ( parameters : ProfileCreationScheme ) : Promise < Result < OwnerScheme > > {
13+ var response = await this . httpClient . post ( "/api/v1/profiles/owner" , parameters ) ;
14+ if ( response . status < 200 || response . status >= 300 ) {
15+ return Result . failure < OwnerScheme > ( response . data ) ;
16+ }
17+
18+ return Result . success < OwnerScheme > ( response . data ) ;
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments