(
prefix: DataPrefix_,
suffix: string,
model: Partial<InstanceType<Awaited<ReturnType<Model>>>>,
params?: {
cacheOnly?: boolean;
trx?: TransactionOrKnex;
dtrx?: DataTransaction;
},
)
| 541 | } |
| 542 | |
| 543 | async patch< |
| 544 | DataPrefix_ extends DataPrefix, |
| 545 | Model extends DataHashes_[DataPrefix_]['model'], |
| 546 | >( |
| 547 | prefix: DataPrefix_, |
| 548 | suffix: string, |
| 549 | model: Partial<InstanceType<Awaited<ReturnType<Model>>>>, |
| 550 | params?: { |
| 551 | cacheOnly?: boolean; |
| 552 | |
| 553 | trx?: TransactionOrKnex; |
| 554 | dtrx?: DataTransaction; |
| 555 | }, |
| 556 | ) { |
| 557 | // Collect the extra columns of all fields affected |
| 558 | |
| 559 | const extraColumns = new Set<string>(); |
| 560 | |
| 561 | await Promise.allSettled( |
| 562 | Object.entries(this.dataHashes[prefix].fields).map( |
| 563 | async ([_fieldName, fieldInfos]) => { |
| 564 | let modelHasSomeFieldColumns = false; |
| 565 | |
| 566 | for (const column of fieldInfos.columns ?? []) { |
| 567 | if (column in model) { |
| 568 | modelHasSomeFieldColumns = true; |
| 569 | break; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | if (modelHasSomeFieldColumns) { |
| 574 | for (const column of fieldInfos.columns ?? []) { |
| 575 | if (!(column in model)) { |
| 576 | extraColumns.add(column); |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | }, |
| 581 | ), |
| 582 | ); |
| 583 | |
| 584 | if (!params?.cacheOnly) { |
| 585 | let patchQuery: any = (await this.dataHashes[prefix].model()) |
| 586 | .query(params?.dtrx?.trx ?? params?.trx) |
| 587 | .findById(splitStr(suffix, ':')) |
| 588 | .patch(model); |
| 589 | |
| 590 | if (extraColumns.size > 0) { |
| 591 | patchQuery = patchQuery.returning(Array.from(extraColumns)); |
| 592 | } |
| 593 | |
| 594 | model = { ...model, ...(await patchQuery) }; |
| 595 | } else if (extraColumns.size > 0) { |
| 596 | model = { |
| 597 | ...model, |
| 598 | ...(await this.dataHashes[prefix].model()) |
| 599 | .query(params?.dtrx?.trx ?? params?.trx) |
| 600 | .findById(splitStr(suffix, ':')) |
no test coverage detected