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.

20 lines
723 B

2 years ago
  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(private readonly request = ApiService) {}
  7. async getMe(): Promise<UserItem> {
  8. const url = '/me'
  9. const response = await this.request.get(url)
  10. return plainToInstance(UserItem, response.data)
  11. }
  12. async list(query: string): Promise<UserItem[]> {
  13. const url = `/users?q=${query}`
  14. const response = await this.request.get(url)
  15. return response.data.map((item: any) => plainToInstance(UserItem, item))
  16. }
  17. }