-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54b0b81
commit 8141164
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import axios from 'axios' | ||
|
||
import { Attachment, AttachmentAddData, AttachmentUpdateData, AttachmentREST } from 'productboard-common' | ||
|
||
import { auth } from '../auth' | ||
import { CacheAPI } from '../cache' | ||
|
||
class AttachmentClientImpl implements AttachmentREST<AttachmentAddData, AttachmentUpdateData, File> { | ||
async findAttachments(productId: string): Promise<Attachment[]> { | ||
return (await axios.get<Attachment[]>(`/rest/products/${productId}/attachments`, auth)).data | ||
} | ||
async addAttachment(productId: string, data: AttachmentAddData): Promise<Attachment> { | ||
const issue = (await axios.post<Attachment>(`/rest/products/${productId}/attachments`, data, auth)).data | ||
CacheAPI.putAttachment(issue) | ||
return issue | ||
} | ||
async getAttachment(productId: string, issueId: string): Promise<Attachment> { | ||
return (await axios.get<Attachment>(`/rest/products/${productId}/attachments/${issueId}`, { ...auth })).data | ||
} | ||
async updateAttachment(productId: string, issueId: string, data: AttachmentUpdateData): Promise<Attachment> { | ||
const issue = (await axios.put<Attachment>(`/rest/products/${productId}/attachments/${issueId}`, data, auth)).data | ||
CacheAPI.putAttachment(issue) | ||
return issue | ||
} | ||
async deleteAttachment(productId: string, issueId: string): Promise<Attachment> { | ||
const issue = (await axios.delete<Attachment>(`/rest/products/${productId}/attachments/${issueId}`, auth)).data | ||
CacheAPI.putAttachment(issue) | ||
return issue | ||
} | ||
} | ||
|
||
export const AttachmentClient = new AttachmentClientImpl() |