Skip to content

Commit a56ff28

Browse files
authored
feat: add support for string comment attachments (#633)
1 parent 51b1c3d commit a56ff28

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

src/stringComments/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ export class StringComments extends CrowdinApi {
122122
const url = `${this.url}/projects/${projectId}/comments`;
123123
return this.patch(url, request, this.defaultConfig());
124124
}
125+
126+
/**
127+
* @param projectId project identifier
128+
* @param stringCommentId string comment identifier
129+
* @param attachmentId attachment identifier
130+
* @see https://developer.crowdin.com/api/v2/#operation/api.projects.comments.attachments.delete
131+
*/
132+
deleteStringCommentAttachment(
133+
projectId: number,
134+
stringCommentId: number,
135+
attachmentId: number,
136+
): Promise<ResponseObject<StringCommentsModel.StringComment>> {
137+
const url = `${this.url}/projects/${projectId}/comments/${stringCommentId}/attachments/${attachmentId}`;
138+
return this.delete(url, this.defaultConfig());
139+
}
125140
}
126141

127142
export namespace StringCommentsModel {
@@ -159,6 +174,18 @@ export namespace StringCommentsModel {
159174
resolver: User;
160175
resolvedAt: string;
161176
createdAt: string;
177+
attachments?: Attachment[];
178+
}
179+
180+
export interface Attachment {
181+
id: number;
182+
name: string;
183+
mime: string;
184+
size: number;
185+
category: string;
186+
thumbnailUrl: string | null;
187+
url: string;
188+
downloadUrl: string;
162189
}
163190

164191
export interface User {
@@ -185,6 +212,11 @@ export namespace StringCommentsModel {
185212
type: Type;
186213
isShared?: boolean;
187214
issueType?: IssueType;
215+
attachments?: AttachmentRequest[];
216+
}
217+
218+
export interface AttachmentRequest {
219+
id: number;
188220
}
189221

190222
export type Type = 'comment' | 'issue';

tests/stringComments/api.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe('String Comments API', () => {
1111
const projectId = 2;
1212
const stringId = 3;
1313
const stringCommentId = 4;
14+
const attachmentId = 5;
1415
const text = 'test';
1516
const languageId = 'uk';
1617
const type = 'comment';
@@ -131,6 +132,17 @@ describe('String Comments API', () => {
131132
},
132133
},
133134
],
135+
})
136+
.delete(`/projects/${projectId}/comments/${stringCommentId}/attachments/${attachmentId}`, undefined, {
137+
reqheaders: {
138+
Authorization: `Bearer ${api.token}`,
139+
},
140+
})
141+
.reply(200, {
142+
data: {
143+
id: stringCommentId,
144+
attachments: [],
145+
},
134146
});
135147
});
136148

@@ -197,4 +209,10 @@ describe('String Comments API', () => {
197209
expect(translations.data[0].data.type).toBe(type);
198210
expect(translations.data[0].data.issueType).toBe(issueType);
199211
});
212+
213+
it('Delete string comment attachment', async () => {
214+
const comment = await api.deleteStringCommentAttachment(projectId, stringCommentId, attachmentId);
215+
expect(comment.data.id).toBe(stringCommentId);
216+
expect(comment.data.attachments).toEqual([]);
217+
});
200218
});

0 commit comments

Comments
 (0)