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