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

Function validateForeignValues

packages/axe-api/src/Handlers/Helpers.ts:630–653  ·  view source on GitHub ↗
(
  database: Knex,
  version: IVersion,
  relation: IRelation,
  value: any,
)

Source from the content-addressed store, hash-verified

628};
629
630const validateForeignValues = async (
631 database: Knex,
632 version: IVersion,
633 relation: IRelation,
634 value: any,
635): Promise<boolean> => {
636 if (!value) {
637 return true;
638 }
639
640 const foreignModel = version.modelList
641 .get()
642 .find((model) => model.name === relation.model);
643
644 if (!foreignModel) {
645 throw new Error(`The model not found: ${relation.model}`);
646 }
647
648 const found = await database(foreignModel.instance.table)
649 .where(foreignModel.instance.primaryKey, value)
650 .first();
651
652 return !!found;
653};
654
655export const getForeignKeyValueErrors = async (context: IContext) => {
656 const { model, database, version } = context;

Callers 1

getForeignKeyValueErrorsFunction · 0.85

Calls 2

findMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected