mirror of
https://github.com/directus/directus.git
synced 2026-04-03 03:00:39 -04:00
Fix upsert of collections meta
This commit is contained in:
@@ -82,6 +82,7 @@ router.patch(
|
|||||||
accountability: req.accountability,
|
accountability: req.accountability,
|
||||||
schema: req.schema,
|
schema: req.schema,
|
||||||
});
|
});
|
||||||
|
|
||||||
await collectionsService.updateOne(req.params.collection, req.body);
|
await collectionsService.updateOne(req.params.collection, req.body);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -265,9 +265,17 @@ export class CollectionsService {
|
|||||||
throw new InvalidPayloadException(`"meta" key is required`);
|
throw new InvalidPayloadException(`"meta" key is required`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We upsert the directus_collections row here, as the database itself can already exist, but
|
const exists = !!(await this.knex
|
||||||
// the meta data missing
|
.select('collection')
|
||||||
await collectionItemsService.upsertOne(payload.meta, opts);
|
.from('directus_collections')
|
||||||
|
.where({ collection: collectionKey })
|
||||||
|
.first());
|
||||||
|
|
||||||
|
if (exists) {
|
||||||
|
await collectionItemsService.updateOne(collectionKey, payload.meta, opts);
|
||||||
|
} else {
|
||||||
|
await collectionItemsService.createOne({ ...payload.meta, collection: collectionKey }, opts);
|
||||||
|
}
|
||||||
|
|
||||||
return collectionKey;
|
return collectionKey;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user