MCPcopy Create free account
hub / github.com/axe-api/axe-api / getForeignKeyValueErrors

Function getForeignKeyValueErrors

packages/axe-api/src/Handlers/Helpers.ts:655–686  ·  view source on GitHub ↗
(context: IContext)

Source from the content-addressed store, hash-verified

653};
654
655export const getForeignKeyValueErrors = async (context: IContext) => {
656 const { model, database, version } = context;
657 // Getting all foreign rules.
658 const foreignRelations = model.relations.filter(
659 (relation) => relation.type === Relationships.HAS_ONE,
660 );
661
662 const tasks: BulkTask<IForeignKeyTask, boolean>[] = [];
663 for (const relation of foreignRelations) {
664 const value = context.formData[relation.foreignKey];
665 tasks.push({
666 data: {
667 value,
668 relation,
669 },
670 promise: validateForeignValues(database, version, relation, value),
671 });
672 }
673
674 const results = await Promise.all(tasks.map((promise) => promise.promise));
675 return results
676 .map((result, index) => {
677 if (result) {
678 return null;
679 }
680
681 const data = tasks[index].data;
682
683 return `Invalid value: ${data.relation.foreignKey} = ${data.value}`;
684 })
685 .filter((error) => error);
686};
687
688export const getSearchData = (
689 model: IModelService,

Callers 3

PreparePhase.tsFile · 0.90

Calls 2

validateForeignValuesFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected