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.

17 lines
587 B

2 years ago
  1. import ApiService from '@/services/api.service'
  2. import { RoleRepository } from '@/domain/models/role/roleRepository'
  3. import { RoleItem } from '@/domain/models/role/role'
  4. function toModel(item: { [key: string]: any }): RoleItem {
  5. return new RoleItem(item.id, item.name)
  6. }
  7. export class APIRoleRepository implements RoleRepository {
  8. constructor(private readonly request = ApiService) {}
  9. async list(): Promise<RoleItem[]> {
  10. const url = `/roles`
  11. const response = await this.request.get(url)
  12. return response.data.map((item: { [key: string]: any }) => toModel(item))
  13. }
  14. }