Skip to content

Commit acfc6c8

Browse files
committed
Add batch edit helpers
1 parent 826e21d commit acfc6c8

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

src/helpers/resources/ResourcesHelper.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ const { SortOptions } = require("../../SortOptions");
3939
* @property {number} review_average
4040
*/
4141

42+
/**
43+
* @typedef {object} BatchChange
44+
* @property {string} field
45+
* @property {string} type
46+
* @property {string} value
47+
* @property {string|undefined} search
48+
*/
49+
50+
/**
51+
* @typedef {object} BatchEdit
52+
* @property {number} batch_id
53+
* @property {number} created_at
54+
* @property {number} completed_at
55+
* @property {Map<string, Array<string>>} errors
56+
*/
57+
4258
/** A helper type for resource-related API endpoints. */
4359
class ResourcesHelper {
4460
#wrapper;
@@ -176,6 +192,27 @@ class ResourcesHelper {
176192
return await this.#wrapper.http().patch(`/resources/${resourceId}`, body);
177193
}
178194

195+
/** Batch edit resource fields for resources you own.
196+
*
197+
* @param {Array<number>} resourceIds The identifiers of the resources.
198+
* @param {Array<BatchChange>} changes A list of changes to make.
199+
*
200+
* @return {number} A batch edit identifier.
201+
*/
202+
async batchModify(resourceIds, changes) {
203+
let body = {"resources": resourceIds, changes};
204+
return await this.#wrapper.http().post("/resources/batch/", body);
205+
}
206+
207+
/** Fetch the status of a batch edit.
208+
*
209+
* @param {number} batchId The identifier of the batch edit.
210+
* @return {BatchEdit} A raw data object.
211+
*/
212+
async batchStatus(batchId) {
213+
return await this.#wrapper.http().get(`/resources/batch/${batchId}`);
214+
}
215+
179216
/** Access download-related helper functions.
180217
*
181218
* @return {DownloadsHelper} A newly-constructed download helper instance.

types/helpers/resources/ResourcesHelper.d.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ export type Resource = {
2323
review_count: number;
2424
review_average: number;
2525
};
26+
export type BatchChange = {
27+
field: string;
28+
type: string;
29+
value: string;
30+
search: string | undefined;
31+
};
32+
export type BatchEdit = {
33+
batch_id: number;
34+
created_at: number;
35+
completed_at: number;
36+
errors: Map<string, string[]>;
37+
};
2638
/**
2739
* @typedef {object} BasicResource
2840
* @property {number} resource_id
@@ -50,6 +62,20 @@ export type Resource = {
5062
* @property {number} review_count
5163
* @property {number} review_average
5264
*/
65+
/**
66+
* @typedef {object} BatchChange
67+
* @property {string} field
68+
* @property {string} type
69+
* @property {string} value
70+
* @property {string|undefined} search
71+
*/
72+
/**
73+
* @typedef {object} BatchEdit
74+
* @property {number} batch_id
75+
* @property {number} created_at
76+
* @property {number} completed_at
77+
* @property {Map<string, Array<string>>} errors
78+
*/
5379
/** A helper type for resource-related API endpoints. */
5480
export class ResourcesHelper {
5581
constructor(wrapper: any);
@@ -141,6 +167,20 @@ export class ResourcesHelper {
141167
* @param {string} tagLine The updated content of the tag line, or undefined.
142168
*/
143169
modify(resourceId: number, title: string, description: string, tagLine: string): Promise<any>;
170+
/** Batch edit resource fields for resources you own.
171+
*
172+
* @param {Array<number>} resourceIds The identifiers of the resources.
173+
* @param {Array<BatchChange>} changes A list of changes to make.
174+
*
175+
* @return {number} A batch edit identifier.
176+
*/
177+
batchModify(resourceIds: Array<number>, changes: Array<BatchChange>): number;
178+
/** Fetch the status of a batch edit.
179+
*
180+
* @param {number} batchId The identifier of the batch edit.
181+
* @return {BatchEdit} A raw data object.
182+
*/
183+
batchStatus(batchId: number): BatchEdit;
144184
/** Access download-related helper functions.
145185
*
146186
* @return {DownloadsHelper} A newly-constructed download helper instance.

types/helpers/resources/ResourcesHelper.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)