You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
706 B

2 years ago
  1. import { UserItem } from '@/domain/models/user/user'
  2. import ApiService from '@/services/api.service'
  3. function toModel(item: { [key: string]: any }): UserItem {
  4. return new UserItem(item.id, item.username, item.is_superuser, item.is_staff)
  5. }
  6. export class APIUserRepository {
  7. constructor(private readonly request = ApiService) {}
  8. async getProfile(): Promise<UserItem> {
  9. const url = '/me'
  10. const response = await this.request.get(url)
  11. return toModel(response.data)
  12. }
  13. async list(query: string): Promise<UserItem[]> {
  14. const url = `/users?q=${query}`
  15. const response = await this.request.get(url)
  16. return response.data.map((item: { [key: string]: any }) => toModel(item))
  17. }
  18. }