MCPcopy Create free account
hub / github.com/dadi/api / updateSettings

Method updateSettings

dadi/lib/model/schemaStore.js:426–478  ·  view source on GitHub ↗
({name, property, settings})

Source from the content-addressed store, hash-verified

424 }
425
426 async updateSettings({name, property, settings}) {
427 const database = await this.connection
428 const {results} = await this.find({
429 name,
430 property
431 })
432
433 if (results.length === 0) {
434 throw new Error('SCHEMA_NOT_FOUND')
435 }
436
437 const {settings: currentSettings} = results[0]
438 const updatedSettings = Object.assign({}, currentSettings, settings)
439
440 await this.validate({
441 settings: updatedSettings
442 })
443
444 const update = {
445 settings: updatedSettings,
446 timestamp: Date.now()
447 }
448 const {matchedCount} = await database.update({
449 collection: config.get('schemas.collection'),
450 query: {
451 name,
452 property
453 },
454 update: {
455 $set: update
456 }
457 })
458
459 if (matchedCount === 0) {
460 throw new Error('SCHEMA_NOT_FOUND')
461 }
462
463 const updatedSchema = await this.get({
464 name,
465 property
466 })
467
468 // Reloading the model.
469 Model({
470 isListable: true,
471 name,
472 schema: updatedSchema.fields,
473 settings: updatedSchema.settings,
474 property
475 })
476
477 return updatedSchema
478 }
479
480 async validate({fields, name, property, requiredFields = [], settings}) {
481 let combinedErrors = []

Callers 1

collections.jsFile · 0.80

Calls 4

findMethod · 0.95
validateMethod · 0.95
getMethod · 0.95
ModelFunction · 0.85

Tested by

no test coverage detected