Skip to content

Commit

Permalink
prettier fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anemne committed Sep 9, 2024
1 parent c6e1570 commit 4a5d6cb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
6 changes: 4 additions & 2 deletions studio/schemas/objects/compensations/benefitsByLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ 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 "./utils/validation";

import {
checkForDuplicateLocations,
DocumentWithLocation,
} from "./utils/validation";

export const benefitsByLocation = defineField({
name: "benefitsByLocation",
Expand Down
52 changes: 26 additions & 26 deletions studio/schemas/objects/compensations/utils/validation.ts
Original file line number Diff line number Diff line change
@@ -1,27 +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;
};
_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;
};

0 comments on commit 4a5d6cb

Please sign in to comment.