Browse Source

Add member repository

pull/1224/head
Hironsan 3 years ago
parent
commit
aef3f445c5
2 changed files with 55 additions and 0 deletions
  1. 36
      frontend/repositories/member/api.ts
  2. 19
      frontend/repositories/member/interface.ts

36
frontend/repositories/member/api.ts

@ -0,0 +1,36 @@
import ApiService from '@/services/api.service'
import { MemberItem } from '@/models/member'
import { MemberItemListRepository, MemberItemResponse } from './interface'
export class FromApiMemberItemListRepository implements MemberItemListRepository {
constructor(
private readonly request = ApiService
) {}
async list(projectId: string): Promise<MemberItem[]> {
const url = `/projects/${projectId}/roles`
const response = await this.request.get(url)
const responseItems: MemberItemResponse[] = response.data
return responseItems.map(item => MemberItem.valueOf(item))
}
async create(projectId: string, item: MemberItem): Promise<MemberItem> {
const url = `/projects/${projectId}/roles`
const response = await this.request.post(url, item.toObject())
const responseItem: MemberItemResponse = response.data
return MemberItem.valueOf(responseItem)
}
async update(projectId: string, item: MemberItem): Promise<MemberItem> {
const url = `/projects/${projectId}/roles/${item.id}`
const response = await this.request.patch(url, item.toObject())
const responseItem: MemberItemResponse = response.data
return MemberItem.valueOf(responseItem)
}
async bulkDelete(projectId: string, labelIds: number[]): Promise<void> {
const url = `/projects/${projectId}/roles`
await this.request.delete(url, { ids: labelIds })
}
}

19
frontend/repositories/member/interface.ts

@ -0,0 +1,19 @@
import { MemberItem } from '@/models/member'
export interface MemberItemResponse {
id: number,
user: number,
role: number,
username: string,
rolename: string
}
export interface MemberItemListRepository {
list(projectId: string): Promise<MemberItem[]>
create(projectId: string, item: MemberItem): Promise<MemberItem>
update(projectId: string, item: MemberItem): Promise<MemberItem>
bulkDelete(projectId: string, memberIds: number[]): Promise<void>
}
Loading…
Cancel
Save