mirror of
https://github.com/strapi/strapi.git
synced 2025-09-19 05:23:05 +00:00
27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
import type { Attribute, Model } from './types';
|
|
|
|
import { isRelationalAttribute } from './content-types';
|
|
|
|
const MANY_RELATIONS = ['oneToMany', 'manyToMany'];
|
|
|
|
const getRelationalFields = (contentType: Model) => {
|
|
return Object.keys(contentType.attributes).filter((attributeName) => {
|
|
return contentType.attributes[attributeName].type === 'relation';
|
|
});
|
|
};
|
|
|
|
const isOneToAny = (attribute: Attribute) =>
|
|
isRelationalAttribute(attribute) && ['oneToOne', 'oneToMany'].includes(attribute.relation);
|
|
const isManyToAny = (attribute: Attribute) =>
|
|
isRelationalAttribute(attribute) && ['manyToMany', 'manyToOne'].includes(attribute.relation);
|
|
const isAnyToOne = (attribute: Attribute) =>
|
|
isRelationalAttribute(attribute) && ['oneToOne', 'manyToOne'].includes(attribute.relation);
|
|
const isAnyToMany = (attribute: Attribute) =>
|
|
isRelationalAttribute(attribute) && ['oneToMany', 'manyToMany'].includes(attribute.relation);
|
|
|
|
export const constants = {
|
|
MANY_RELATIONS,
|
|
};
|
|
|
|
export { getRelationalFields, isOneToAny, isManyToAny, isAnyToOne, isAnyToMany };
|