diff --git a/studio/schemas/objects/compensations/benefitsByLocation.ts b/studio/schemas/objects/compensations/benefitsByLocation.ts index 71f0d2c34..2ca07b2a1 100644 --- a/studio/schemas/objects/compensations/benefitsByLocation.ts +++ b/studio/schemas/objects/compensations/benefitsByLocation.ts @@ -2,10 +2,8 @@ import { defineField } from "sanity"; import { location, locationID } from "../locations"; import { companyLocationNameID } from "studio/schemas/documents/companyLocation"; import { benefitId } from "studio/schemas/documents/benefit"; -import { - checkForDuplicateLocations, - DocumentWithLocation, -} from "studio/utils/checkForDuplicateLocations"; +import { checkForDuplicateLocations, DocumentWithLocation } from "./utils/validation"; + export const benefitsByLocation = defineField({ name: "benefitsByLocation", diff --git a/studio/schemas/objects/compensations/utils/validation.ts b/studio/schemas/objects/compensations/utils/validation.ts new file mode 100644 index 000000000..27d84d302 --- /dev/null +++ b/studio/schemas/objects/compensations/utils/validation.ts @@ -0,0 +1,27 @@ +interface LocationReference { + _ref: string; + _type: string; + title?: string; + } + + export interface DocumentWithLocation { + location: LocationReference; + } + + /** + * Checks for duplicate location references in the documents array. + * Ensures each location has a unique document entry. + * + * @param {DocumentWithLocation[] | undefined} documents - The array of documents, each with one or more locations. + * @returns {string | true} - Returns an error message if duplicate locations are found, or true if all are unique. + */ + export const checkForDuplicateLocations = ( + documents: DocumentWithLocation[] | undefined, + ): boolean => { + if (!documents) return true; + const locationRefs = documents + .map((entry) => entry.location?._ref) + .filter(Boolean); + const uniqueRefs = new Set(locationRefs); + return uniqueRefs.size === locationRefs.length; + }; \ No newline at end of file diff --git a/studio/utils/checkForDuplicateLocations.ts b/studio/utils/checkForDuplicateLocations.ts deleted file mode 100644 index 5369f7d40..000000000 --- a/studio/utils/checkForDuplicateLocations.ts +++ /dev/null @@ -1,20 +0,0 @@ -interface LocationReference { - _ref: string; - _type: string; - title?: string; -} - -export interface DocumentWithLocation { - location: LocationReference; -} - -export const checkForDuplicateLocations = ( - documents: DocumentWithLocation[] | undefined, -): boolean => { - if (!documents) return true; - const locationRefs = documents - .map((entry) => entry.location?._ref) - .filter(Boolean); - const uniqueRefs = new Set(locationRefs); - return uniqueRefs.size === locationRefs.length; -};