({name, property, settings})
| 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 = [] |
no test coverage detected