Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/stringComments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ export class StringComments extends CrowdinApi {
const url = `${this.url}/projects/${projectId}/comments`;
return this.patch(url, request, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param stringCommentId string comment identifier
* @param attachmentId attachment identifier
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.comments.attachments.delete
*/
deleteStringCommentAttachment(
projectId: number,
stringCommentId: number,
attachmentId: number,
): Promise<ResponseObject<StringCommentsModel.StringComment>> {
const url = `${this.url}/projects/${projectId}/comments/${stringCommentId}/attachments/${attachmentId}`;
return this.delete(url, this.defaultConfig());
}
}

export namespace StringCommentsModel {
Expand Down Expand Up @@ -159,6 +174,18 @@ export namespace StringCommentsModel {
resolver: User;
resolvedAt: string;
createdAt: string;
attachments?: Attachment[];
}

export interface Attachment {
id: number;
name: string;
mime: string;
size: number;
category: string;
thumbnailUrl: string | null;
url: string;
downloadUrl: string;
}

export interface User {
Expand All @@ -185,6 +212,11 @@ export namespace StringCommentsModel {
type: Type;
isShared?: boolean;
issueType?: IssueType;
attachments?: AttachmentRequest[];
}

export interface AttachmentRequest {
id: number;
}

export type Type = 'comment' | 'issue';
Expand Down
18 changes: 18 additions & 0 deletions tests/stringComments/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('String Comments API', () => {
const projectId = 2;
const stringId = 3;
const stringCommentId = 4;
const attachmentId = 5;
const text = 'test';
const languageId = 'uk';
const type = 'comment';
Expand Down Expand Up @@ -131,6 +132,17 @@ describe('String Comments API', () => {
},
},
],
})
.delete(`/projects/${projectId}/comments/${stringCommentId}/attachments/${attachmentId}`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: {
id: stringCommentId,
attachments: [],
},
});
});

Expand Down Expand Up @@ -197,4 +209,10 @@ describe('String Comments API', () => {
expect(translations.data[0].data.type).toBe(type);
expect(translations.data[0].data.issueType).toBe(issueType);
});

it('Delete string comment attachment', async () => {
const comment = await api.deleteStringCommentAttachment(projectId, stringCommentId, attachmentId);
expect(comment.data.id).toBe(stringCommentId);
expect(comment.data.attachments).toEqual([]);
});
});
Loading