mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Update SDK docs and code to match API (#5437)
This commit is contained in:
@@ -230,53 +230,28 @@ await articles.readOne(15);
|
||||
Supports optional query:
|
||||
|
||||
```js
|
||||
// One
|
||||
await articles.readOne(15, { fields: ['title'] });
|
||||
```
|
||||
|
||||
Supports optional query:
|
||||
|
||||
```js
|
||||
await articles.updateOne(15, { title: 'An Updated title' }, { fields: ['title'] });
|
||||
|
||||
await articles.updateMany(
|
||||
[
|
||||
/*...*/
|
||||
],
|
||||
{ fields: ['title'] }
|
||||
);
|
||||
```
|
||||
|
||||
### Update Multiple Items
|
||||
|
||||
```js
|
||||
await articles.updateMany([
|
||||
{
|
||||
id: 15,
|
||||
title: 'Article 15',
|
||||
},
|
||||
{
|
||||
id: 42,
|
||||
title: 'Article 42',
|
||||
},
|
||||
]);
|
||||
await articles.updateMany([15, 42], {
|
||||
title: 'Both articles now have the same title',
|
||||
});
|
||||
```
|
||||
|
||||
Supports optional query:
|
||||
|
||||
```js
|
||||
await articles.updateMany(
|
||||
[
|
||||
{
|
||||
id: 15,
|
||||
title: 'Article 15',
|
||||
},
|
||||
{
|
||||
id: 42,
|
||||
title: 'Article 42',
|
||||
},
|
||||
],
|
||||
{ fields: ['title'] }
|
||||
[15, 42],
|
||||
{
|
||||
title: 'Both articles now have the same title',
|
||||
},
|
||||
{
|
||||
fields: ['title'],
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
|
||||
@@ -52,13 +52,17 @@ export class ItemsHandler<T extends Item> implements IItems<T> {
|
||||
).data;
|
||||
}
|
||||
|
||||
// TODO: needs to support submitting arrays
|
||||
// async updateMany(ids: item: PartialItem<T>, query?: QueryMany<T>): Promise<ManyItems<T>>;
|
||||
|
||||
async updateMany(items: PartialItem<T>[], query?: QueryMany<T>): Promise<ManyItems<T>> {
|
||||
return await this.transport.patch<PartialItem<T>[]>(`${this.endpoint}`, items, {
|
||||
params: query,
|
||||
});
|
||||
async updateMany(ids: ID[], data: PartialItem<T>, query?: QueryMany<T>): Promise<ManyItems<T>> {
|
||||
return await this.transport.patch<PartialItem<T>[]>(
|
||||
`${this.endpoint}`,
|
||||
{
|
||||
keys: ids,
|
||||
data,
|
||||
},
|
||||
{
|
||||
params: query,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async deleteOne(id: ID): Promise<void> {
|
||||
|
||||
@@ -81,7 +81,7 @@ export interface IItems<T extends Item> {
|
||||
readMany(query?: QueryMany<T>): Promise<ManyItems<T>>;
|
||||
|
||||
updateOne(id: ID, item: PartialItem<T>, query?: QueryOne<T>): Promise<OneItem<T>>;
|
||||
updateMany(items: PartialItem<T>[], query?: QueryMany<T>): Promise<ManyItems<T>>;
|
||||
updateMany(ids: ID[], item: PartialItem<T>, query?: QueryMany<T>): Promise<ManyItems<T>>;
|
||||
|
||||
deleteOne(id: ID): Promise<void>;
|
||||
deleteMany(ids: ID[]): Promise<void>;
|
||||
|
||||
@@ -233,40 +233,31 @@ describe('items', function () {
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: 'Updated post 2',
|
||||
body: 'Updated post content 2',
|
||||
title: 'Updated post',
|
||||
body: 'Updated post content',
|
||||
published: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const sdk = new Directus<Blog>(url);
|
||||
const item = await sdk.items('posts').updateMany([
|
||||
{
|
||||
id: 1,
|
||||
title: 'Updated post',
|
||||
body: 'Updated post content',
|
||||
published: true,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: 'Updated post 2',
|
||||
body: 'Updated post content 2',
|
||||
published: true,
|
||||
},
|
||||
]);
|
||||
const items = await sdk.items('posts').updateMany([1, 2], {
|
||||
title: 'Updated post',
|
||||
body: 'Updated post content',
|
||||
published: true,
|
||||
});
|
||||
|
||||
expect(item.data?.[0]).toMatchObject({
|
||||
expect(items.data?.[0]).toMatchObject({
|
||||
id: 1,
|
||||
title: 'Updated post',
|
||||
body: 'Updated post content',
|
||||
published: true,
|
||||
});
|
||||
|
||||
expect(item.data?.[1]).toMatchObject({
|
||||
expect(items.data?.[1]).toMatchObject({
|
||||
id: 2,
|
||||
title: 'Updated post 2',
|
||||
body: 'Updated post content 2',
|
||||
title: 'Updated post',
|
||||
body: 'Updated post content',
|
||||
published: true,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user