From 3a26dc9e36a14855f99dbb4a95c497094018e0b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Wed, 11 Dec 2024 21:32:29 -0300 Subject: [PATCH] types alocations --- .../domain/models/CollectionSearchCriteria.ts | 45 ++++++++++++++++--- .../models/GetCollectionItemsQueryParams.ts | 23 ---------- .../repositories/CollectionsRepository.ts | 19 ++++++-- .../collections/CollectionsRepository.test.ts | 2 +- .../collections/CollectionsRepository.test.ts | 14 +++--- 5 files changed, 64 insertions(+), 39 deletions(-) delete mode 100644 src/collections/domain/models/GetCollectionItemsQueryParams.ts diff --git a/src/collections/domain/models/CollectionSearchCriteria.ts b/src/collections/domain/models/CollectionSearchCriteria.ts index 5d000c72..3f36735b 100644 --- a/src/collections/domain/models/CollectionSearchCriteria.ts +++ b/src/collections/domain/models/CollectionSearchCriteria.ts @@ -1,5 +1,16 @@ import { CollectionItemType } from './CollectionItemType' -import { FilterQuery, OrderType, SortType } from './GetCollectionItemsQueryParams' + +export enum SortType { + NAME = 'name', + DATE = 'date' +} + +export enum OrderType { + ASC = 'asc', + DESC = 'desc' +} + +export type FilterQuery = `${string}:${string}` export class CollectionSearchCriteria { constructor( @@ -11,19 +22,43 @@ export class CollectionSearchCriteria { ) {} withSearchText(searchText: string | undefined): CollectionSearchCriteria { - return new CollectionSearchCriteria(searchText, this.itemTypes, this.sort, this.order) + return new CollectionSearchCriteria( + searchText, + this.itemTypes, + this.sort, + this.order, + this.filterQueries + ) } withItemTypes(itemTypes: CollectionItemType[] | undefined): CollectionSearchCriteria { - return new CollectionSearchCriteria(this.searchText, itemTypes, this.sort, this.order) + return new CollectionSearchCriteria( + this.searchText, + itemTypes, + this.sort, + this.order, + this.filterQueries + ) } withSort(sort: SortType | undefined): CollectionSearchCriteria { - return new CollectionSearchCriteria(this.searchText, this.itemTypes, sort, this.order) + return new CollectionSearchCriteria( + this.searchText, + this.itemTypes, + sort, + this.order, + this.filterQueries + ) } withOrder(order: OrderType | undefined): CollectionSearchCriteria { - return new CollectionSearchCriteria(this.searchText, this.itemTypes, this.sort, order) + return new CollectionSearchCriteria( + this.searchText, + this.itemTypes, + this.sort, + order, + this.filterQueries + ) } withFilterQueries(filterQueries: FilterQuery[] | undefined): CollectionSearchCriteria { diff --git a/src/collections/domain/models/GetCollectionItemsQueryParams.ts b/src/collections/domain/models/GetCollectionItemsQueryParams.ts deleted file mode 100644 index 3c9dd1b3..00000000 --- a/src/collections/domain/models/GetCollectionItemsQueryParams.ts +++ /dev/null @@ -1,23 +0,0 @@ -export enum GetCollectionItemsQueryParams { - QUERY = 'q', - SHOW_FACETS = 'show_facets', - SORT = 'sort', - ORDER = 'order', - SUBTREE = 'subtree', - PER_PAGE = 'per_page', - START = 'start', - TYPE = 'type', - FILTERQUERY = 'fq' -} - -export enum SortType { - NAME = 'name', - DATE = 'date' -} - -export enum OrderType { - ASC = 'asc', - DESC = 'desc' -} - -export type FilterQuery = `${string}:${string}` diff --git a/src/collections/infra/repositories/CollectionsRepository.ts b/src/collections/infra/repositories/CollectionsRepository.ts index 242df28e..bee82863 100644 --- a/src/collections/infra/repositories/CollectionsRepository.ts +++ b/src/collections/infra/repositories/CollectionsRepository.ts @@ -11,13 +11,12 @@ import { CollectionFacet } from '../../domain/models/CollectionFacet' import { CollectionUserPermissions } from '../../domain/models/CollectionUserPermissions' import { transformCollectionUserPermissionsResponseToCollectionUserPermissions } from './transformers/collectionUserPermissionsTransformers' import { CollectionItemSubset } from '../../domain/models/CollectionItemSubset' -import { CollectionSearchCriteria } from '../../domain/models/CollectionSearchCriteria' -import { CollectionItemType } from '../../domain/models/CollectionItemType' import { - GetCollectionItemsQueryParams, + CollectionSearchCriteria, OrderType, SortType -} from '../../domain/models/GetCollectionItemsQueryParams' +} from '../../domain/models/CollectionSearchCriteria' +import { CollectionItemType } from '../../domain/models/CollectionItemType' export interface NewCollectionRequestPayload { alias: string @@ -45,6 +44,18 @@ export interface NewCollectionInputLevelRequestPayload { required: boolean } +export enum GetCollectionItemsQueryParams { + QUERY = 'q', + SHOW_FACETS = 'show_facets', + SORT = 'sort', + ORDER = 'order', + SUBTREE = 'subtree', + PER_PAGE = 'per_page', + START = 'start', + TYPE = 'type', + FILTERQUERY = 'fq' +} + export class CollectionsRepository extends ApiRepository implements ICollectionsRepository { private readonly collectionsResourceName: string = 'dataverses' diff --git a/test/integration/collections/CollectionsRepository.test.ts b/test/integration/collections/CollectionsRepository.test.ts index bff0f6a5..e763e105 100644 --- a/test/integration/collections/CollectionsRepository.test.ts +++ b/test/integration/collections/CollectionsRepository.test.ts @@ -27,7 +27,7 @@ import { CollectionType } from '../../../src/collections/domain/models/Collectio import { OrderType, SortType -} from '../../../src/collections/domain/models/GetCollectionItemsQueryParams' +} from '../../../src/collections/domain/models/CollectionSearchCriteria' describe('CollectionsRepository', () => { const testCollectionAlias = 'collectionsRepositoryTestCollection' diff --git a/test/unit/collections/CollectionsRepository.test.ts b/test/unit/collections/CollectionsRepository.test.ts index 5c407e58..d7a0af31 100644 --- a/test/unit/collections/CollectionsRepository.test.ts +++ b/test/unit/collections/CollectionsRepository.test.ts @@ -1,4 +1,7 @@ -import { CollectionsRepository } from '../../../src/collections/infra/repositories/CollectionsRepository' +import { + CollectionsRepository, + GetCollectionItemsQueryParams +} from '../../../src/collections/infra/repositories/CollectionsRepository' import axios from 'axios' import { ApiConfig, @@ -31,15 +34,14 @@ import { createCollectionPreviewModel, createCollectionPreviewPayload } from '../../testHelpers/collections/collectionPreviewHelper' -import { - GetCollectionItemsQueryParams, - OrderType, - SortType -} from '../../../src/collections/domain/models/GetCollectionItemsQueryParams' import { createCollectionItemsFacetsModel, createCollectionItemsFacetsPayload } from '../../testHelpers/collections/collectionItemsFacetsHelper' +import { + OrderType, + SortType +} from '../../../src/collections/domain/models/CollectionSearchCriteria' describe('CollectionsRepository', () => { const sut: CollectionsRepository = new CollectionsRepository()