@bit-ui-libs/common
Version:
This library was generated with [Nx](https://nx.dev).
43 lines (34 loc) • 1.45 kB
text/typescript
import { BaseService, BaseServiceOptions } from '../../api/services/base-service';
import { ProfileTypeEnum, UserTypeEnum } from '../enums';
import { Profile } from '../interfaces';
import { AddProfileRequest, EditProfileRequest, ListProfilesRequest } from './profile.service.interfaces';
export type ProfileServiceOptions = BaseServiceOptions & { profileType: ProfileTypeEnum };
export class ProfileService<TProfile extends Profile> extends BaseService {
protected profileApiUrl: string;
constructor(opts: ProfileServiceOptions) {
super(opts);
// Examples:
// - /users/v1/end-user/buyer
// - /users/v1/end-user/seller
// - /users/v1/end-user/creator
this.profileApiUrl = `${this.apiUrl}/users/v1/${UserTypeEnum.EndUser}/${opts.profileType}`;
}
listProfiles(req: ListProfilesRequest) {
return this.get<TProfile[]>(`${this.profileApiUrl}/list`, req);
}
getDefaultProfile() {
return this.get<TProfile>(`${this.profileApiUrl}/default`);
}
getProfileById(id: string) {
return this.get<TProfile>(`${this.profileApiUrl}/${id}`);
}
editProfile(id: string, req: EditProfileRequest) {
return this.put<TProfile, EditProfileRequest>(`${this.profileApiUrl}/${id}`, req);
}
removeProfile(id: string) {
return this.delete<void>(`${this.profileApiUrl}/${id}`);
}
addProfile(req: AddProfileRequest) {
return this.post<TProfile, AddProfileRequest>(`${this.profileApiUrl}`, req);
}
}