MCPcopy
hub / github.com/directus/directus / updateOne

Method updateOne

api/src/services/collections.ts:452–517  ·  view source on GitHub ↗

* Update a single collection by name

(collectionKey: string, payload: DeepPartial<Collection>, opts?: MutationOptions)

Source from the content-addressed store, hash-verified

450 * Update a single collection by name
451 */
452 async updateOne(collectionKey: string, payload: DeepPartial<Collection>, opts?: MutationOptions): Promise<string> {
453 if (this.accountability && this.accountability.admin !== true) {
454 throw new ForbiddenError();
455 }
456
457 const nestedActionEvents: ActionEventParams[] = [];
458
459 try {
460 const collectionsItemsService = new ItemsService('directus_collections', {
461 knex: this.knex,
462 accountability: this.accountability,
463 schema: this.schema,
464 });
465
466 if (!payload.meta) {
467 return collectionKey;
468 }
469
470 if (payload.meta?.status === 'active') {
471 await getEntitlementManager().assert('collections', { adding: 1, knex: this.knex });
472 }
473
474 const exists = !!(await this.knex
475 .select('collection')
476 .from('directus_collections')
477 .where({ collection: collectionKey })
478 .first());
479
480 if (exists) {
481 await collectionsItemsService.updateOne(collectionKey, payload.meta, {
482 ...opts,
483 bypassEmitAction: (params) =>
484 opts?.bypassEmitAction ? opts.bypassEmitAction(params) : nestedActionEvents.push(params),
485 });
486 } else {
487 await collectionsItemsService.createOne(
488 { ...payload.meta, collection: collectionKey },
489 {
490 ...opts,
491 bypassEmitAction: (params) =>
492 opts?.bypassEmitAction ? opts.bypassEmitAction(params) : nestedActionEvents.push(params),
493 },
494 );
495 }
496
497 return collectionKey;
498 } finally {
499 if (shouldClearCache(this.cache, opts)) {
500 await this.cache.clear();
501 }
502
503 if (opts?.autoPurgeSystemCache !== false) {
504 await clearSystemCache({ autoPurgeCache: opts?.autoPurgeCache });
505 await getEntitlementManager().clearCache('collections');
506 }
507
508 if (opts?.emitEvents !== false && nestedActionEvents.length > 0) {
509 const updatedSchema = await getSchema();

Callers 5

applyDiffFunction · 0.95
resolveCollectionsFunction · 0.95
updateBatchMethod · 0.95
updateManyMethod · 0.95
resolveSystemAdminFunction · 0.95

Calls 11

updateOneMethod · 0.95
createOneMethod · 0.95
getEntitlementManagerFunction · 0.85
shouldClearCacheFunction · 0.85
clearSystemCacheFunction · 0.85
getSchemaFunction · 0.85
assertMethod · 0.80
fromMethod · 0.80
emitActionMethod · 0.80
clearMethod · 0.65
clearCacheMethod · 0.65

Tested by

no test coverage detected