Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor model transformers and test helpers to use payload interfaces instead of 'any' #108

Open
GPortas opened this issue Dec 21, 2023 · 0 comments
Labels
Size: 3 A percentage of a sprint. 2.1 hours.

Comments

@GPortas
Copy link
Contributor

GPortas commented Dec 21, 2023

Overview of the Feature Request

Refactor model transformers and test helpers to use payload interfaces instead of 'any'

Example

Use a payload model like:

export interface DatasetPreviewPayload {
  global_id: string;
  name: string;
  versionId: number;
  majorVersion: number;
  minorVersion: number;
  versionState: string;
  createdAt: string;
  updatedAt: string;
  published_at?: string;
  citation: string;
  description: string;
}

export const transformDatasetPreviewsResponseToPreviews = (response: AxiosResponse): DatasetPreview[] => {
  const datasetPreviews: DatasetPreview[] = [];
  const datasetPreviewsPayload = response.data.data.items;
  datasetPreviewsPayload.forEach(function (datasetPreviewPayload: DatasetPreviewPayload) {
    datasetPreviews.push(transformDatasetPreviewPayloadToDatasetPreview(datasetPreviewPayload));
  });
  return datasetPreviews;
};

const transformDatasetPreviewPayloadToDatasetPreview = (
  datasetPreviewPayload: DatasetPreviewPayload,
): DatasetPreview => {
  return {
    persistentId: datasetPreviewPayload.global_id,
    title: datasetPreviewPayload.name,
    versionId: datasetPreviewPayload.versionId,
    versionInfo: {
      majorNumber: datasetPreviewPayload.majorVersion,
      minorNumber: datasetPreviewPayload.minorVersion,
      state: datasetPreviewPayload.versionState as DatasetVersionState,
      createTime: new Date(datasetPreviewPayload.createdAt),
      lastUpdateTime: new Date(datasetPreviewPayload.updatedAt),
      ...(datasetPreviewPayload.published_at && { releaseTime: new Date(datasetPreviewPayload.published_at) }),
    },
    citation: datasetPreviewPayload.citation,
    description: datasetPreviewPayload.description,
  };
};

Instead of

export const transformDatasetPreviewsResponseToPreviews = (response: AxiosResponse): DatasetPreview[] => {
  const datasetPreviews: DatasetPreview[] = [];
  const datasetPreviewsPayload = response.data.data.items;
  // eslint-disable-next-line  @typescript-eslint/no-explicit-any
  datasetPreviewsPayload.forEach(function (datasetPreviewPayload: any) {
    datasetPreviews.push(transformDatasetPreviewPayloadToDatasetPreview(datasetPreviewPayload));
  });
  return datasetPreviews;
};

// eslint-disable-next-line  @typescript-eslint/no-explicit-any
const transformDatasetPreviewPayloadToDatasetPreview = (datasetPreviewPayload: any): DatasetPreview => {
  return {
    persistentId: datasetPreviewPayload.global_id,
    title: datasetPreviewPayload.name,
    versionId: datasetPreviewPayload.versionId,
    versionInfo: {
      majorNumber: datasetPreviewPayload.majorVersion,
      minorNumber: datasetPreviewPayload.minorVersion,
      state: datasetPreviewPayload.versionState as DatasetVersionState,
      createTime: new Date(datasetPreviewPayload.createdAt),
      lastUpdateTime: new Date(datasetPreviewPayload.updatedAt),
      ...(datasetPreviewPayload.published_at && { releaseTime: new Date(datasetPreviewPayload.published_at) }),
    },
    citation: datasetPreviewPayload.citation,
    description: datasetPreviewPayload.description,
  };
};

What kind of user is the feature intended for?

Developer

What inspired the request?

What existing behavior do you want changed?

None

Any brand new behavior do you want to add to Dataverse?

None

Any open or closed issues related to this feature request?

@GPortas GPortas changed the title Refactor datasetTransformers and datasetHelpers to use payload models instead of 'any' Refactor datasetTransformers and datasetHelper (test helper) to use payload models instead of 'any' Dec 21, 2023
@GPortas GPortas added pm.GREI-d-2.7.1 NIH, yr2, aim7, task1: R&D UI modules for creating datasets and supporting publishing workflows pm.GREI-d-2.7.2 NIH, yr2, aim7, task2: Implement UI modules for creating datasets and publishing workflows Size: 10 A percentage of a sprint. 7 hours. Size: 3 A percentage of a sprint. 2.1 hours. and removed Size: 10 A percentage of a sprint. 7 hours. labels Dec 21, 2023
@GPortas GPortas changed the title Refactor datasetTransformers and datasetHelper (test helper) to use payload models instead of 'any' Refactor model transformers and test helpers (test helper) to use payload models instead of 'any' Dec 21, 2023
@GPortas GPortas changed the title Refactor model transformers and test helpers (test helper) to use payload models instead of 'any' Refactor model transformers and test helpers to use payload models instead of 'any' Dec 21, 2023
@GPortas GPortas changed the title Refactor model transformers and test helpers to use payload models instead of 'any' Refactor model transformers and test helpers to use payload interfaces instead of 'any' Dec 21, 2023
@GPortas GPortas removed pm.GREI-d-2.7.1 NIH, yr2, aim7, task1: R&D UI modules for creating datasets and supporting publishing workflows pm.GREI-d-2.7.2 NIH, yr2, aim7, task2: Implement UI modules for creating datasets and publishing workflows labels Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: 3 A percentage of a sprint. 2.1 hours.
Projects
None yet
Development

No branches or pull requests

1 participant