Skip to content
Snippets Groups Projects
apiPath.ts 3.44 KiB
Newer Older
import { PROJECT_ID } from '@/constants';
import { PerfectSearchParams } from '@/types/search';
import { Point } from '@/types/map';
import { GetPublicationsParams, PublicationsQueryParams } from './publications/publications.types';
const getPublicationsURLSearchParams = (
  providedParams: PublicationsQueryParams,
): URLSearchParams => {
  const params = new URLSearchParams();

  const validProvidedParamsArray = Object.entries(providedParams).filter(([, value]) =>
    Boolean(value),
  );

  validProvidedParamsArray.forEach(([key, value]) => {
    params.append(key, value.toString());
  });

export const apiPath = {
  getBioEntityContentsStringWithQuery: ({
    searchQuery,
    isPerfectMatch,
  }: PerfectSearchParams): string =>
    `projects/${PROJECT_ID}/models/*/bioEntities/:search?query=${searchQuery}&size=1000&perfectMatch=${isPerfectMatch}`,
  getSingleBioEntityContentsStringWithCoordinates: (
    { x, y }: Point,
    currentModelId: number,
  ): string => {
    const coordinates = [x, y].join();
    return `projects/${PROJECT_ID}/models/${currentModelId}/bioEntities:search/?coordinates=${coordinates}&count=1`;
  },
  getReactionsWithIds: (ids: number[]): string =>
    `projects/${PROJECT_ID}/models/*/bioEntities/reactions/?id=${ids.join(',')}&size=1000`,
  getDrugsStringWithQuery: (searchQuery: string): string =>
    `projects/${PROJECT_ID}/drugs:search?query=${searchQuery}`,
  getModelsString: (): string => `projects/${PROJECT_ID}/models/`,
  getChemicalsStringWithQuery: (searchQuery: string): string =>
    `projects/${PROJECT_ID}/chemicals:search?query=${searchQuery}`,
  getAllOverlaysByProjectIdQuery: (
    projectId: string,
    { publicOverlay }: { publicOverlay: boolean },
  ): string => `projects/${projectId}/overlays/?publicOverlay=${String(publicOverlay)}`,
  getAllBackgroundsByProjectIdQuery: (projectId: string): string =>
    `projects/${projectId}/backgrounds/`,
  getProjectById: (projectId: string): string => `projects/${projectId}`,
  getSessionValid: (): string => `users/isSessionValid`,
  postLogin: (): string => `doLogin`,
  getConfigurationOptions: (): string => 'configuration/options/',
  getConfiguration: (): string => 'configuration/',
  getOverlayBioEntity: ({ overlayId, modelId }: { overlayId: number; modelId: number }): string =>
    `projects/${PROJECT_ID}/overlays/${overlayId}/models/${modelId}/bioEntities/`,
  createOverlay: (projectId: string): string => `projects/${projectId}/overlays/`,
  createOverlayFile: (): string => `files/`,
  uploadOverlayFileContent: (fileId: number): string => `files/${fileId}:uploadContent`,
  getStatisticsById: (projectId: string): string => `projects/${projectId}/statistics/`,
  getCompartmentPathwaysIds: (objectId: number): string =>
    `projects/${PROJECT_ID}/models/${objectId}/bioEntities/elements/?columns=id&type=Compartment,Pathway`,
  getCompartmentPathwayDetails: (ids: number[]): string =>
    `projects/${PROJECT_ID}/models/*/bioEntities/elements/?id=${ids.join(',')}`,
  sendCompartmentPathwaysIds: (): string => `projects/${PROJECT_ID}/models/*/bioEntities/elements/`,
  getSourceFile: (): string => `/projects/${PROJECT_ID}:downloadSource`,
  getMesh: (meshId: string): string => `mesh/${meshId}`,
  getTaxonomy: (taxonomyId: string): string => `taxonomy/${taxonomyId}`,
  getPublications: ({ params, modelId = '*' }: GetPublicationsParams): string =>
    `/projects/${PROJECT_ID}/models/${modelId}/publications/?${getPublicationsURLSearchParams(