Skip to content

Commit 31bc494

Browse files
committed
Refactor updateMany and deleteMany to use filters
The updateMany and deleteMany methods now accept a filters parameter instead of a list of IDs, allowing for more flexible batch operations. This change updates the request payloads to use filters, improving API usability.
1 parent 55f71e2 commit 31bc494

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

packages/client/src/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,11 @@ export class ObjectStackClient {
186186
return res.json();
187187
},
188188

189-
updateMany: async <T = any>(object: string, ids: string[], data: Partial<T>): Promise<number> => {
190-
// Warning: This implies updating all IDs with the SAME data
189+
updateMany: async <T = any>(object: string, data: Partial<T>, filters?: Record<string, any> | any[]): Promise<number> => {
191190
const route = this.getRoute('data');
192191
const res = await this.fetch(`${this.baseUrl}${route}/${object}/batch`, {
193192
method: 'PATCH',
194-
body: JSON.stringify({ ids, data })
193+
body: JSON.stringify({ data, filters })
195194
});
196195
return res.json(); // Returns count
197196
},
@@ -204,11 +203,11 @@ export class ObjectStackClient {
204203
return res.json();
205204
},
206205

207-
deleteMany: async(object: string, ids: string[]): Promise<{ count: number }> => {
206+
deleteMany: async(object: string, filters?: Record<string, any> | any[]): Promise<{ count: number }> => {
208207
const route = this.getRoute('data');
209208
const res = await this.fetch(`${this.baseUrl}${route}/${object}/batch`, {
210209
method: 'DELETE',
211-
body: JSON.stringify({ ids })
210+
body: JSON.stringify({ filters })
212211
});
213212
return res.json();
214213
}

0 commit comments

Comments
 (0)