| 72 | } |
| 73 | |
| 74 | export class APIExampleRepository implements ExampleRepository { |
| 75 | constructor(private readonly request = ApiService) {} |
| 76 | |
| 77 | async list( |
| 78 | projectId: string, |
| 79 | { limit = '10', offset = '0', q = '', isChecked = '', ordering = '' }: SearchOption |
| 80 | ): Promise<ExampleItemList> { |
| 81 | // @ts-ignore |
| 82 | const params = buildQueryParams(limit, offset, q, isChecked, ordering) |
| 83 | const url = `/projects/${projectId}/examples?${params}` |
| 84 | const response = await this.request.get(url) |
| 85 | return new ExampleItemList( |
| 86 | response.data.count, |
| 87 | response.data.next, |
| 88 | response.data.previous, |
| 89 | response.data.results.map((item: { [key: string]: any }) => toModel(item)) |
| 90 | ) |
| 91 | } |
| 92 | |
| 93 | async create(projectId: string, item: ExampleItem): Promise<ExampleItem> { |
| 94 | const url = `/projects/${projectId}/examples` |
| 95 | const payload = toPayload(item) |
| 96 | const response = await this.request.post(url, payload) |
| 97 | return toModel(response.data) |
| 98 | } |
| 99 | |
| 100 | async update(projectId: string, item: ExampleItem): Promise<ExampleItem> { |
| 101 | const url = `/projects/${projectId}/examples/${item.id}` |
| 102 | const payload = toPayload(item) |
| 103 | const response = await this.request.patch(url, payload) |
| 104 | return toModel(response.data) |
| 105 | } |
| 106 | |
| 107 | async bulkDelete(projectId: string, ids: number[]): Promise<void> { |
| 108 | const url = `/projects/${projectId}/examples` |
| 109 | await this.request.delete(url, { ids }) |
| 110 | } |
| 111 | |
| 112 | async deleteAll(projectId: string): Promise<void> { |
| 113 | const url = `/projects/${projectId}/examples` |
| 114 | await this.request.delete(url) |
| 115 | } |
| 116 | |
| 117 | async findById(projectId: string, exampleId: number): Promise<ExampleItem> { |
| 118 | const url = `/projects/${projectId}/examples/${exampleId}` |
| 119 | const response = await this.request.get(url) |
| 120 | return toModel(response.data) |
| 121 | } |
| 122 | |
| 123 | async confirm(projectId: string, exampleId: number): Promise<void> { |
| 124 | const url = `/projects/${projectId}/examples/${exampleId}/states` |
| 125 | await this.request.post(url, {}) |
| 126 | } |
| 127 | } |
nothing calls this directly
no outgoing calls
no test coverage detected