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
731 B

  1. import { plainToInstance } from 'class-transformer'
  2. import ApiService from '@/services/api.service'
  3. import { UserRepository } from '@/domain/models/user/userRepository'
  4. import { UserItem } from '~/domain/models/user/user'
  5. export class APIUserRepository implements UserRepository {
  6. constructor(
  7. private readonly request = ApiService
  8. ) {}
  9. async getMe(): Promise<UserItem> {
  10. const url = '/me'
  11. const response = await this.request.get(url)
  12. return plainToInstance(UserItem, response.data)
  13. }
  14. async list(query: string): Promise<UserItem[]> {
  15. const url = `/users?q=${query}`
  16. const response = await this.request.get(url)
  17. return response.data.map((item: any) => plainToInstance(UserItem, item))
  18. }
  19. }