From 389490d9be98fecac0729d717445c2fcd8aa0fd2 Mon Sep 17 00:00:00 2001 From: nsemets Date: Thu, 21 May 2026 13:16:46 +0300 Subject: [PATCH 1/5] fix(activity-logs): updated models and mapper --- src/app/features/metadata/models/ror.model.ts | 102 ++++++++---------- .../shared/mappers/activity-logs.mapper.ts | 81 ++------------ .../activity-logs-json-api.model.ts | 88 ++------------- .../activity-logs/activity-logs.model.ts | 73 +------------ 4 files changed, 62 insertions(+), 282 deletions(-) diff --git a/src/app/features/metadata/models/ror.model.ts b/src/app/features/metadata/models/ror.model.ts index 5775df7e4..a4ddede3a 100644 --- a/src/app/features/metadata/models/ror.model.ts +++ b/src/app/features/metadata/models/ror.model.ts @@ -1,4 +1,40 @@ -export interface RorAdmin { +export interface RorSearchResponse { + items: RorOrganization[]; + meta: RorMeta; + number_of_results: number; + time_taken: number; +} + +export interface RorFunderOption { + id: string; + name: string; +} + +export interface RorOrganization { + id: string; + admin: RorAdmin; + domains: string[]; + established: number | null; + external_ids: RorExternalId[]; + links: RorLink[]; + locations: RorLocation[]; + names: RorName[]; + relationships: RorRelationship[]; + status: 'active' | 'inactive' | 'withdrawn'; + types: ( + | 'education' + | 'healthcare' + | 'company' + | 'archive' + | 'nonprofit' + | 'government' + | 'facility' + | 'other' + | 'funder' + )[]; +} + +interface RorAdmin { created: { date: string; schema_version: string; @@ -9,18 +45,18 @@ export interface RorAdmin { }; } -export interface RorExternalId { +interface RorExternalId { all: string[]; preferred: string | null; type: 'grid' | 'fundref' | 'isni' | 'wikidata'; } -export interface RorLink { +interface RorLink { type: 'website' | 'wikipedia'; value: string; } -export interface RorGeonamesDetails { +interface RorGeonamesDetails { continent_code: string; continent_name: string; country_code: string; @@ -32,80 +68,32 @@ export interface RorGeonamesDetails { name: string; } -export interface RorLocation { +interface RorLocation { geonames_details: RorGeonamesDetails; geonames_id: number; } -export interface RorName { +interface RorName { lang: string | null; types: ('ror_display' | 'label' | 'alias' | 'acronym')[]; value: string; } -export interface RorRelationship { +interface RorRelationship { type: string; id: string; label: string; } -export interface RorOrganization { - id: string; - admin: RorAdmin; - domains: string[]; - established: number | null; - external_ids: RorExternalId[]; - links: RorLink[]; - locations: RorLocation[]; - names: RorName[]; - relationships: RorRelationship[]; - status: 'active' | 'inactive' | 'withdrawn'; - types: ( - | 'education' - | 'healthcare' - | 'company' - | 'archive' - | 'nonprofit' - | 'government' - | 'facility' - | 'other' - | 'funder' - )[]; -} - -export interface RorMetaCount { +interface RorMetaCount { id: string; title: string; count: number; } -export interface RorMeta { +interface RorMeta { types: RorMetaCount[]; countries: RorMetaCount[]; continents: RorMetaCount[]; statuses: RorMetaCount[]; } - -export interface RorSearchResponse { - items: RorOrganization[]; - meta: RorMeta; - number_of_results: number; - time_taken: number; -} - -export interface RorFunderOption { - id: string; - name: string; -} - -export interface RorDisplayData { - id: string; - displayName: string; - acronym?: string; - type: string; - country: string; - city: string; - established?: number; - website?: string; - status: string; -} diff --git a/src/app/shared/mappers/activity-logs.mapper.ts b/src/app/shared/mappers/activity-logs.mapper.ts index ba0caf8ea..3c40ba7b6 100644 --- a/src/app/shared/mappers/activity-logs.mapper.ts +++ b/src/app/shared/mappers/activity-logs.mapper.ts @@ -6,6 +6,9 @@ import { ActivityLogJsonApi, LogContributorJsonApi } from '../models/activity-lo import { ResponseJsonApi } from '../models/common/json-api.model'; import { PaginatedData } from '../models/paginated-data.model'; +import { BaseNodeMapper } from './nodes'; +import { UserMapper } from './user'; + export class ActivityLogsMapper { static fromActivityLogJsonApi(log: ActivityLogJsonApi, isAnonymous?: boolean): ActivityLog { const params = log.attributes.params ?? {}; @@ -71,83 +74,11 @@ export class ActivityLogsMapper { embeds: log.embeds ? { originalNode: log.embeds.original_node?.data - ? { - id: log.embeds.original_node.data.id, - type: log.embeds.original_node.data.type, - title: replaceBadEncodedChars(log.embeds.original_node.data.attributes.title), - description: replaceBadEncodedChars(log.embeds.original_node.data.attributes.description), - category: log.embeds.original_node.data.attributes.category, - customCitation: log.embeds.original_node.data.attributes.custom_citation, - dateCreated: log.embeds.original_node.data.attributes.date_created, - dateModified: log.embeds.original_node.data.attributes.date_modified, - registration: log.embeds.original_node.data.attributes.registration, - preprint: log.embeds.original_node.data.attributes.preprint, - fork: log.embeds.original_node.data.attributes.fork, - collection: log.embeds.original_node.data.attributes.collection, - tags: log.embeds.original_node.data.attributes.tags, - accessRequestsEnabled: log.embeds.original_node.data.attributes.access_requests_enabled, - nodeLicense: log.embeds.original_node.data.attributes.node_license - ? { - copyrightHolders: log.embeds.original_node.data.attributes.node_license.copyright_holders, - year: log.embeds.original_node.data.attributes.node_license.year, - } - : { copyrightHolders: [], year: null }, - currentUserCanComment: log.embeds.original_node.data.attributes.current_user_can_comment, - currentUserPermissions: log.embeds.original_node.data.attributes.current_user_permissions, - currentUserIsContributor: log.embeds.original_node.data.attributes.current_user_is_contributor, - currentUserIsContributorOrGroupMember: - log.embeds.original_node.data.attributes.current_user_is_contributor_or_group_member, - wikiEnabled: log.embeds.original_node.data.attributes.wiki_enabled, - public: log.embeds.original_node.data.attributes.public, - subjects: log.embeds.original_node.data.attributes.subjects, - } - : undefined, - user: log.embeds.user?.data - ? { - id: log.embeds.user.data.id, - type: log.embeds.user.data.type, - fullName: log.embeds.user.data.attributes.full_name, - givenName: log.embeds.user.data.attributes.given_name, - middleNames: log.embeds.user.data.attributes.middle_names, - familyName: log.embeds.user.data.attributes.family_name, - suffix: log.embeds.user.data.attributes.suffix, - dateRegistered: log.embeds.user.data.attributes.date_registered, - active: log.embeds.user.data.attributes.active, - timezone: log.embeds.user.data.attributes.timezone, - locale: log.embeds.user.data.attributes.locale, - } + ? BaseNodeMapper.getNodeData(log.embeds.original_node.data) : undefined, + user: log.embeds.user?.data ? UserMapper.fromUserGetResponse(log.embeds.user.data) : undefined, linkedNode: log.embeds.linked_node?.data - ? { - id: log.embeds.linked_node.data.id, - type: log.embeds.linked_node.data.type, - title: replaceBadEncodedChars(log.embeds.linked_node.data.attributes.title), - description: replaceBadEncodedChars(log.embeds.linked_node.data.attributes.description), - category: log.embeds.linked_node.data.attributes.category, - customCitation: log.embeds.linked_node.data.attributes.custom_citation, - dateCreated: log.embeds.linked_node.data.attributes.date_created, - dateModified: log.embeds.linked_node.data.attributes.date_modified, - registration: log.embeds.linked_node.data.attributes.registration, - preprint: log.embeds.linked_node.data.attributes.preprint, - fork: log.embeds.linked_node.data.attributes.fork, - collection: log.embeds.linked_node.data.attributes.collection, - tags: log.embeds.linked_node.data.attributes.tags, - accessRequestsEnabled: log.embeds.linked_node.data.attributes.access_requests_enabled, - nodeLicense: log.embeds.linked_node.data.attributes.node_license - ? { - copyrightHolders: log.embeds.linked_node.data.attributes.node_license.copyright_holders, - year: log.embeds.linked_node.data.attributes.node_license.year, - } - : { copyrightHolders: [], year: null }, - currentUserCanComment: log.embeds.linked_node.data.attributes.current_user_can_comment, - currentUserPermissions: log.embeds.linked_node.data.attributes.current_user_permissions, - currentUserIsContributor: log.embeds.linked_node.data.attributes.current_user_is_contributor, - currentUserIsContributorOrGroupMember: - log.embeds.linked_node.data.attributes.current_user_is_contributor_or_group_member, - wikiEnabled: log.embeds.linked_node.data.attributes.wiki_enabled, - public: log.embeds.linked_node.data.attributes.public, - subjects: log.embeds.linked_node.data.attributes.subjects, - } + ? BaseNodeMapper.getNodeData(log.embeds.linked_node.data) : undefined, } : undefined, diff --git a/src/app/shared/models/activity-logs/activity-logs-json-api.model.ts b/src/app/shared/models/activity-logs/activity-logs-json-api.model.ts index a63d50129..11af9b7e8 100644 --- a/src/app/shared/models/activity-logs/activity-logs-json-api.model.ts +++ b/src/app/shared/models/activity-logs/activity-logs-json-api.model.ts @@ -1,3 +1,6 @@ +import { BaseNodeDataJsonApi } from '../nodes/base-node-data-json-api.model'; +import { UserDataJsonApi } from '../user/user-json-api.model'; + export interface ActivityLogJsonApi { id: string; type: string; @@ -78,13 +81,13 @@ export interface ActivityLogJsonApi { }; embeds?: { original_node?: { - data: OriginalNodeEmbedsData; + data: BaseNodeDataJsonApi; }; user?: { - data: UserEmbedsData; + data: UserDataJsonApi; }; linked_node?: { - data: LinkedNodeEmbedsData; + data: BaseNodeDataJsonApi; }; }; meta: { @@ -100,85 +103,6 @@ interface PointerJsonApi { url: string; } -interface OriginalNodeEmbedsData { - id: string; - type: string; - attributes: { - title: string; - description: string; - category: string; - custom_citation: string | null; - date_created: string; - date_modified: string; - registration: boolean; - preprint: boolean; - fork: boolean; - collection: boolean; - tags: string[]; - access_requests_enabled: boolean; - node_license: { - copyright_holders: string[]; - year: string | null; - } | null; - current_user_can_comment: boolean; - current_user_permissions: string[]; - current_user_is_contributor: boolean; - current_user_is_contributor_or_group_member: boolean; - wiki_enabled: boolean; - public: boolean; - subjects: { id: string; text: string }[][]; - }; -} - -interface UserEmbedsData { - id: string; - type: string; - attributes: { - full_name: string; - given_name: string; - middle_names: string; - family_name: string; - suffix: string; - date_registered: string; - active: boolean; - timezone: string; - locale: string; - }; -} - -interface LinkedNodeEmbedsData { - id: string; - type: string; - attributes: { - title: string; - description: string; - category: string; - custom_citation: string | null; - date_created: string; - date_modified: string; - registration: boolean; - preprint: boolean; - fork: boolean; - collection: boolean; - tags: string[]; - access_requests_enabled: boolean; - node_license: { - copyright_holders: string[]; - year: string | null; - } | null; - current_user_can_comment: boolean; - current_user_permissions: string[]; - current_user_is_contributor: boolean; - current_user_is_contributor_or_group_member: boolean; - wiki_enabled: boolean; - public: boolean; - subjects: { - id: string; - text: string; - }[][]; - }; -} - export interface LogContributorJsonApi { id: string; full_name: string; diff --git a/src/app/shared/models/activity-logs/activity-logs.model.ts b/src/app/shared/models/activity-logs/activity-logs.model.ts index 1b729eaf0..658f83212 100644 --- a/src/app/shared/models/activity-logs/activity-logs.model.ts +++ b/src/app/shared/models/activity-logs/activity-logs.model.ts @@ -1,5 +1,6 @@ import { IdNameModel } from '../common/id-name.model'; -import { LicensesOption } from '../license/license.model'; +import { BaseNodeModel } from '../nodes/base-node.model'; +import { UserModel } from '../user/user.model'; export interface ActivityLog { id: string; @@ -38,9 +39,9 @@ export interface ActivityLog { githubUser?: string; }; embeds?: { - originalNode?: OriginalNode; - user?: User; - linkedNode?: LinkedNode; + originalNode?: BaseNodeModel; + user?: UserModel; + linkedNode?: BaseNodeModel; }; isAnonymous?: boolean; } @@ -52,70 +53,6 @@ interface Pointer { url: string; } -interface OriginalNode { - id: string; - type: string; - title: string; - description: string; - category: string; - customCitation: string | null; - dateCreated: string; - dateModified: string; - registration: boolean; - preprint: boolean; - fork: boolean; - collection: boolean; - tags: string[]; - accessRequestsEnabled: boolean; - nodeLicense: LicensesOption; - currentUserCanComment: boolean; - currentUserPermissions: string[]; - currentUserIsContributor: boolean; - currentUserIsContributorOrGroupMember: boolean; - wikiEnabled: boolean; - public: boolean; - subjects: { id: string; text: string }[][]; -} - -interface User { - id: string; - type: string; - fullName: string; - givenName: string; - middleNames: string; - familyName: string; - suffix: string; - dateRegistered: string; - active: boolean; - timezone: string; - locale: string; -} - -interface LinkedNode { - id: string; - type: string; - title: string; - description: string; - category: string; - customCitation: string | null; - dateCreated: string; - dateModified: string; - registration: boolean; - preprint: boolean; - fork: boolean; - collection: boolean; - tags: string[]; - accessRequestsEnabled: boolean; - nodeLicense: LicensesOption; - currentUserCanComment: boolean; - currentUserPermissions: string[]; - currentUserIsContributor: boolean; - currentUserIsContributorOrGroupMember: boolean; - wikiEnabled: boolean; - public: boolean; - subjects: { id: string; text: string }[][]; -} - export interface LogContributor { id: string; fullName: string; From 5bd60529409e64625a6aaa97054636be371183dc Mon Sep 17 00:00:00 2001 From: nsemets Date: Tue, 26 May 2026 19:53:15 +0300 Subject: [PATCH 2/5] refactor(models): updated models for json api --- .../mappers/institution-departments.mapper.ts | 8 +- .../mappers/institution-users.mapper.ts | 2 +- .../models/institution-department.model.ts | 1 - .../institution-departments-json-api.model.ts | 25 +- ...ution-index-value-search-json-api.model.ts | 2 +- ...titution-summary-metrics-json-api.model.ts | 43 +-- .../institution-users-json-api.model.ts | 43 ++- .../models/send-message-json-api.model.ts | 23 +- .../mappers/related-counts.mapper.ts | 10 +- .../models/node-analytics-json-api.model.ts | 19 +- .../models/related-counts-json-api.model.ts | 46 +--- .../services/resource-analytics.service.ts | 4 +- .../mappers/file-custom-metadata.mapper.ts | 5 +- .../files/mappers/file-revision.mapper.ts | 9 +- .../files/mappers/resource-metadata.mapper.ts | 8 +- .../models/file-metadata-response.model.ts | 16 ++ .../models/file-revisions-response.model.ts | 23 ++ .../files/models/file-revisions.model.ts | 2 +- .../get-custom-metadata-response.model.ts | 26 -- .../get-file-metadata-response.model.ts | 10 - .../get-file-revisions-response.model.ts | 16 -- ...resource-custom-metadata-response.model.ts | 29 -- .../get-resource-short-info-response.model.ts | 17 -- .../models/get-short-info-response.model.ts | 17 -- src/app/features/files/models/index.ts | 7 +- .../models/node-short-info-response.model.ts | 20 ++ ...resource-custom-metadata-response.model.ts | 30 ++ .../file-detail/file-detail.component.ts | 4 +- .../pages/dashboard/dashboard.component.ts | 2 +- .../meetings/mappers/meetings.mapper.ts | 12 +- .../models/meetings-json-api.model.ts | 54 ++-- .../meetings/services/meetings.service.ts | 12 +- .../cedar-template-form.component.ts | 4 +- .../metadata/mappers/metadata.mapper.ts | 12 +- .../features/metadata/metadata.component.ts | 4 +- .../models/cedar-metadata-template.model.ts | 138 +++------- .../models/metadata-json-api.model.ts | 71 ++--- .../add-metadata/add-metadata.component.ts | 4 +- .../metadata/store/metadata.actions.ts | 4 +- .../features/metadata/store/metadata.model.ts | 4 +- .../moderation/mappers/moderation.mapper.ts | 21 -- .../mappers/preprint-moderation.mapper.ts | 15 +- .../mappers/registry-moderation.mapper.ts | 7 +- ...submission-review-action-json-api.model.ts | 50 ++-- .../models/moderator-json-api.model.ts | 39 ++- .../preprint-related-count-json-api.model.ts | 40 ++- .../preprint-review-action-json-api.model.ts | 59 ++-- .../preprint-submission-json-api.model.ts | 29 +- ...nt-withdrawal-submission-json-api.model.ts | 36 ++- .../models/registry-json-api.model.ts | 16 +- .../models/review-action-json-api.model.ts | 9 +- .../moderation/services/moderators.service.ts | 14 +- .../services/preprint-moderation.service.ts | 12 +- .../services/provider-subscription.service.ts | 12 +- .../my-projects/my-projects.component.ts | 2 +- .../mappers/preprint-providers.mapper.ts | 4 +- .../preprints/mappers/preprints.mapper.ts | 46 ++-- src/app/features/preprints/models/index.ts | 1 - .../preprint-licenses-json-api.model.ts | 10 +- .../preprint-provider-json-api.model.ts | 69 ++--- .../preprint-request-action-json-api.model.ts | 25 +- .../models/preprint-request-json-api.model.ts | 22 +- .../services/preprint-files.service.ts | 38 +-- .../services/preprint-licenses.service.ts | 14 +- .../services/preprint-providers.service.ts | 12 +- .../services/preprints-projects.service.ts | 36 +-- .../preprints/services/preprints.service.ts | 107 +++----- .../link-resource-dialog.component.spec.ts | 2 +- .../link-resource-dialog.component.ts | 2 +- .../mappers/project-overview.mapper.ts | 13 +- .../overview/models/project-overview.model.ts | 11 - .../services/project-overview.service.ts | 15 +- .../overview/store/project-overview.state.ts | 4 +- .../project-addons.component.html | 2 +- .../services/registrations.service.ts | 11 +- .../settings/mappers/settings.mapper.ts | 4 +- .../models/project-settings-response.model.ts | 34 +-- .../settings/services/settings.service.ts | 12 +- .../features/project/wiki/wiki.component.ts | 2 +- .../registries/services/registries.service.ts | 53 ++-- .../resource-type-options.constant.ts | 2 +- .../registry/mappers/linked-nodes.mapper.ts | 9 +- src/app/features/registry/models/index.ts | 2 - .../models/linked-nodes-json-api.model.ts | 31 --- .../registry/models/linked-nodes.model.ts | 2 - .../linked-registrations-json-api.model.ts | 29 +- .../registry/models/linked-response.model.ts | 27 -- .../registration-overview-json-api.model.ts | 48 ++-- .../registry-components-json-api.model.ts | 27 +- .../models/registry-overview.model.ts | 12 +- .../add-resource-response-json-api.model.ts | 16 -- .../get-registry-resources-json-api.model.ts | 4 - .../registry/models/resources/index.ts | 3 +- .../resource-response-json-api.model.ts | 15 + .../registry-wiki/registry-wiki.component.ts | 2 +- .../services/registry-components.service.ts | 13 +- .../services/registry-links.service.ts | 32 ++- .../services/registry-overview.service.ts | 6 +- .../registry-components.state.ts | 2 +- .../registry-links/registry-links.model.ts | 14 +- .../registry-links/registry-links.state.ts | 4 +- .../mappers/external-identities.mapper.ts | 8 +- ...ccount-settings-response-json-api.model.ts | 13 +- .../list-identities-response.model.ts | 12 +- .../mappers/developer-app.mapper.ts | 4 +- .../models/developer-app-json-api.model.ts | 50 ++-- .../services/developer-apps.service.ts | 19 +- .../notification-subscription.service.ts | 10 +- .../settings/tokens/mappers/scope.mapper.ts | 4 +- .../settings/tokens/mappers/token.mapper.ts | 4 +- .../tokens/models/scope-json-api.model.ts | 15 +- .../tokens/models/token-json-api.model.ts | 26 +- .../tokens/services/tokens.service.spec.ts | 47 +++- .../tokens/services/tokens.service.ts | 20 +- .../metadata-tabs/metadata-tabs.component.ts | 4 +- .../my-projects-table.component.spec.ts | 2 +- .../my-projects-table.component.ts | 2 +- .../recent-activity-list.component.ts | 4 +- .../wiki-list/wiki-list.component.spec.ts | 2 +- .../wiki/wiki-list/wiki-list.component.ts | 2 +- src/app/shared/enums/wiki-modes.enum.ts | 5 + .../wiki-type.enum.ts} | 0 .../shared/mappers/activity-logs.mapper.ts | 60 ++-- src/app/shared/mappers/citations.mapper.ts | 8 +- .../mappers/collections/collections.mapper.ts | 29 +- .../contributors/contributors.mapper.ts | 26 +- .../institutions/institutions.mapper.ts | 8 +- src/app/shared/mappers/my-resources.mapper.ts | 3 +- .../shared/mappers/nodes/base-node.mapper.ts | 15 +- .../registration/registration.mapper.ts | 2 +- .../shared/mappers/view-only-links.mapper.ts | 7 +- src/app/shared/mappers/wiki/wiki.mapper.ts | 32 +-- .../activity-log-with-display.model.ts | 4 +- .../activity-logs-json-api.model.ts | 207 +++++++------- .../activity-logs/activity-logs.model.ts | 133 ++++++--- .../models/addons/addon-json-api.model.ts | 6 + .../shared/models/banner.json-api.model.ts | 40 +-- .../models/brand/brand.json-api.model.ts | 24 +- .../citation-style-json-api.model.ts | 22 +- .../custom-citation-payload-json-api.model.ts | 15 +- .../styled-citation-json-api.model.ts | 15 +- .../collections/collections-json-api.model.ts | 205 +++++++------- .../shared/models/common/json-api.model.ts | 49 ---- .../models/common/json-api/embeds.model.ts | 9 + .../models/common/json-api/links.model.ts | 31 +++ .../models/common/json-api/meta.model.ts | 11 + .../common/json-api/relationships.model.ts | 25 ++ .../models/common/json-api/resource.model.ts | 10 + .../models/common/json-api/responses.model.ts | 22 ++ .../contributor-add-request.model.ts | 23 ++ .../contributor-response-json-api.model.ts | 79 +----- .../emails/account-emails-json-api.model.ts | 19 +- .../files/file-folder-json-api.model.ts | 46 +--- .../models/files/file-json-api.model.ts | 76 ++---- .../files/file-version-json-api.model.ts | 20 +- .../models/guid-response-json-api.model.ts | 42 ++- .../identifiers/identifier-json-api.model.ts | 10 +- .../institution-json-api.model.ts | 69 ++--- .../models/license/licenses-json-api.model.ts | 20 +- .../my-resources/my-resources-item.model.ts | 11 + .../my-resources-json-api.model.ts | 22 ++ .../models/my-resources/my-resources.model.ts | 33 --- .../node-links/node-link-json-api.model.ts | 19 +- .../base-node-attributes-json-api.model.ts | 9 +- .../nodes/base-node-data-json-api.model.ts | 5 +- .../nodes/base-node-embeds-json-api.model.ts | 81 +----- .../nodes/base-node-links-json-api.model.ts | 5 - .../base-node-relationships-json-api.model.ts | 80 +++--- .../nodes/node-preprint-json-api.model.ts | 15 +- .../nodes/node-storage-json-api.model.ts | 19 +- .../models/nodes/nodes-json-api.model.ts | 32 +-- ...otification-subscription-json-api.model.ts | 28 +- .../preprints}/preprint-json-api.model.ts | 99 +++---- .../preprints-provider-json-api.model.ts | 2 +- .../provider/providers-json-api.model.ts | 11 +- .../registration-provider-json-api.model.ts | 32 ++- .../models/regions/regions.json-api.model.ts | 18 +- .../registration-json-api.model.ts | 256 ++++++------------ .../registration-node-json-api.model.ts | 14 +- .../registration/registration-node.model.ts | 9 - .../schema-blocks-json-api.model.ts | 11 +- .../schema-response-json-api.model.ts | 46 ++++ .../request-access-json-api.model.ts | 20 +- .../shared/models/resource-metadata.model.ts | 18 +- .../review-action-payload-json-api.model.ts | 31 ++- .../search/filter-options-json-api.model.ts | 23 +- .../index-card-search-json-api.model.ts | 45 +-- .../models/subject/subjects-json-api.model.ts | 57 +--- .../user-related-counts-json-api.model.ts | 58 ++-- .../shared/models/user/user-json-api.model.ts | 27 +- .../view-only-link-response.model.ts | 37 +-- .../shared/models/wiki/wiki-json-api.model.ts | 36 +++ src/app/shared/models/wiki/wiki-menu.model.ts | 2 +- src/app/shared/models/wiki/wiki.model.ts | 84 ------ .../activity-log-display.service.ts | 6 +- .../activity-log-formatter.service.ts | 50 ++-- .../activity-log-url-builder.service.ts | 26 +- .../activity-logs/activity-logs.service.ts | 11 +- .../shared/services/addons/addons.service.ts | 2 +- src/app/shared/services/banners.service.ts | 5 +- src/app/shared/services/bookmarks.service.ts | 11 +- src/app/shared/services/citations.service.ts | 15 +- .../shared/services/collections.service.ts | 56 ++-- .../shared/services/contributors.service.ts | 5 +- .../datacite/datacite.service.spec.ts | 3 - src/app/shared/services/files.service.ts | 50 ++-- .../shared/services/institutions.service.ts | 3 +- src/app/shared/services/json-api.service.ts | 2 +- src/app/shared/services/metadata.service.ts | 19 +- .../shared/services/my-resources.service.ts | 26 +- src/app/shared/services/node-links.service.ts | 12 +- .../services/registration-provider.service.ts | 7 +- src/app/shared/services/resource.service.ts | 19 +- src/app/shared/services/wiki.service.ts | 91 +++---- .../activity-logs/activity-logs.model.ts | 4 +- .../activity-logs/activity-logs.selectors.ts | 4 +- .../stores/bookmarks/bookmarks.model.ts | 2 +- .../stores/my-resources/my-resources.model.ts | 2 +- .../my-resources/my-resources.selectors.ts | 2 +- .../stores/my-resources/my-resources.state.ts | 6 +- .../stores/node-links/node-links.actions.ts | 2 +- src/app/shared/stores/wiki/wiki.actions.ts | 2 +- src/app/shared/stores/wiki/wiki.state.ts | 4 +- src/testing/data/dashboard/dasboard.data.ts | 72 ----- .../mocks/activity-log-with-display.mock.ts | 8 +- src/testing/mocks/admin-institutions.mock.ts | 4 +- ...ar-metadata-data-template-json-api.mock.ts | 5 +- .../mocks/cedar-metadata-record.mock.ts | 15 +- src/testing/mocks/linked-node.mock.ts | 2 - src/testing/mocks/my-resources.mock.ts | 2 +- src/testing/mocks/project-overview.mock.ts | 3 - .../activity-log-display.service.mock.ts | 4 +- 232 files changed, 2376 insertions(+), 3152 deletions(-) create mode 100644 src/app/features/files/models/file-metadata-response.model.ts create mode 100644 src/app/features/files/models/file-revisions-response.model.ts delete mode 100644 src/app/features/files/models/get-custom-metadata-response.model.ts delete mode 100644 src/app/features/files/models/get-file-metadata-response.model.ts delete mode 100644 src/app/features/files/models/get-file-revisions-response.model.ts delete mode 100644 src/app/features/files/models/get-resource-custom-metadata-response.model.ts delete mode 100644 src/app/features/files/models/get-resource-short-info-response.model.ts delete mode 100644 src/app/features/files/models/get-short-info-response.model.ts create mode 100644 src/app/features/files/models/node-short-info-response.model.ts create mode 100644 src/app/features/files/models/resource-custom-metadata-response.model.ts delete mode 100644 src/app/features/registry/models/linked-nodes-json-api.model.ts delete mode 100644 src/app/features/registry/models/linked-response.model.ts delete mode 100644 src/app/features/registry/models/resources/add-resource-response-json-api.model.ts delete mode 100644 src/app/features/registry/models/resources/get-registry-resources-json-api.model.ts create mode 100644 src/app/features/registry/models/resources/resource-response-json-api.model.ts create mode 100644 src/app/shared/enums/wiki-modes.enum.ts rename src/app/shared/{models/wiki/wiki-type.model.ts => enums/wiki-type.enum.ts} (100%) delete mode 100644 src/app/shared/models/common/json-api.model.ts create mode 100644 src/app/shared/models/common/json-api/embeds.model.ts create mode 100644 src/app/shared/models/common/json-api/links.model.ts create mode 100644 src/app/shared/models/common/json-api/meta.model.ts create mode 100644 src/app/shared/models/common/json-api/relationships.model.ts create mode 100644 src/app/shared/models/common/json-api/resource.model.ts create mode 100644 src/app/shared/models/common/json-api/responses.model.ts create mode 100644 src/app/shared/models/contributors/contributor-add-request.model.ts create mode 100644 src/app/shared/models/my-resources/my-resources-item.model.ts create mode 100644 src/app/shared/models/my-resources/my-resources-json-api.model.ts delete mode 100644 src/app/shared/models/my-resources/my-resources.model.ts delete mode 100644 src/app/shared/models/nodes/base-node-links-json-api.model.ts rename src/app/{features/preprints/models => shared/models/preprints}/preprint-json-api.model.ts (54%) create mode 100644 src/app/shared/models/registration/schema-response-json-api.model.ts create mode 100644 src/app/shared/models/wiki/wiki-json-api.model.ts delete mode 100644 src/testing/data/dashboard/dasboard.data.ts diff --git a/src/app/features/admin-institutions/mappers/institution-departments.mapper.ts b/src/app/features/admin-institutions/mappers/institution-departments.mapper.ts index 22b0f07df..aced15a9c 100644 --- a/src/app/features/admin-institutions/mappers/institution-departments.mapper.ts +++ b/src/app/features/admin-institutions/mappers/institution-departments.mapper.ts @@ -1,15 +1,10 @@ -import { - InstitutionDepartment, - InstitutionDepartmentDataJsonApi, - InstitutionDepartmentsJsonApi, -} from '@osf/features/admin-institutions/models'; +import { InstitutionDepartment, InstitutionDepartmentDataJsonApi, InstitutionDepartmentsJsonApi } from '../models'; export function mapInstitutionDepartments(jsonApiData: InstitutionDepartmentsJsonApi): InstitutionDepartment[] { return jsonApiData.data.map((department: InstitutionDepartmentDataJsonApi) => ({ id: department.id, name: department.attributes.name, numberOfUsers: department.attributes.number_of_users, - selfLink: department.links.self, })); } @@ -18,6 +13,5 @@ export function mapInstitutionDepartment(department: InstitutionDepartmentDataJs id: department.id, name: department.attributes.name, numberOfUsers: department.attributes.number_of_users, - selfLink: department.links.self, }; } diff --git a/src/app/features/admin-institutions/mappers/institution-users.mapper.ts b/src/app/features/admin-institutions/mappers/institution-users.mapper.ts index 7f9785b2e..d79f8f198 100644 --- a/src/app/features/admin-institutions/mappers/institution-users.mapper.ts +++ b/src/app/features/admin-institutions/mappers/institution-users.mapper.ts @@ -3,7 +3,7 @@ import { InstitutionUser, InstitutionUserDataJsonApi, InstitutionUsersJsonApi } export function mapInstitutionUsers(jsonApiData: InstitutionUsersJsonApi): InstitutionUser[] { return jsonApiData.data.map((user: InstitutionUserDataJsonApi) => ({ id: user.id, - userId: user.relationships.user.data.id, + userId: user.relationships?.user?.data?.id ?? '', userName: user.attributes.user_name, department: user.attributes.department, orcidId: user.attributes.orcid_id, diff --git a/src/app/features/admin-institutions/models/institution-department.model.ts b/src/app/features/admin-institutions/models/institution-department.model.ts index f0341bd1d..9119aa3e6 100644 --- a/src/app/features/admin-institutions/models/institution-department.model.ts +++ b/src/app/features/admin-institutions/models/institution-department.model.ts @@ -2,5 +2,4 @@ export interface InstitutionDepartment { id: string; name: string; numberOfUsers: number; - selfLink: string; } diff --git a/src/app/features/admin-institutions/models/institution-departments-json-api.model.ts b/src/app/features/admin-institutions/models/institution-departments-json-api.model.ts index b44db76b7..cf15fb815 100644 --- a/src/app/features/admin-institutions/models/institution-departments-json-api.model.ts +++ b/src/app/features/admin-institutions/models/institution-departments-json-api.model.ts @@ -1,19 +1,14 @@ -export interface InstitutionDepartmentAttributesJsonApi { - name: string; - number_of_users: number; -} +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ListResponse } from '@osf/shared/models/common/json-api/responses.model'; -export interface InstitutionDepartmentLinksJsonApi { - self: string; -} +export type InstitutionDepartmentsJsonApi = ListResponse; -export interface InstitutionDepartmentDataJsonApi { - id: string; - type: 'institution-departments'; - attributes: InstitutionDepartmentAttributesJsonApi; - links: InstitutionDepartmentLinksJsonApi; -} +export type InstitutionDepartmentDataJsonApi = JsonApiResource< + 'institution-departments', + InstitutionDepartmentAttributesJsonApi +>; -export interface InstitutionDepartmentsJsonApi { - data: InstitutionDepartmentDataJsonApi[]; +interface InstitutionDepartmentAttributesJsonApi { + name: string; + number_of_users: number; } diff --git a/src/app/features/admin-institutions/models/institution-index-value-search-json-api.model.ts b/src/app/features/admin-institutions/models/institution-index-value-search-json-api.model.ts index b76c8e348..41c86c8fe 100644 --- a/src/app/features/admin-institutions/models/institution-index-value-search-json-api.model.ts +++ b/src/app/features/admin-institutions/models/institution-index-value-search-json-api.model.ts @@ -1,4 +1,4 @@ -import { JsonApiResponse } from '@shared/models/common/json-api.model'; +import { JsonApiResponse } from '@osf/shared/models/common/json-api/responses.model'; export interface InstitutionSearchResultCountJsonApi { attributes: { diff --git a/src/app/features/admin-institutions/models/institution-summary-metrics-json-api.model.ts b/src/app/features/admin-institutions/models/institution-summary-metrics-json-api.model.ts index c418e98ac..77a62bad9 100644 --- a/src/app/features/admin-institutions/models/institution-summary-metrics-json-api.model.ts +++ b/src/app/features/admin-institutions/models/institution-summary-metrics-json-api.model.ts @@ -1,3 +1,13 @@ +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ItemResponse } from '@osf/shared/models/common/json-api/responses.model'; + +export type InstitutionSummaryMetricsJsonApi = ItemResponse; + +export type InstitutionSummaryMetricsDataJsonApi = JsonApiResource< + 'institution-summary-metrics', + InstitutionSummaryMetricsAttributesJsonApi +>; + export interface InstitutionSummaryMetricsAttributesJsonApi { report_yearmonth: string; user_count: number; @@ -11,36 +21,3 @@ export interface InstitutionSummaryMetricsAttributesJsonApi { monthly_logged_in_user_count: number; monthly_active_user_count: number; } - -export interface InstitutionSummaryMetricsRelationshipsJsonApi { - user: { - data: null; - }; - institution: { - links: { - related: { - href: string; - meta: Record; - }; - }; - data: { - id: string; - type: 'institutions'; - }; - }; -} - -export interface InstitutionSummaryMetricsDataJsonApi { - id: string; - type: 'institution-summary-metrics'; - attributes: InstitutionSummaryMetricsAttributesJsonApi; - relationships: InstitutionSummaryMetricsRelationshipsJsonApi; - links: Record; -} - -export interface InstitutionSummaryMetricsJsonApi { - data: InstitutionSummaryMetricsDataJsonApi; - meta: { - version: string; - }; -} diff --git a/src/app/features/admin-institutions/models/institution-users-json-api.model.ts b/src/app/features/admin-institutions/models/institution-users-json-api.model.ts index dd07ec1eb..b35559cee 100644 --- a/src/app/features/admin-institutions/models/institution-users-json-api.model.ts +++ b/src/app/features/admin-institutions/models/institution-users-json-api.model.ts @@ -1,6 +1,17 @@ -import { MetaJsonApi } from '@osf/shared/models/common/json-api.model'; +import { ToOneRel } from '@osf/shared/models/common/json-api/relationships.model'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ListResponse } from '@osf/shared/models/common/json-api/responses.model'; -export interface InstitutionUserAttributesJsonApi { +export type InstitutionUsersJsonApi = ListResponse; + +export interface InstitutionUserDataJsonApi extends JsonApiResource< + 'institution-users', + InstitutionUserAttributesJsonApi +> { + relationships: InstitutionUserRelationshipsJsonApi; +} + +interface InstitutionUserAttributesJsonApi { user_name: string; department: string | null; orcid_id: string | null; @@ -18,29 +29,7 @@ export interface InstitutionUserAttributesJsonApi { storage_byte_count: number; } -export interface InstitutionUserRelationshipDataJsonApi { - id: string; - type: string; -} - -export interface InstitutionUserRelationshipJsonApi { - data: InstitutionUserRelationshipDataJsonApi; -} - -export interface InstitutionUserRelationshipsJsonApi { - user: InstitutionUserRelationshipJsonApi; - institution: InstitutionUserRelationshipJsonApi; -} - -export interface InstitutionUserDataJsonApi { - id: string; - type: 'institution-users'; - attributes: InstitutionUserAttributesJsonApi; - relationships: InstitutionUserRelationshipsJsonApi; - links: Record; -} - -export interface InstitutionUsersJsonApi { - data: InstitutionUserDataJsonApi[]; - meta: MetaJsonApi; +interface InstitutionUserRelationshipsJsonApi { + user: ToOneRel<'user'>; + institution: ToOneRel<'institution'>; } diff --git a/src/app/features/admin-institutions/models/send-message-json-api.model.ts b/src/app/features/admin-institutions/models/send-message-json-api.model.ts index e561865da..70d03b304 100644 --- a/src/app/features/admin-institutions/models/send-message-json-api.model.ts +++ b/src/app/features/admin-institutions/models/send-message-json-api.model.ts @@ -1,12 +1,13 @@ -export interface SendMessageResponseJsonApi { - data: { - id: string; - type: string; - attributes: { - message_text: string; - message_type: string; - bcc_sender: boolean; - reply_to: boolean; - }; - }; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ItemResponse } from '@osf/shared/models/common/json-api/responses.model'; + +export type SendMessageResponseJsonApi = ItemResponse; + +export type SendMessageDataJsonApi = JsonApiResource<'send-message', SendMessageAttributesJsonApi>; + +interface SendMessageAttributesJsonApi { + message_text: string; + message_type: string; + bcc_sender: boolean; + reply_to: boolean; } diff --git a/src/app/features/analytics/mappers/related-counts.mapper.ts b/src/app/features/analytics/mappers/related-counts.mapper.ts index 89ba90f4f..caef745eb 100644 --- a/src/app/features/analytics/mappers/related-counts.mapper.ts +++ b/src/app/features/analytics/mappers/related-counts.mapper.ts @@ -1,13 +1,13 @@ -import { RelatedCountsGetResponse, RelatedCountsModel } from '../models'; +import { RelatedCountsModel, RelatedCountsResponseJsonApi } from '../models'; export class RelatedCountsMapper { - static fromResponse(response: RelatedCountsGetResponse): RelatedCountsModel { + static fromResponse(response: RelatedCountsResponseJsonApi): RelatedCountsModel { return { id: response.data.id, isPublic: response.data.attributes.public, - forksCount: response.data.relationships.forks?.links.related.meta.count || 0, - linksToCount: response.data.relationships.linked_by_nodes?.links.related.meta.count || 0, - templateCount: response.meta.templated_by_count || 0, + forksCount: response.data.relationships.forks?.links?.related?.meta?.count ?? 0, + linksToCount: response.data.relationships.linked_by_nodes?.links?.related?.meta?.count ?? 0, + templateCount: response.meta?.templated_by_count ?? 0, }; } } diff --git a/src/app/features/analytics/models/node-analytics-json-api.model.ts b/src/app/features/analytics/models/node-analytics-json-api.model.ts index e06297531..6fdf9f7be 100644 --- a/src/app/features/analytics/models/node-analytics-json-api.model.ts +++ b/src/app/features/analytics/models/node-analytics-json-api.model.ts @@ -1,33 +1,30 @@ -import { ResponseDataJsonApi } from '@osf/shared/models/common/json-api.model'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ItemResponse } from '@osf/shared/models/common/json-api/responses.model'; -export type NodeAnalyticsResponseJsonApi = ResponseDataJsonApi; +export type NodeAnalyticsResponseJsonApi = ItemResponse; -export interface NodeAnalyticsDataJsonApi { - id: string; - type: 'node-analytics'; - attributes: NodeAnalyticsAttributesJsonApi; -} +export type NodeAnalyticsDataJsonApi = JsonApiResource<'node-analytics', NodeAnalyticsAttributesJsonApi>; -export interface NodeAnalyticsAttributesJsonApi { +interface NodeAnalyticsAttributesJsonApi { popular_pages: PopularPageJsonApi[]; unique_visits: UniqueVisitJsonApi[]; time_of_day: TimeOfDayJsonApi[]; referer_domain: RefererDomainJsonApi[]; } -export interface PopularPageJsonApi { +interface PopularPageJsonApi { path: string; route: string; title: string; count: number; } -export interface UniqueVisitJsonApi { +interface UniqueVisitJsonApi { date: string; count: number; } -export interface TimeOfDayJsonApi { +interface TimeOfDayJsonApi { hour: number; count: number; } diff --git a/src/app/features/analytics/models/related-counts-json-api.model.ts b/src/app/features/analytics/models/related-counts-json-api.model.ts index f51b9acf4..2914a1545 100644 --- a/src/app/features/analytics/models/related-counts-json-api.model.ts +++ b/src/app/features/analytics/models/related-counts-json-api.model.ts @@ -1,39 +1,21 @@ -export interface RelatedCountsGetResponse { - data: RelatedCountsDataResponse; - meta: MetaGetResponse; -} - -interface MetaGetResponse { - templated_by_count: number; -} - -interface RelatedCountsDataResponse { - id: string; - attributes: RelatedCountsAttributes; - relationships: RelationshipsResponse; -} +import { RelatedCountRel } from '@osf/shared/models/common/json-api/relationships.model'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ItemResponse } from '@osf/shared/models/common/json-api/responses.model'; +import { BaseNodeAttributesJsonApi } from '@osf/shared/models/nodes/base-node-attributes-json-api.model'; -interface RelatedCountsAttributes { - public: boolean; -} - -interface RelationshipsResponse { - forks: Relationship; - linked_by_nodes: Relationship; -} +export type RelatedCountsResponseJsonApi = ItemResponse & { + meta: RelatedCountsResponseMetaJsonApi; +}; -interface Relationship { - links: Links; +interface RelatedCountsDataJsonApi extends JsonApiResource<'related-counts', BaseNodeAttributesJsonApi> { + relationships: RelatedCountsRelationshipsJsonApi; } -interface Links { - related: RelatedLink; +interface RelatedCountsRelationshipsJsonApi { + forks?: RelatedCountRel; + linked_by_nodes?: RelatedCountRel; } -interface RelatedLink { - meta: MetaCount; -} - -interface MetaCount { - count: number; +interface RelatedCountsResponseMetaJsonApi { + templated_by_count: number; } diff --git a/src/app/features/analytics/services/resource-analytics.service.ts b/src/app/features/analytics/services/resource-analytics.service.ts index 96a7e1bf6..019de928c 100644 --- a/src/app/features/analytics/services/resource-analytics.service.ts +++ b/src/app/features/analytics/services/resource-analytics.service.ts @@ -7,7 +7,7 @@ import { AnalyticsMetricsMapper, RelatedCountsMapper } from '@osf/features/analy import { NodeAnalyticsModel, NodeAnalyticsResponseJsonApi, - RelatedCountsGetResponse, + RelatedCountsResponseJsonApi, } from '@osf/features/analytics/models'; import { ResourceType } from '@osf/shared/enums/resource-type.enum'; import { JsonApiService } from '@osf/shared/services/json-api.service'; @@ -41,7 +41,7 @@ export class ResourceAnalyticsService { const url = `${this.apiDomainUrl}/v2/${resourcePath}/${resourceId}/?related_counts=true`; return this.jsonApiService - .get(url) + .get(url) .pipe(map((response) => RelatedCountsMapper.fromResponse(response))); } } diff --git a/src/app/features/files/mappers/file-custom-metadata.mapper.ts b/src/app/features/files/mappers/file-custom-metadata.mapper.ts index 3af893193..c7430b9d0 100644 --- a/src/app/features/files/mappers/file-custom-metadata.mapper.ts +++ b/src/app/features/files/mappers/file-custom-metadata.mapper.ts @@ -1,9 +1,8 @@ -import { ApiData } from '@osf/shared/models/common/json-api.model'; import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; -import { FileCustomMetadata, OsfFileCustomMetadata } from '../models'; +import { FileCustomMetadataDataJsonApi, OsfFileCustomMetadata } from '../models'; -export function MapFileCustomMetadata(data: ApiData): OsfFileCustomMetadata { +export function MapFileCustomMetadata(data: FileCustomMetadataDataJsonApi): OsfFileCustomMetadata { return { id: data.id, description: replaceBadEncodedChars(data.attributes.description), diff --git a/src/app/features/files/mappers/file-revision.mapper.ts b/src/app/features/files/mappers/file-revision.mapper.ts index 19046d20f..4b93e40d0 100644 --- a/src/app/features/files/mappers/file-revision.mapper.ts +++ b/src/app/features/files/mappers/file-revision.mapper.ts @@ -1,13 +1,10 @@ -import { ApiData } from '@osf/shared/models/common/json-api.model'; +import { FileRevisionDataJsonApi, OsfFileRevision } from '../models'; -import { FileRevisionJsonApi, OsfFileRevision } from '../models'; - -export function MapFileRevision(data: ApiData[]): OsfFileRevision[] { - const revision = data.map((revision) => ({ +export function MapFileRevision(data: FileRevisionDataJsonApi[]): OsfFileRevision[] { + return data.map((revision) => ({ downloads: revision.attributes.extra.downloads, hashes: { md5: revision.attributes.extra.hashes?.md5, sha256: revision.attributes.extra.hashes?.sha256 }, dateTime: new Date(revision.attributes.modified_utc), version: revision.attributes.version, })); - return revision; } diff --git a/src/app/features/files/mappers/resource-metadata.mapper.ts b/src/app/features/files/mappers/resource-metadata.mapper.ts index 5fc0e6fc0..827c3e92b 100644 --- a/src/app/features/files/mappers/resource-metadata.mapper.ts +++ b/src/app/features/files/mappers/resource-metadata.mapper.ts @@ -2,12 +2,12 @@ import { IdentifiersMapper } from '@osf/shared/mappers/identifiers.mapper'; import { ResourceMetadata } from '@osf/shared/models/resource-metadata.model'; import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; -import { GetResourceCustomMetadataResponse } from '../models/get-resource-custom-metadata-response.model'; -import { GetResourceShortInfoResponse } from '../models/get-resource-short-info-response.model'; +import { NodeShortInfoResponse } from '../models/node-short-info-response.model'; +import { ResourceCustomMetadataResponse } from '../models/resource-custom-metadata-response.model'; export function MapResourceMetadata( - shortInfo: GetResourceShortInfoResponse, - customMetadata: GetResourceCustomMetadataResponse + shortInfo: NodeShortInfoResponse, + customMetadata: ResourceCustomMetadataResponse ): ResourceMetadata { return { title: replaceBadEncodedChars(shortInfo.data.attributes.title), diff --git a/src/app/features/files/models/file-metadata-response.model.ts b/src/app/features/files/models/file-metadata-response.model.ts new file mode 100644 index 000000000..925861218 --- /dev/null +++ b/src/app/features/files/models/file-metadata-response.model.ts @@ -0,0 +1,16 @@ +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ItemResponse } from '@osf/shared/models/common/json-api/responses.model'; + +export type FileMetadataResponse = ItemResponse; + +export type FileCustomMetadataDataJsonApi = JsonApiResource< + 'custom_file_metadata_records', + FileCustomMetadataAttributesJsonApi +>; + +interface FileCustomMetadataAttributesJsonApi { + description: string; + language: string; + resource_type_general: string; + title: string; +} diff --git a/src/app/features/files/models/file-revisions-response.model.ts b/src/app/features/files/models/file-revisions-response.model.ts new file mode 100644 index 000000000..0ee38dddd --- /dev/null +++ b/src/app/features/files/models/file-revisions-response.model.ts @@ -0,0 +1,23 @@ +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { DataResponse } from '@osf/shared/models/common/json-api/responses.model'; + +export type FileRevisionsResponse = DataResponse; + +export type FileRevisionDataJsonApi = JsonApiResource; + +interface FileRevisionAttributesJsonApi { + extra: FileRevisionExtraJsonApi; + modified: string; + modified_utc: string; + version: string; +} + +interface FileRevisionExtraJsonApi { + downloads: number; + hashes: FileRevisionHashesJsonApi; +} + +interface FileRevisionHashesJsonApi { + md5: string; + sha256: string; +} diff --git a/src/app/features/files/models/file-revisions.model.ts b/src/app/features/files/models/file-revisions.model.ts index 84148c1d7..9bb41e509 100644 --- a/src/app/features/files/models/file-revisions.model.ts +++ b/src/app/features/files/models/file-revisions.model.ts @@ -1,5 +1,5 @@ export interface OsfFileRevision { - downloads: 0; + downloads: number; hashes: { md5: string; sha256: string; diff --git a/src/app/features/files/models/get-custom-metadata-response.model.ts b/src/app/features/files/models/get-custom-metadata-response.model.ts deleted file mode 100644 index 4420eff6e..000000000 --- a/src/app/features/files/models/get-custom-metadata-response.model.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { ApiData, JsonApiResponse } from '@osf/shared/models/common/json-api.model'; - -export type GetCustomMetadataResponse = JsonApiResponse, null>; - -export interface MetadataEmbedResponse { - custom_metadata: JsonApiResponse< - ApiData< - { - language: string; - resource_type_general: string; - funders: { - funder_name: string; - funder_identifier: string; - funder_identifier_type: string; - award_number: string; - award_uri: string; - award_title: string; - }[]; - }, - null, - null, - null - >, - null - >; -} diff --git a/src/app/features/files/models/get-file-metadata-response.model.ts b/src/app/features/files/models/get-file-metadata-response.model.ts deleted file mode 100644 index 7f0662855..000000000 --- a/src/app/features/files/models/get-file-metadata-response.model.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { ApiData, JsonApiResponse } from '@osf/shared/models/common/json-api.model'; - -export type GetFileMetadataResponse = JsonApiResponse, null>; - -export interface FileCustomMetadata { - language: string; - resource_type_general: string; - title: string; - description: string; -} diff --git a/src/app/features/files/models/get-file-revisions-response.model.ts b/src/app/features/files/models/get-file-revisions-response.model.ts deleted file mode 100644 index 1491314c3..000000000 --- a/src/app/features/files/models/get-file-revisions-response.model.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { ApiData, JsonApiResponse } from '@osf/shared/models/common/json-api.model'; - -export interface FileRevisionJsonApi { - extra: { - downloads: 0; - hashes: { - md5: string; - sha256: string; - }; - }; - version: string; - modified: string; - modified_utc: string; -} - -export type GetFileRevisionsResponse = JsonApiResponse[], null>; diff --git a/src/app/features/files/models/get-resource-custom-metadata-response.model.ts b/src/app/features/files/models/get-resource-custom-metadata-response.model.ts deleted file mode 100644 index 10e121cfa..000000000 --- a/src/app/features/files/models/get-resource-custom-metadata-response.model.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { ApiData, JsonApiResponse } from '@osf/shared/models/common/json-api.model'; - -export type GetResourceCustomMetadataResponse = JsonApiResponse< - ApiData, - null ->; - -export interface ResourceMetadataEmbedResponse { - custom_metadata: JsonApiResponse< - ApiData< - { - language: string; - resource_type_general: string; - funders: { - funder_name: string; - funder_identifier: string; - funder_identifier_type: string; - award_number: string; - award_uri: string; - award_title: string; - }[]; - }, - null, - null, - null - >, - null - >; -} diff --git a/src/app/features/files/models/get-resource-short-info-response.model.ts b/src/app/features/files/models/get-resource-short-info-response.model.ts deleted file mode 100644 index 831a33f76..000000000 --- a/src/app/features/files/models/get-resource-short-info-response.model.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { ApiData, JsonApiResponse } from '@osf/shared/models/common/json-api.model'; -import { IdentifiersResponseJsonApi } from '@osf/shared/models/identifiers/identifier-json-api.model'; - -export type GetResourceShortInfoResponse = JsonApiResponse< - ApiData< - { - title: string; - description: string; - date_created: string; - date_modified: string; - }, - { identifiers: IdentifiersResponseJsonApi }, - null, - null - >, - null ->; diff --git a/src/app/features/files/models/get-short-info-response.model.ts b/src/app/features/files/models/get-short-info-response.model.ts deleted file mode 100644 index 2fd10f273..000000000 --- a/src/app/features/files/models/get-short-info-response.model.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { ApiData, JsonApiResponse } from '@osf/shared/models/common/json-api.model'; -import { IdentifiersResponseJsonApi } from '@osf/shared/models/identifiers/identifier-json-api.model'; - -export type GetShortInfoResponse = JsonApiResponse< - ApiData< - { - title: string; - description: string; - date_created: string; - date_modified: string; - }, - { identifiers: IdentifiersResponseJsonApi }, - null, - null - >, - null ->; diff --git a/src/app/features/files/models/index.ts b/src/app/features/files/models/index.ts index 29d50dfc6..128cca939 100644 --- a/src/app/features/files/models/index.ts +++ b/src/app/features/files/models/index.ts @@ -1,9 +1,8 @@ export * from './file-custom-metadata.model'; +export * from './file-metadata-response.model'; export * from './file-revisions.model'; +export * from './file-revisions-response.model'; export * from './files-metadata-fields.model'; -export * from './get-custom-metadata-response.model'; -export * from './get-file-metadata-response.model'; -export * from './get-file-revisions-response.model'; -export * from './get-short-info-response.model'; export * from './info-item.model'; +export * from './node-short-info-response.model'; export * from './patch-file-metadata.model'; diff --git a/src/app/features/files/models/node-short-info-response.model.ts b/src/app/features/files/models/node-short-info-response.model.ts new file mode 100644 index 000000000..13a248d8e --- /dev/null +++ b/src/app/features/files/models/node-short-info-response.model.ts @@ -0,0 +1,20 @@ +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ItemResponse } from '@osf/shared/models/common/json-api/responses.model'; +import { IdentifiersResponseJsonApi } from '@osf/shared/models/identifiers/identifier-json-api.model'; + +export type NodeShortInfoResponse = ItemResponse; + +export interface NodeShortInfoDataJsonApi extends JsonApiResource { + embeds?: NodeShortInfoEmbedsJsonApi; +} + +interface NodeShortInfoAttributesJsonApi { + date_created: string; + date_modified: string; + description: string; + title: string; +} + +interface NodeShortInfoEmbedsJsonApi { + identifiers: IdentifiersResponseJsonApi; +} diff --git a/src/app/features/files/models/resource-custom-metadata-response.model.ts b/src/app/features/files/models/resource-custom-metadata-response.model.ts new file mode 100644 index 000000000..debe5a66b --- /dev/null +++ b/src/app/features/files/models/resource-custom-metadata-response.model.ts @@ -0,0 +1,30 @@ +import { Embed } from '@osf/shared/models/common/json-api/embeds.model'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ItemResponse } from '@osf/shared/models/common/json-api/responses.model'; + +export type ResourceCustomMetadataResponse = ItemResponse; + +export interface ResourceCustomMetadataGuidDataJsonApi extends JsonApiResource<'guids', Record> { + embeds: ResourceCustomMetadataEmbedsJsonApi; +} + +interface ResourceCustomMetadataEmbedsJsonApi { + custom_metadata: Embed; +} + +type CustomMetadataDataJsonApi = JsonApiResource<'custom-metadata-records', CustomMetadataAttributesJsonApi>; + +interface CustomMetadataAttributesJsonApi { + funders: CustomMetadataFunderJsonApi[]; + language: string; + resource_type_general: string; +} + +interface CustomMetadataFunderJsonApi { + award_number: string; + award_title: string; + award_uri: string; + funder_identifier: string; + funder_identifier_type: string; + funder_name: string; +} diff --git a/src/app/features/files/pages/file-detail/file-detail.component.ts b/src/app/features/files/pages/file-detail/file-detail.component.ts index 84f1108e8..c03d88f8a 100644 --- a/src/app/features/files/pages/file-detail/file-detail.component.ts +++ b/src/app/features/files/pages/file-detail/file-detail.component.ts @@ -29,7 +29,7 @@ import { ActivatedRoute, Router, RouterLink } from '@angular/router'; import { ENVIRONMENT } from '@core/provider/environment.provider'; import { CedarMetadataDataTemplateJsonApi, - CedarMetadataRecordData, + CedarMetadataRecordDataJsonApi, CedarRecordDataBinding, } from '@osf/features/metadata/models'; import { @@ -191,7 +191,7 @@ export class FileDetailComponent implements OnInit, OnDestroy { selectedMetadataTab = signal('osf'); - selectedCedarRecord = signal(null); + selectedCedarRecord = signal(null); selectedCedarTemplate = signal(null); cedarFormReadonly = signal(true); diff --git a/src/app/features/home/pages/dashboard/dashboard.component.ts b/src/app/features/home/pages/dashboard/dashboard.component.ts index f9fa9eb5c..e68b552a5 100644 --- a/src/app/features/home/pages/dashboard/dashboard.component.ts +++ b/src/app/features/home/pages/dashboard/dashboard.component.ts @@ -23,7 +23,7 @@ import { SearchInputComponent } from '@osf/shared/components/search-input/search import { SubHeaderComponent } from '@osf/shared/components/sub-header/sub-header.component'; import { DEFAULT_TABLE_PARAMS } from '@osf/shared/constants/default-table-params.constants'; import { SortOrder } from '@osf/shared/enums/sort-order.enum'; -import { MyResourcesItem } from '@osf/shared/models/my-resources/my-resources.model'; +import { MyResourcesItem } from '@osf/shared/models/my-resources/my-resources-item.model'; import { MyResourcesSearchFilters } from '@osf/shared/models/my-resources/my-resources-search-filters.model'; import { CustomDialogService } from '@osf/shared/services/custom-dialog.service'; import { ProjectRedirectDialogService } from '@osf/shared/services/project-redirect-dialog.service'; diff --git a/src/app/features/meetings/mappers/meetings.mapper.ts b/src/app/features/meetings/mappers/meetings.mapper.ts index f967aa4bb..bd34d187f 100644 --- a/src/app/features/meetings/mappers/meetings.mapper.ts +++ b/src/app/features/meetings/mappers/meetings.mapper.ts @@ -1,15 +1,15 @@ -import { ResponseJsonApi } from '@osf/shared/models/common/json-api.model'; import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { - MeetingGetResponseJsonApi, - MeetingSubmissionGetResponseJsonApi, + MeetingDataJsonApi, + MeetingsListResponseJsonApi, + MeetingSubmissionsListResponseJsonApi, MeetingSubmissionsWithPaging, MeetingsWithPaging, } from '../models'; export class MeetingsMapper { - static fromMeetingsGetResponse(response: ResponseJsonApi): MeetingsWithPaging { + static fromMeetingsGetResponse(response: MeetingsListResponseJsonApi): MeetingsWithPaging { return { data: response.data.map((item) => ({ id: item.id, @@ -24,7 +24,7 @@ export class MeetingsMapper { } static fromMeetingSubmissionGetResponse( - response: ResponseJsonApi + response: MeetingSubmissionsListResponseJsonApi ): MeetingSubmissionsWithPaging { return { data: response.data.map((item) => ({ @@ -40,7 +40,7 @@ export class MeetingsMapper { }; } - static fromMeetingGetResponse(response: MeetingGetResponseJsonApi) { + static fromMeetingGetResponse(response: MeetingDataJsonApi) { return { id: response.id, name: response.attributes.name, diff --git a/src/app/features/meetings/models/meetings-json-api.model.ts b/src/app/features/meetings/models/meetings-json-api.model.ts index b2d77d7e1..c66e38c64 100644 --- a/src/app/features/meetings/models/meetings-json-api.model.ts +++ b/src/app/features/meetings/models/meetings-json-api.model.ts @@ -1,28 +1,36 @@ import { NumberOrNull, StringOrNull } from '@osf/shared/helpers/types.helper'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ItemResponse, ListResponse } from '@osf/shared/models/common/json-api/responses.model'; -export interface MeetingGetResponseJsonApi { - id: string; - type: 'meetings'; - attributes: { - name: string; - location: string; - start_date: Date; - end_date: Date; - submissions_count: number; - }; +export type MeetingsListResponseJsonApi = ListResponse; +export type MeetingSubmissionsListResponseJsonApi = ListResponse; +export type MeetingResponseJsonApi = ItemResponse; + +export type MeetingDataJsonApi = JsonApiResource<'meetings', MeetingAttributesJsonApi>; + +export interface MeetingSubmissionDataJsonApi extends JsonApiResource< + 'meeting-submissions', + MeetingSubmissionAttributesJsonApi +> { + links: MeetingSubmissionLinksJsonApi; +} + +interface MeetingAttributesJsonApi { + end_date: Date; + location: string; + name: string; + start_date: Date; + submissions_count: number; +} + +interface MeetingSubmissionAttributesJsonApi { + author_name: string; + date_created: Date; + download_count: NumberOrNull; + meeting_category: string; + title: string; } -export interface MeetingSubmissionGetResponseJsonApi { - id: string; - type: 'meeting-submissions'; - attributes: { - title: string; - date_created: Date; - author_name: string; - download_count: NumberOrNull; - meeting_category: string; - }; - links: { - download: StringOrNull; - }; +interface MeetingSubmissionLinksJsonApi { + download: StringOrNull; } diff --git a/src/app/features/meetings/services/meetings.service.ts b/src/app/features/meetings/services/meetings.service.ts index d3dc25201..d0f95e029 100644 --- a/src/app/features/meetings/services/meetings.service.ts +++ b/src/app/features/meetings/services/meetings.service.ts @@ -4,15 +4,15 @@ import { inject, Injectable } from '@angular/core'; import { ENVIRONMENT } from '@core/provider/environment.provider'; import { searchPreferencesToJsonApiQueryParams } from '@osf/shared/helpers/search-pref-to-json-api-query-params.helper'; -import { JsonApiResponse, ResponseJsonApi } from '@osf/shared/models/common/json-api.model'; import { SearchFilters } from '@osf/shared/models/search-filters.model'; import { JsonApiService } from '@osf/shared/services/json-api.service'; import { meetingSortFieldMap, meetingSubmissionSortFieldMap } from '../constants'; import { MeetingsMapper } from '../mappers'; import { - MeetingGetResponseJsonApi, - MeetingSubmissionGetResponseJsonApi, + MeetingResponseJsonApi, + MeetingsListResponseJsonApi, + MeetingSubmissionsListResponseJsonApi, MeetingSubmissionsWithPaging, MeetingsWithPaging, } from '../models'; @@ -38,7 +38,7 @@ export class MeetingsService { ); return this.jsonApiService - .get>(this.apiUrl, params) + .get(this.apiUrl, params) .pipe(map((response) => MeetingsMapper.fromMeetingsGetResponse(response))); } @@ -57,13 +57,13 @@ export class MeetingsService { ); return this.jsonApiService - .get>(`${this.apiUrl}${meetingId}/submissions/`, params) + .get(`${this.apiUrl}${meetingId}/submissions/`, params) .pipe(map((response) => MeetingsMapper.fromMeetingSubmissionGetResponse(response))); } getMeetingById(meetingId: string) { return this.jsonApiService - .get>(this.apiUrl + meetingId) + .get(this.apiUrl + meetingId) .pipe(map((response) => MeetingsMapper.fromMeetingGetResponse(response.data))); } } diff --git a/src/app/features/metadata/components/cedar-template-form/cedar-template-form.component.ts b/src/app/features/metadata/components/cedar-template-form/cedar-template-form.component.ts index 032e378f3..6fe9cb4c9 100644 --- a/src/app/features/metadata/components/cedar-template-form/cedar-template-form.component.ts +++ b/src/app/features/metadata/components/cedar-template-form/cedar-template-form.component.ts @@ -29,7 +29,7 @@ import { CedarMetadataHelper } from '../../helpers'; import { CedarEditorElement, CedarMetadataDataTemplateJsonApi, - CedarMetadataRecordData, + CedarMetadataRecordDataJsonApi, CedarRecordDataBinding, } from '../../models'; @@ -48,7 +48,7 @@ export class CedarTemplateFormComponent { toggleEditMode = output(); template = input.required(); - existingRecord = input(null); + existingRecord = input(null); readonly = input(false); showEditButton = input(false); diff --git a/src/app/features/metadata/mappers/metadata.mapper.ts b/src/app/features/metadata/mappers/metadata.mapper.ts index eb6044cb3..8aeeb95d0 100644 --- a/src/app/features/metadata/mappers/metadata.mapper.ts +++ b/src/app/features/metadata/mappers/metadata.mapper.ts @@ -2,10 +2,10 @@ import { IdentifiersMapper } from '@osf/shared/mappers/identifiers.mapper'; import { LicensesMapper } from '@osf/shared/mappers/licenses.mapper'; import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; -import { CustomItemMetadataRecord, CustomMetadataJsonApi, MetadataJsonApi, MetadataModel } from '../models'; +import { CustomItemMetadataRecord, CustomMetadataDataJsonApi, MetadataDataJsonApi, MetadataModel } from '../models'; export class MetadataMapper { - static fromMetadataApiResponse(response: MetadataJsonApi): MetadataModel { + static fromMetadataApiResponse(response: MetadataDataJsonApi): MetadataModel { return { id: response.id, title: replaceBadEncodedChars(response.attributes.title), @@ -14,7 +14,9 @@ export class MetadataMapper { dateCreated: response.attributes.date_created, dateModified: response.attributes.date_modified, publicationDoi: response.attributes.article_doi, - license: LicensesMapper.fromLicenseDataJsonApi(response.embeds?.license?.data), + license: response.embeds?.license?.data + ? LicensesMapper.fromLicenseDataJsonApi(response.embeds?.license?.data) + : null, nodeLicense: response.attributes.node_license ? { copyrightHolders: response.attributes.node_license.copyright_holders || [], @@ -22,14 +24,14 @@ export class MetadataMapper { } : undefined, identifiers: IdentifiersMapper.fromJsonApi(response.embeds?.identifiers), - provider: response.embeds?.provider?.data.id, + provider: response.relationships?.provider?.data?.id, public: response.attributes.public, currentUserPermissions: response.attributes.current_user_permissions, registrationSupplement: response.attributes.registration_supplement, }; } - static fromCustomMetadataApiResponse(response: CustomMetadataJsonApi): Partial { + static fromCustomMetadataApiResponse(response: CustomMetadataDataJsonApi): Partial { return { language: response.attributes.language, resourceTypeGeneral: response.attributes.resource_type_general, diff --git a/src/app/features/metadata/metadata.component.ts b/src/app/features/metadata/metadata.component.ts index ad6f68623..0e685469b 100644 --- a/src/app/features/metadata/metadata.component.ts +++ b/src/app/features/metadata/metadata.component.ts @@ -75,7 +75,7 @@ import { ResourceInformationDialogComponent } from './dialogs/resource-informati import { ResourceInfoTooltipComponent } from './dialogs/resource-tooltip-info/resource-tooltip-info.component'; import { CedarMetadataDataTemplateJsonApi, - CedarMetadataRecordData, + CedarMetadataRecordDataJsonApi, CedarRecordDataBinding, DialogValueModel, } from './models'; @@ -133,7 +133,7 @@ export class MetadataComponent implements OnInit, OnDestroy { tabs = signal([]); selectedTab = signal('osf'); - selectedCedarRecord = signal(null); + selectedCedarRecord = signal(null); selectedCedarTemplate = signal(null); cedarFormReadonly = signal(true); resourceType = signal(this.activeRoute.parent?.snapshot.data['resourceType'] || ResourceType.Project); diff --git a/src/app/features/metadata/models/cedar-metadata-template.model.ts b/src/app/features/metadata/models/cedar-metadata-template.model.ts index e75886006..0ea7a8b97 100644 --- a/src/app/features/metadata/models/cedar-metadata-template.model.ts +++ b/src/app/features/metadata/models/cedar-metadata-template.model.ts @@ -1,66 +1,27 @@ -import { MetaJsonApi, PaginationLinksJsonApi } from '@osf/shared/models/common/json-api.model'; +import { Embed } from '@osf/shared/models/common/json-api/embeds.model'; +import { JsonApiResource, JsonApiResourceRef } from '@osf/shared/models/common/json-api/resource.model'; +import { DataResponse, ListResponse } from '@osf/shared/models/common/json-api/responses.model'; -export interface CedarMetadataDataTemplateJsonApi { +export type CedarMetadataTemplateJsonApi = ListResponse; +export type CedarMetadataRecordJsonApi = ListResponse; +export type CedarMetadataRecord = DataResponse; + +export interface CedarRecordDataBinding { id: string; - type: 'cedar-metadata-templates'; - attributes: { - schema_name: string; - cedar_id: string; - template: CedarTemplate; - }; + data: CedarMetadataAttributes; + isPublished: boolean; } -export interface CedarTemplate { - '@id': string; - '@type': string; - type: string; - title: string; - description: string; - $schema: string; - '@context': CedarTemplateContext; - required: string[]; - properties: Record; - _ui: { - order: string[]; - propertyLabels: Record; - propertyDescriptions: Record; - }; -} +export type CedarMetadataDataTemplateJsonApi = JsonApiResource< + 'cedar-metadata-templates', + CedarMetadataTemplateAttributesJsonApi +>; -export interface CedarTemplateContext { - pav: string; - xsd: string; - bibo: string; - oslc: string; - schema: string; - 'schema:name': { - '@type': string; - }; - 'pav:createdBy': { - '@type': string; - }; - 'pav:createdOn': { - '@type': string; - }; - 'oslc:modifiedBy': { - '@type': string; - }; - 'pav:lastUpdatedOn': { - '@type': string; - }; - 'schema:description': { - '@type': string; - }; -} - -export interface CedarMetadataTemplate { - id: string; - type: 'cedar-metadata-templates'; - attributes: { - schema_name: string; - cedar_id: string; - template: CedarTemplate; - }; +interface CedarMetadataTemplateAttributesJsonApi { + active: boolean; + cedar_id: string; + schema_name: string; + template: CedarTemplate; } export interface CedarTemplate { @@ -68,6 +29,7 @@ export interface CedarTemplate { '@type': string; type: string; title: string; + description: string; $schema: string; '@context': CedarTemplateContext; required: string[]; @@ -79,7 +41,7 @@ export interface CedarTemplate { }; } -export interface CedarTemplateContext { +interface CedarTemplateContext { pav: string; xsd: string; bibo: string; @@ -105,11 +67,6 @@ export interface CedarTemplateContext { }; } -export interface CedarMetadataTemplateJsonApi { - data: CedarMetadataDataTemplateJsonApi[]; - links: PaginationLinksJsonApi; -} - export interface FieldSchema { type?: string; format?: string; @@ -130,13 +87,6 @@ export interface FieldSchema { '@id': string; } -export interface CedarFieldItem extends Record { - '@id'?: string; - '@type'?: string; - 'rdfs:label'?: string | null; - '@value'?: string; -} - export interface CedarMetadataAttributes { '@context': Record; Constructs: CedarFieldItem[]; @@ -182,55 +132,31 @@ export interface CedarMetadataAttributes { }[]; } -export interface CedarMetadataRecord { - data: CedarMetadataRecordData; -} - -export interface CedarRecordDataBinding { - data: CedarMetadataAttributes; - id: string; - isPublished: boolean; -} - -export interface CedarMetadataRecordJsonApi { - data: CedarMetadataRecordData[]; - links: PaginationLinksJsonApi; - meta: MetaJsonApi; +interface CedarFieldItem extends Record { + '@id'?: string; + '@type'?: string; + 'rdfs:label'?: string | null; + '@value'?: string; } -export interface CedarMetadataRecordData { +export interface CedarMetadataRecordDataJsonApi { id?: string; + type?: string; attributes: CedarMetadataRecordAttributes; embeds?: { - template: { - data: { - attributes: { - active: boolean; - cedar_id: string; - schema_name: string; - }; - id: string; - }; - }; + template: Embed; }; relationships: { template: { - data: { - type: string; - id: string; - }; + data: JsonApiResourceRef; }; target: { - data: { - type: string; - id: string; - }; + data: JsonApiResourceRef; }; }; - type?: string; } -export interface CedarMetadataRecordAttributes { +interface CedarMetadataRecordAttributes { metadata: CedarMetadataAttributes; is_published: boolean; } diff --git a/src/app/features/metadata/models/metadata-json-api.model.ts b/src/app/features/metadata/models/metadata-json-api.model.ts index 802777461..ce91803fb 100644 --- a/src/app/features/metadata/models/metadata-json-api.model.ts +++ b/src/app/features/metadata/models/metadata-json-api.model.ts @@ -1,58 +1,59 @@ +import { ToOneRel } from '@osf/shared/models/common/json-api/relationships.model'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; import { UserPermissions } from '@shared/enums/user-permissions.enum'; -import { ApiData } from '@shared/models/common/json-api.model'; +import { Embed } from '@shared/models/common/json-api/embeds.model'; +import { ItemResponse } from '@shared/models/common/json-api/responses.model'; import { IdentifiersResponseJsonApi } from '@shared/models/identifiers/identifier-json-api.model'; -import { InstitutionsJsonApiResponse } from '@shared/models/institutions/institution-json-api.model'; import { LicenseDataJsonApi, LicenseRecordJsonApi } from '@shared/models/license/licenses-json-api.model'; -export interface MetadataJsonApiResponse { - data: MetadataJsonApi; +export type MetadataResponseJsonApi = ItemResponse; +export type CustomMetadataResponseJsonApi = ItemResponse; + +export interface MetadataDataJsonApi extends JsonApiResource<'metadata', MetadataAttributesJsonApi> { + relationships: MetadataRelationshipsJsonApi; + embeds?: MetadataEmbedsJsonApi; } -export type MetadataJsonApi = ApiData; +export type CustomMetadataDataJsonApi = JsonApiResource< + 'custom-item-metadata-records', + CustomMetadataAttributesJsonApi +>; export interface MetadataAttributesJsonApi { - title: string; - description: string; - tags: string[]; + article_doi?: string; + category?: string; + current_user_permissions: UserPermissions[]; date_created: string; date_modified: string; - article_doi?: string; + description: string; doi?: boolean; - category?: string; node_license?: LicenseRecordJsonApi; public?: boolean; registration_supplement?: string; - current_user_permissions: UserPermissions[]; -} - -interface MetadataEmbedsJsonApi { - affiliated_institutions: InstitutionsJsonApiResponse; - identifiers: IdentifiersResponseJsonApi; - license: { - data: LicenseDataJsonApi; - }; - provider?: { - data: { id: string; type: string; attributes: { name: string } }; - }; -} - -export interface CustomMetadataJsonApiResponse { - data: CustomMetadataJsonApi; + tags: string[]; + title: string; } -export type CustomMetadataJsonApi = ApiData; - -export interface CustomMetadataAttributesJsonApi { +interface CustomMetadataAttributesJsonApi { + funders?: FunderJsonApi[]; language?: string; resource_type_general?: string; - funders?: FunderJsonApi[]; } -export interface FunderJsonApi { - funder_name: string; - funder_identifier: string; - funder_identifier_type: string; +interface FunderJsonApi { award_number: string; - award_uri: string; award_title: string; + award_uri: string; + funder_identifier: string; + funder_identifier_type: string; + funder_name: string; +} + +interface MetadataEmbedsJsonApi { + identifiers: IdentifiersResponseJsonApi; + license: Embed; +} + +interface MetadataRelationshipsJsonApi { + provider: ToOneRel; } diff --git a/src/app/features/metadata/pages/add-metadata/add-metadata.component.ts b/src/app/features/metadata/pages/add-metadata/add-metadata.component.ts index c60deb5be..a01e652b3 100644 --- a/src/app/features/metadata/pages/add-metadata/add-metadata.component.ts +++ b/src/app/features/metadata/pages/add-metadata/add-metadata.component.ts @@ -25,7 +25,7 @@ import { IS_MEDIUM } from '@osf/shared/helpers/breakpoints.tokens'; import { ToastService } from '@osf/shared/services/toast.service'; import { CedarTemplateFormComponent } from '../../components/cedar-template-form/cedar-template-form.component'; -import { CedarMetadataDataTemplateJsonApi, CedarMetadataRecordData, CedarRecordDataBinding } from '../../models'; +import { CedarMetadataDataTemplateJsonApi, CedarMetadataRecordDataJsonApi, CedarRecordDataBinding } from '../../models'; import { CreateCedarMetadataRecord, GetCedarMetadataRecords, @@ -54,7 +54,7 @@ export class AddMetadataComponent implements OnInit { private resourceId = ''; isEditMode = true; selectedTemplate: CedarMetadataDataTemplateJsonApi | null = null; - existingRecord: CedarMetadataRecordData | null = null; + existingRecord: CedarMetadataRecordDataJsonApi | null = null; readonly cedarTemplates = select(MetadataSelectors.getCedarTemplates); readonly cedarRecords = select(MetadataSelectors.getCedarRecords); diff --git a/src/app/features/metadata/store/metadata.actions.ts b/src/app/features/metadata/store/metadata.actions.ts index cc3301bca..d9b492ddf 100644 --- a/src/app/features/metadata/store/metadata.actions.ts +++ b/src/app/features/metadata/store/metadata.actions.ts @@ -2,7 +2,7 @@ import { ResourceType } from '@osf/shared/enums/resource-type.enum'; import { LicenseOptions } from '@shared/models/license/license.model'; import { - CedarMetadataRecordData, + CedarMetadataRecordDataJsonApi, CedarRecordDataBinding, CustomItemMetadataRecord, MetadataAttributesJsonApi, @@ -98,5 +98,5 @@ export class UpdateCedarMetadataRecord { export class AddCedarMetadataRecordToState { static readonly type = '[Metadata] Add Cedar Metadata Record To State'; - constructor(public record: CedarMetadataRecordData) {} + constructor(public record: CedarMetadataRecordDataJsonApi) {} } diff --git a/src/app/features/metadata/store/metadata.model.ts b/src/app/features/metadata/store/metadata.model.ts index a5e05dc5b..f46134f50 100644 --- a/src/app/features/metadata/store/metadata.model.ts +++ b/src/app/features/metadata/store/metadata.model.ts @@ -1,6 +1,6 @@ import { CedarMetadataRecord, - CedarMetadataRecordData, + CedarMetadataRecordDataJsonApi, CedarMetadataTemplateJsonApi, CustomItemMetadataRecord, } from '@osf/features/metadata/models'; @@ -15,7 +15,7 @@ export interface MetadataStateModel { fundersList: AsyncStateModel; cedarTemplates: AsyncStateModel; cedarRecord: AsyncStateModel; - cedarRecords: AsyncStateModel; + cedarRecords: AsyncStateModel; } export const METADATA_STATE_DEFAULTS: MetadataStateModel = { diff --git a/src/app/features/moderation/mappers/moderation.mapper.ts b/src/app/features/moderation/mappers/moderation.mapper.ts index 18af21c2e..160ae8844 100644 --- a/src/app/features/moderation/mappers/moderation.mapper.ts +++ b/src/app/features/moderation/mappers/moderation.mapper.ts @@ -1,7 +1,3 @@ -import { ResponseJsonApi } from '@osf/shared/models/common/json-api.model'; -import { PaginatedData } from '@osf/shared/models/paginated-data.model'; -import { UserDataJsonApi } from '@osf/shared/models/user/user-json-api.model'; - import { AddModeratorType, ModeratorPermission } from '../enums'; import { ModeratorAddModel, ModeratorAddRequestModel, ModeratorDataJsonApi, ModeratorModel } from '../models'; @@ -25,23 +21,6 @@ export class ModerationMapper { }; } - static fromUsersWithPaginationGetResponse( - response: ResponseJsonApi - ): PaginatedData { - return { - data: response.data.map( - (user) => - ({ - id: user.id, - fullName: user.attributes.full_name, - permission: ModeratorPermission.Moderator, - }) as ModeratorAddModel - ), - totalCount: response.meta.total, - pageSize: response.meta.per_page, - }; - } - static toModeratorAddRequest(model: ModeratorAddModel, type = AddModeratorType.Search): ModeratorAddRequestModel { if (type === AddModeratorType.Search) { return { diff --git a/src/app/features/moderation/mappers/preprint-moderation.mapper.ts b/src/app/features/moderation/mappers/preprint-moderation.mapper.ts index 621d929c1..455b11257 100644 --- a/src/app/features/moderation/mappers/preprint-moderation.mapper.ts +++ b/src/app/features/moderation/mappers/preprint-moderation.mapper.ts @@ -1,11 +1,12 @@ +import { DEFAULT_TABLE_PARAMS } from '@osf/shared/constants/default-table-params.constants'; import { UserMapper } from '@osf/shared/mappers/user'; -import { ResponseJsonApi } from '@osf/shared/models/common/json-api.model'; import { PaginatedData } from '@osf/shared/models/paginated-data.model'; import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { PreprintProviderModerationInfo, PreprintRelatedCountJsonApi, + PreprintReviewActionListResponseJsonApi, PreprintSubmissionResponseJsonApi, PreprintSubmissionWithdrawalResponseJsonApi, PreprintWithdrawalPaginatedData, @@ -39,12 +40,12 @@ export class PreprintModerationMapper { } static fromResponseWithPagination( - response: ResponseJsonApi + response: PreprintReviewActionListResponseJsonApi ): PaginatedData { return { data: response.data.map((x) => this.fromResponse(x)), totalCount: response.meta.total, - pageSize: response.meta.per_page, + pageSize: response.meta.per_page ?? DEFAULT_TABLE_PARAMS.rows, }; } @@ -73,7 +74,7 @@ export class PreprintModerationMapper { totalContributors: 0, })), totalCount: response.meta.total, - pageSize: response.meta.per_page, + pageSize: response.meta.per_page ?? DEFAULT_TABLE_PARAMS.rows, pendingCount: response.meta?.reviews_state_counts?.pending || 0, acceptedCount: response.meta?.reviews_state_counts?.accepted || 0, rejectedCount: response.meta?.reviews_state_counts?.rejected || 0, @@ -87,14 +88,14 @@ export class PreprintModerationMapper { return { data: response.data.map((x) => ({ id: x.id, - title: replaceBadEncodedChars(x.embeds.target.data.attributes.title), - preprintId: x.embeds.target.data.id, + title: replaceBadEncodedChars(x.embeds.target?.data?.attributes?.title), + preprintId: x.embeds.target?.data?.id, actions: [], contributors: [], totalContributors: 0, })), totalCount: response.meta.total, - pageSize: response.meta.per_page, + pageSize: response.meta.per_page ?? DEFAULT_TABLE_PARAMS.rows, pendingCount: response.meta.requests_state_counts.pending, acceptedCount: response.meta.requests_state_counts.accepted, rejectedCount: response.meta.requests_state_counts.rejected, diff --git a/src/app/features/moderation/mappers/registry-moderation.mapper.ts b/src/app/features/moderation/mappers/registry-moderation.mapper.ts index 70ab5fdb4..bab234290 100644 --- a/src/app/features/moderation/mappers/registry-moderation.mapper.ts +++ b/src/app/features/moderation/mappers/registry-moderation.mapper.ts @@ -1,3 +1,4 @@ +import { DEFAULT_TABLE_PARAMS } from '@osf/shared/constants/default-table-params.constants'; import { UserMapper } from '@osf/shared/mappers/user'; import { PaginatedData } from '@osf/shared/models/paginated-data.model'; import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; @@ -7,7 +8,7 @@ import { RegistryModeration, RegistryResponseJsonApi, ReviewAction, - ReviewActionsDataJsonApi, + ReviewActionDataJsonApi, } from '../models'; export class RegistryModerationMapper { @@ -29,11 +30,11 @@ export class RegistryModerationMapper { return { data: response.data.map((x) => this.fromResponse(x)), totalCount: response.meta.total, - pageSize: response.meta.per_page, + pageSize: response.meta.per_page ?? DEFAULT_TABLE_PARAMS.rows, }; } - static fromActionResponse(response: ReviewActionsDataJsonApi): ReviewAction { + static fromActionResponse(response: ReviewActionDataJsonApi): ReviewAction { const creator = UserMapper.getUserInfo(response.embeds?.creator); return { diff --git a/src/app/features/moderation/models/collection-submission-review-action-json-api.model.ts b/src/app/features/moderation/models/collection-submission-review-action-json-api.model.ts index cca102865..40f45a35a 100644 --- a/src/app/features/moderation/models/collection-submission-review-action-json-api.model.ts +++ b/src/app/features/moderation/models/collection-submission-review-action-json-api.model.ts @@ -1,25 +1,33 @@ +import { JsonApiResource, JsonApiResourceRef } from '@osf/shared/models/common/json-api/resource.model'; +import { ListResponse } from '@osf/shared/models/common/json-api/responses.model'; import { UserDataErrorResponseJsonApi } from '@osf/shared/models/user/user-json-api.model'; -export interface CollectionSubmissionReviewActionJsonApi { - id: string; - type: 'collection-submission-actions'; - attributes: { - trigger: string; - comment: string; - from_state: string; - to_state: string; - date_created: string; - date_modified: string; - }; - embeds: { - creator: UserDataErrorResponseJsonApi; - }; - relationships: { - target: { - data: { - id: string; - type: 'collection-submission'; - }; - }; +export type CollectionSubmissionReviewActionsListResponseJsonApi = + ListResponse; + +export interface CollectionSubmissionReviewActionJsonApi extends JsonApiResource< + 'collection-submission-actions', + CollectionSubmissionReviewActionAttributesJsonApi +> { + embeds: CollectionSubmissionReviewActionEmbedsJsonApi; + relationships: CollectionSubmissionReviewActionRelationshipsJsonApi; +} + +interface CollectionSubmissionReviewActionAttributesJsonApi { + comment: string; + date_created: string; + date_modified: string; + from_state: string; + to_state: string; + trigger: string; +} + +interface CollectionSubmissionReviewActionEmbedsJsonApi { + creator: UserDataErrorResponseJsonApi; +} + +interface CollectionSubmissionReviewActionRelationshipsJsonApi { + target: { + data: JsonApiResourceRef<'collection-submission'>; }; } diff --git a/src/app/features/moderation/models/moderator-json-api.model.ts b/src/app/features/moderation/models/moderator-json-api.model.ts index 24449f115..5838dfb87 100644 --- a/src/app/features/moderation/models/moderator-json-api.model.ts +++ b/src/app/features/moderation/models/moderator-json-api.model.ts @@ -1,31 +1,30 @@ -import { ApiData, MetaJsonApi, PaginationLinksJsonApi } from '@osf/shared/models/common/json-api.model'; +import { Embed } from '@osf/shared/models/common/json-api/embeds.model'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ItemResponse, ListResponse } from '@osf/shared/models/common/json-api/responses.model'; import { UserDataJsonApi } from '@osf/shared/models/user/user-json-api.model'; -export interface ModeratorResponseJsonApi { - data: ModeratorDataJsonApi[]; - meta: MetaJsonApi; - links: PaginationLinksJsonApi; -} - -export type ModeratorDataJsonApi = ApiData; +export type ModeratorResponseJsonApi = ListResponse; +export type ModeratorItemResponseJsonApi = ItemResponse; -interface ModeratorAttributesJsonApi { - full_name: string; - permission_group: 'moderator' | 'admin'; -} - -interface ModeratorEmbedsJsonApi { - user: { - data: UserDataJsonApi; - }; +export interface ModeratorDataJsonApi extends JsonApiResource<'moderators', ModeratorAttributesJsonApi> { + embeds: ModeratorEmbedsJsonApi; } export interface ModeratorAddRequestModel { - type: 'moderators'; attributes: { + email?: string; + full_name?: string; id?: string; permission_group: string; - full_name?: string; - email?: string; }; + type: 'moderators'; +} + +interface ModeratorAttributesJsonApi { + full_name: string; + permission_group: 'admin' | 'moderator'; +} + +interface ModeratorEmbedsJsonApi { + user: Embed; } diff --git a/src/app/features/moderation/models/preprint-related-count-json-api.model.ts b/src/app/features/moderation/models/preprint-related-count-json-api.model.ts index 7b78a3871..6acc16e83 100644 --- a/src/app/features/moderation/models/preprint-related-count-json-api.model.ts +++ b/src/app/features/moderation/models/preprint-related-count-json-api.model.ts @@ -1,21 +1,31 @@ +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ItemResponse, ListResponse } from '@osf/shared/models/common/json-api/responses.model'; import { PreprintProviderAttributesJsonApi } from '@osf/shared/models/provider/preprints-provider-json-api.model'; -export interface PreprintRelatedCountJsonApi { - id: string; - attributes: PreprintProviderAttributesJsonApi; - relationships: { - preprints: { - links: { - related: { - meta: { - accepted: number; - initial: number; - pending: number; - rejected: number; - withdrawn: number; - }; - }; +export type PreprintRelatedCountListResponseJsonApi = ListResponse; +export type PreprintRelatedCountItemResponseJsonApi = ItemResponse; + +export interface PreprintRelatedCountJsonApi extends JsonApiResource< + 'preprint-providers', + PreprintProviderAttributesJsonApi +> { + relationships: PreprintRelatedCountRelationshipsJsonApi; +} + +interface PreprintRelatedCountRelationshipsJsonApi { + preprints: { + links: { + related: { + meta: PreprintRelationshipMetaJsonApi; }; }; }; } + +interface PreprintRelationshipMetaJsonApi { + accepted: number; + initial: number; + pending: number; + rejected: number; + withdrawn: number; +} diff --git a/src/app/features/moderation/models/preprint-review-action-json-api.model.ts b/src/app/features/moderation/models/preprint-review-action-json-api.model.ts index ef2ce5fbf..552394353 100644 --- a/src/app/features/moderation/models/preprint-review-action-json-api.model.ts +++ b/src/app/features/moderation/models/preprint-review-action-json-api.model.ts @@ -1,49 +1,28 @@ -import { UserAttributesJsonApi, UserDataErrorResponseJsonApi } from '@osf/shared/models/user/user-json-api.model'; +import { Embed } from '@osf/shared/models/common/json-api/embeds.model'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ListResponse } from '@osf/shared/models/common/json-api/responses.model'; +import { PreprintDataJsonApi } from '@osf/shared/models/preprints/preprint-json-api.model'; +import { PreprintProviderAttributesJsonApi } from '@osf/shared/models/provider/preprints-provider-json-api.model'; +import { UserDataErrorResponseJsonApi } from '@osf/shared/models/user/user-json-api.model'; -export interface ReviewActionJsonApi { - id: string; - type: 'review-actions'; - attributes: ReviewActionAttributesJsonApi; - embeds: { - creator: UserDataErrorResponseJsonApi; - target: { - data: PreprintModelJsonApi; - }; - provider: { - data: ProviderModelJsonApi; - }; - }; +export type PreprintReviewActionListResponseJsonApi = ListResponse; + +export interface ReviewActionJsonApi extends JsonApiResource<'review-actions', ReviewActionAttributesJsonApi> { + embeds: ReviewActionEmbedsJsonApi; } -export interface ReviewActionAttributesJsonApi { - trigger: string; +interface ReviewActionAttributesJsonApi { + auto: boolean; comment: string; - from_state: string; - to_state: string; date_created: string; date_modified: string; - auto: boolean; -} - -export interface UserModelJsonApi { - id: string; - type: 'users'; - attributes: UserAttributesJsonApi; -} - -export interface PreprintModelJsonApi { - id: string; - type: 'preprints'; - attributes: PreprintAttributesJsonApi; -} - -export interface PreprintAttributesJsonApi { - title: string; + from_state: string; + to_state: string; + trigger: string; } -export interface ProviderModelJsonApi { - id: string; - attributes: { - name: string; - }; +interface ReviewActionEmbedsJsonApi { + creator: UserDataErrorResponseJsonApi; + provider: Embed>; + target: Embed; } diff --git a/src/app/features/moderation/models/preprint-submission-json-api.model.ts b/src/app/features/moderation/models/preprint-submission-json-api.model.ts index d18b87089..51509db33 100644 --- a/src/app/features/moderation/models/preprint-submission-json-api.model.ts +++ b/src/app/features/moderation/models/preprint-submission-json-api.model.ts @@ -1,30 +1,27 @@ -import { JsonApiResponseWithMeta, MetaJsonApi } from '@osf/shared/models/common/json-api.model'; +import { ListMetaJsonApi } from '@osf/shared/models/common/json-api/meta.model'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ListResponse } from '@osf/shared/models/common/json-api/responses.model'; -export type PreprintSubmissionResponseJsonApi = JsonApiResponseWithMeta< - PreprintSubmissionDataJsonApi[], - PreprintSubmissionMetaJsonApi, - null ->; +export type PreprintSubmissionResponseJsonApi = ListResponse & { + meta: PreprintSubmissionMetaJsonApi; +}; -export interface PreprintSubmissionDataJsonApi { - id: string; - attributes: PreprintSubmissionAttributesJsonApi; -} +export type PreprintSubmissionDataJsonApi = JsonApiResource<'preprints', PreprintSubmissionAttributesJsonApi>; -interface PreprintSubmissionMetaJsonApi extends MetaJsonApi { +interface PreprintSubmissionMetaJsonApi extends ListMetaJsonApi { reviews_state_counts: { - pending: number; accepted: number; + pending: number; rejected: number; withdrawn: number; }; } interface PreprintSubmissionAttributesJsonApi { + embargo_end_date: string; + embargoed: boolean; id: string; - title: string; - reviews_state: string; public: boolean; - embargoed: boolean; - embargo_end_date: string; + reviews_state: string; + title: string; } diff --git a/src/app/features/moderation/models/preprint-withdrawal-submission-json-api.model.ts b/src/app/features/moderation/models/preprint-withdrawal-submission-json-api.model.ts index c68a0c336..5430734b3 100644 --- a/src/app/features/moderation/models/preprint-withdrawal-submission-json-api.model.ts +++ b/src/app/features/moderation/models/preprint-withdrawal-submission-json-api.model.ts @@ -1,40 +1,36 @@ -import { JsonApiResponseWithMeta, MetaJsonApi } from '@osf/shared/models/common/json-api.model'; +import { Embed } from '@osf/shared/models/common/json-api/embeds.model'; +import { ListMetaJsonApi } from '@osf/shared/models/common/json-api/meta.model'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ListResponse } from '@osf/shared/models/common/json-api/responses.model'; +import { PreprintAttributesJsonApi } from '@osf/shared/models/preprints/preprint-json-api.model'; import { UserDataErrorResponseJsonApi } from '@osf/shared/models/user/user-json-api.model'; -export type PreprintSubmissionWithdrawalResponseJsonApi = JsonApiResponseWithMeta< - PreprintWithdrawalSubmissionDataJsonApi[], - PreprintWithdrawalSubmissionMetaJsonApi, - null ->; +export type PreprintSubmissionWithdrawalResponseJsonApi = ListResponse & { + meta: PreprintWithdrawalSubmissionMetaJsonApi; +}; -export interface PreprintWithdrawalSubmissionDataJsonApi { - id: string; - attributes: PreprintWithdrawalSubmissionAttributesJsonApi; +export interface PreprintWithdrawalSubmissionDataJsonApi extends JsonApiResource< + 'preprint-withdrawal-submissions', + PreprintWithdrawalSubmissionAttributesJsonApi +> { embeds: PreprintWithdrawalSubmissionEmbedsJsonApi; } -interface PreprintWithdrawalSubmissionMetaJsonApi extends MetaJsonApi { +interface PreprintWithdrawalSubmissionMetaJsonApi extends ListMetaJsonApi { requests_state_counts: { - pending: number; accepted: number; + pending: number; rejected: number; }; } interface PreprintWithdrawalSubmissionAttributesJsonApi { comment: string; - machine_state: string; date_last_transitioned: string; + machine_state: string; } interface PreprintWithdrawalSubmissionEmbedsJsonApi { - target: { - data: { - id: string; - attributes: { - title: string; - }; - }; - }; creator: UserDataErrorResponseJsonApi; + target: Embed>; } diff --git a/src/app/features/moderation/models/registry-json-api.model.ts b/src/app/features/moderation/models/registry-json-api.model.ts index e8dd6c41e..1fbf11e9d 100644 --- a/src/app/features/moderation/models/registry-json-api.model.ts +++ b/src/app/features/moderation/models/registry-json-api.model.ts @@ -1,16 +1,14 @@ -import { ResponseJsonApi } from '@osf/shared/models/common/json-api.model'; +import { ToManyRel } from '@osf/shared/models/common/json-api/relationships.model'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ListResponse } from '@osf/shared/models/common/json-api/responses.model'; import { RegistrationNodeAttributesJsonApi } from '@osf/shared/models/registration/registration-node-json-api.model'; -export type RegistryResponseJsonApi = ResponseJsonApi; +export type RegistryResponseJsonApi = ListResponse; -export interface RegistryDataJsonApi { - id: string; - attributes: RegistrationNodeAttributesJsonApi; +export interface RegistryDataJsonApi extends JsonApiResource<'registrations', RegistrationNodeAttributesJsonApi> { embeds: RegistryEmbedsJsonApi; } -export interface RegistryEmbedsJsonApi { - schema_responses: { - data: { id: string }[]; - }; +interface RegistryEmbedsJsonApi { + schema_responses: ToManyRel<'schema-responses'>; } diff --git a/src/app/features/moderation/models/review-action-json-api.model.ts b/src/app/features/moderation/models/review-action-json-api.model.ts index a8d5be563..0384b3046 100644 --- a/src/app/features/moderation/models/review-action-json-api.model.ts +++ b/src/app/features/moderation/models/review-action-json-api.model.ts @@ -1,11 +1,10 @@ -import { JsonApiResponse } from '@osf/shared/models/common/json-api.model'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ListResponse } from '@osf/shared/models/common/json-api/responses.model'; import { UserDataErrorResponseJsonApi } from '@osf/shared/models/user/user-json-api.model'; -export type ReviewActionsResponseJsonApi = JsonApiResponse; +export type ReviewActionsResponseJsonApi = ListResponse; -export interface ReviewActionsDataJsonApi { - id: string; - attributes: ReviewActionAttributesJsonApi; +export interface ReviewActionDataJsonApi extends JsonApiResource<'review-actions', ReviewActionAttributesJsonApi> { embeds: ReviewActionEmbedsJsonApi; } diff --git a/src/app/features/moderation/services/moderators.service.ts b/src/app/features/moderation/services/moderators.service.ts index 3a184913f..3e201bdb6 100644 --- a/src/app/features/moderation/services/moderators.service.ts +++ b/src/app/features/moderation/services/moderators.service.ts @@ -3,10 +3,10 @@ import { forkJoin, map, Observable } from 'rxjs'; import { inject, Injectable } from '@angular/core'; import { ENVIRONMENT } from '@core/provider/environment.provider'; +import { DEFAULT_TABLE_PARAMS } from '@osf/shared/constants/default-table-params.constants'; import { ResourceType } from '@osf/shared/enums/resource-type.enum'; import { parseSearchTotalCount } from '@osf/shared/helpers/search-total-count.helper'; import { MapResources } from '@osf/shared/mappers/search'; -import { JsonApiResponse } from '@osf/shared/models/common/json-api.model'; import { PaginatedData } from '@osf/shared/models/paginated-data.model'; import { IndexCardSearchResponseJsonApi } from '@osf/shared/models/search/index-card-search-json-api.model'; import { SearchUserDataModel } from '@osf/shared/models/user/search-user-data.model'; @@ -15,7 +15,13 @@ import { StringOrNull } from '@shared/helpers/types.helper'; import { AddModeratorType, ModeratorPermission } from '../enums'; import { ModerationMapper } from '../mappers'; -import { ModeratorAddModel, ModeratorDataJsonApi, ModeratorModel, ModeratorResponseJsonApi } from '../models'; +import { + ModeratorAddModel, + ModeratorDataJsonApi, + ModeratorItemResponseJsonApi, + ModeratorModel, + ModeratorResponseJsonApi, +} from '../models'; @Injectable({ providedIn: 'root', @@ -64,7 +70,7 @@ export class ModeratorsService { map((response) => ({ data: ModerationMapper.getModerators(response.data), totalCount: response.meta.total, - pageSize: response.meta.per_page, + pageSize: response.meta.per_page ?? DEFAULT_TABLE_PARAMS.rows, })) ); } @@ -76,7 +82,7 @@ export class ModeratorsService { const moderatorData = { data: ModerationMapper.toModeratorAddRequest(data, type) }; return this.jsonApiService - .post>(baseUrl, moderatorData) + .post(baseUrl, moderatorData) .pipe(map((moderator) => ModerationMapper.fromModeratorResponse(moderator.data))); } diff --git a/src/app/features/moderation/services/preprint-moderation.service.ts b/src/app/features/moderation/services/preprint-moderation.service.ts index a41c9906f..61672912a 100644 --- a/src/app/features/moderation/services/preprint-moderation.service.ts +++ b/src/app/features/moderation/services/preprint-moderation.service.ts @@ -3,7 +3,6 @@ import { catchError, forkJoin, map, Observable, of, switchMap } from 'rxjs'; import { inject, Injectable } from '@angular/core'; import { ENVIRONMENT } from '@core/provider/environment.provider'; -import { ResponseJsonApi } from '@osf/shared/models/common/json-api.model'; import { PaginatedData } from '@osf/shared/models/paginated-data.model'; import { JsonApiService } from '@osf/shared/services/json-api.service'; @@ -11,13 +10,14 @@ import { PreprintSubmissionsSort } from '../enums'; import { PreprintModerationMapper, RegistryModerationMapper } from '../mappers'; import { PreprintProviderModerationInfo, - PreprintRelatedCountJsonApi, + PreprintRelatedCountItemResponseJsonApi, + PreprintRelatedCountListResponseJsonApi, + PreprintReviewActionListResponseJsonApi, PreprintReviewActionModel, PreprintSubmissionResponseJsonApi, PreprintSubmissionWithdrawalResponseJsonApi, PreprintWithdrawalPaginatedData, ReviewAction, - ReviewActionJsonApi, ReviewActionsResponseJsonApi, } from '../models'; import { PreprintSubmissionPaginatedData } from '../models/preprint-submission.model'; @@ -37,7 +37,7 @@ export class PreprintModerationService { const baseUrl = `${this.apiUrl}/providers/preprints/?filter[permissions]=view_actions,set_up_moderation`; return this.jsonApiService - .get>(baseUrl) + .get(baseUrl) .pipe(map((response) => response.data.map((x) => PreprintModerationMapper.fromPreprintRelatedCounts(x)))); } @@ -45,7 +45,7 @@ export class PreprintModerationService { const baseUrl = `${this.apiUrl}/providers/preprints/${id}/?related_counts=true`; return this.jsonApiService - .get>(baseUrl) + .get(baseUrl) .pipe(map((response) => PreprintModerationMapper.fromPreprintRelatedCounts(response.data))); } @@ -53,7 +53,7 @@ export class PreprintModerationService { const baseUrl = `${this.apiUrl}/actions/reviews/?embed=provider&embed=target&page=${page}`; return this.jsonApiService - .get>(baseUrl) + .get(baseUrl) .pipe(map((response) => PreprintModerationMapper.fromResponseWithPagination(response))); } diff --git a/src/app/features/moderation/services/provider-subscription.service.ts b/src/app/features/moderation/services/provider-subscription.service.ts index 21277c50b..378022180 100644 --- a/src/app/features/moderation/services/provider-subscription.service.ts +++ b/src/app/features/moderation/services/provider-subscription.service.ts @@ -6,9 +6,11 @@ import { ENVIRONMENT } from '@core/provider/environment.provider'; import { SubscriptionFrequency } from '@osf/shared/enums/subscriptions/subscription-frequency.enum'; import { SubscriptionType } from '@osf/shared/enums/subscriptions/subscription-type.enum'; import { NotificationSubscriptionMapper } from '@osf/shared/mappers/notification-subscription.mapper'; -import { JsonApiResponse } from '@osf/shared/models/common/json-api.model'; import { NotificationSubscription } from '@osf/shared/models/notifications/notification-subscription.model'; -import { NotificationSubscriptionGetResponseJsonApi } from '@osf/shared/models/notifications/notification-subscription-json-api.model'; +import { + NotificationSubscriptionDataJsonApi, + NotificationSubscriptionsListResponseJsonApi, +} from '@osf/shared/models/notifications/notification-subscription-json-api.model'; import { JsonApiService } from '@osf/shared/services/json-api.service'; @Injectable({ @@ -24,9 +26,7 @@ export class ProviderSubscriptionService { getProviderSubscriptions(providerType: string, providerId: string): Observable { return this.jsonApiService - .get< - JsonApiResponse - >(this.providerUrl(providerType, providerId)) + .get(this.providerUrl(providerType, providerId)) .pipe( map((responses) => responses.data.map((response) => NotificationSubscriptionMapper.fromGetResponse(response))) ); @@ -47,7 +47,7 @@ export class ProviderSubscriptionService { }; return this.jsonApiService - .patch( + .patch( `${this.providerUrl(providerType, providerId)}${subscriptionId}/`, request ) diff --git a/src/app/features/my-projects/my-projects.component.ts b/src/app/features/my-projects/my-projects.component.ts index eb801ea78..7fd25fe10 100644 --- a/src/app/features/my-projects/my-projects.component.ts +++ b/src/app/features/my-projects/my-projects.component.ts @@ -32,7 +32,7 @@ import { SubHeaderComponent } from '@osf/shared/components/sub-header/sub-header import { DEFAULT_TABLE_PARAMS } from '@osf/shared/constants/default-table-params.constants'; import { SortOrder } from '@osf/shared/enums/sort-order.enum'; import { IS_MEDIUM } from '@osf/shared/helpers/breakpoints.tokens'; -import { MyResourcesItem } from '@osf/shared/models/my-resources/my-resources.model'; +import { MyResourcesItem } from '@osf/shared/models/my-resources/my-resources-item.model'; import { MyResourcesSearchFilters } from '@osf/shared/models/my-resources/my-resources-search-filters.model'; import { CustomDialogService } from '@osf/shared/services/custom-dialog.service'; import { ProjectRedirectDialogService } from '@osf/shared/services/project-redirect-dialog.service'; diff --git a/src/app/features/preprints/mappers/preprint-providers.mapper.ts b/src/app/features/preprints/mappers/preprint-providers.mapper.ts index c9fa25ac2..ecfdd57b9 100644 --- a/src/app/features/preprints/mappers/preprint-providers.mapper.ts +++ b/src/app/features/preprints/mappers/preprint-providers.mapper.ts @@ -8,7 +8,7 @@ import { PreprintProviderDetails, PreprintProviderDetailsJsonApi, PreprintProvid export class PreprintProvidersMapper { static fromPreprintProviderDetailsGetResponse(response: PreprintProviderDetailsJsonApi): PreprintProviderDetails { - const brandRaw = response.embeds!.brand?.data; + const brandRaw = response.embeds?.brand?.data; return { id: response.id, name: replaceBadEncodedChars(response.attributes.name), @@ -32,7 +32,7 @@ export class PreprintProvidersMapper { }; } - static parseBrand(brandRaw: BrandDataJsonApi): BrandModel { + static parseBrand(brandRaw: BrandDataJsonApi | undefined): BrandModel { if (!brandRaw) { return { primaryColor: 'var(--osf-provider-primary-color)', diff --git a/src/app/features/preprints/mappers/preprints.mapper.ts b/src/app/features/preprints/mappers/preprints.mapper.ts index ed01f2be9..952817c24 100644 --- a/src/app/features/preprints/mappers/preprints.mapper.ts +++ b/src/app/features/preprints/mappers/preprints.mapper.ts @@ -2,18 +2,14 @@ import { StringOrNull } from '@osf/shared/helpers/types.helper'; import { ContributorsMapper } from '@osf/shared/mappers/contributors'; import { IdentifiersMapper } from '@osf/shared/mappers/identifiers.mapper'; import { LicensesMapper } from '@osf/shared/mappers/licenses.mapper'; -import { ApiData, JsonApiResponseWithMeta, ResponseJsonApi } from '@osf/shared/models/common/json-api.model'; +import { + PreprintDataJsonApi, + PreprintResponseJsonApi, + PreprintsListResponseJsonApi, +} from '@osf/shared/models/preprints/preprint-json-api.model'; import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; -import { - PreprintAttributesJsonApi, - PreprintEmbedsJsonApi, - PreprintLinksJsonApi, - PreprintMetaJsonApi, - PreprintModel, - PreprintRelationshipsJsonApi, - PreprintShortInfoWithTotalCount, -} from '../models'; +import { PreprintModel, PreprintShortInfoWithTotalCount } from '../models'; export class PreprintsMapper { static toCreatePayload(title: string, abstract: string, providerId: string) { @@ -36,9 +32,7 @@ export class PreprintsMapper { }; } - static fromPreprintJsonApi( - response: ApiData - ): PreprintModel { + static fromPreprintJsonApi(response: PreprintDataJsonApi): PreprintModel { return { id: response.id, dateCreated: response.attributes.date_created, @@ -81,21 +75,15 @@ export class PreprintsMapper { whyNoPrereg: response.attributes.why_no_prereg ? replaceBadEncodedChars(response.attributes.why_no_prereg) : null, preregLinks: response.attributes.prereg_links, preregLinkInfo: response.attributes.prereg_link_info, - preprintDoiLink: response.links.preprint_doi, - articleDoiLink: response.links.doi, + preprintDoiLink: response.links?.preprint_doi ?? '', + articleDoiLink: response.links?.doi ?? '', embeddedLicense: null, providerId: response.relationships?.provider?.data?.id, defaultLicenseId: response.attributes.default_license_id, }; } - static fromPreprintWithEmbedsJsonApi( - response: JsonApiResponseWithMeta< - ApiData, - PreprintMetaJsonApi, - null - > - ): PreprintModel { + static fromPreprintWithEmbedsJsonApi(response: PreprintResponseJsonApi): PreprintModel { const data = response.data; const links = response.data.links; const relationships = response?.data?.relationships; @@ -142,10 +130,12 @@ export class PreprintsMapper { whyNoPrereg: data.attributes.why_no_prereg ? replaceBadEncodedChars(data.attributes.why_no_prereg) : null, preregLinks: data.attributes.prereg_links, preregLinkInfo: data.attributes.prereg_link_info, - embeddedLicense: LicensesMapper.fromLicenseDataJsonApi(data.embeds?.license?.data), + embeddedLicense: data.embeds?.license?.data + ? LicensesMapper.fromLicenseDataJsonApi(data.embeds?.license?.data) + : null, identifiers: IdentifiersMapper.fromJsonApi(data.embeds?.identifiers), - preprintDoiLink: links.preprint_doi, - articleDoiLink: links.doi, + preprintDoiLink: links?.preprint_doi ?? '', + articleDoiLink: links?.doi ?? '', providerId: relationships?.provider?.data?.id, }; } @@ -170,11 +160,7 @@ export class PreprintsMapper { }; } - static fromMyPreprintJsonApi( - response: ResponseJsonApi< - ApiData[] - > - ): PreprintShortInfoWithTotalCount { + static fromMyPreprintJsonApi(response: PreprintsListResponseJsonApi): PreprintShortInfoWithTotalCount { return { data: response.data.map((preprintData) => ({ id: preprintData.id, diff --git a/src/app/features/preprints/models/index.ts b/src/app/features/preprints/models/index.ts index 5c556d995..e831133e1 100644 --- a/src/app/features/preprints/models/index.ts +++ b/src/app/features/preprints/models/index.ts @@ -1,5 +1,4 @@ export * from './preprint.model'; -export * from './preprint-json-api.model'; export * from './preprint-licenses-json-api.model'; export * from './preprint-provider.model'; export * from './preprint-provider-json-api.model'; diff --git a/src/app/features/preprints/models/preprint-licenses-json-api.model.ts b/src/app/features/preprints/models/preprint-licenses-json-api.model.ts index b1b1ba6f8..821bb145c 100644 --- a/src/app/features/preprints/models/preprint-licenses-json-api.model.ts +++ b/src/app/features/preprints/models/preprint-licenses-json-api.model.ts @@ -1,10 +1,5 @@ import { LicenseRecordJsonApi } from '@osf/shared/models/license/licenses-json-api.model'; -export interface PreprintLicenseRelationshipJsonApi { - id: string; - type: 'licenses'; -} - export interface PreprintLicensePayloadJsonApi { data: { type: 'preprints'; @@ -19,3 +14,8 @@ export interface PreprintLicensePayloadJsonApi { }; }; } + +interface PreprintLicenseRelationshipJsonApi { + id: string; + type: 'licenses'; +} diff --git a/src/app/features/preprints/models/preprint-provider-json-api.model.ts b/src/app/features/preprints/models/preprint-provider-json-api.model.ts index e71cc5ee2..7663c7ed0 100644 --- a/src/app/features/preprints/models/preprint-provider-json-api.model.ts +++ b/src/app/features/preprints/models/preprint-provider-json-api.model.ts @@ -1,41 +1,48 @@ import { ReviewPermissions } from '@osf/shared/enums/review-permissions.enum'; import { StringOrNull } from '@osf/shared/helpers/types.helper'; import { BrandDataJsonApi } from '@osf/shared/models/brand/brand.json-api.model'; +import { Embed } from '@osf/shared/models/common/json-api/embeds.model'; +import { ResourceLinksJsonApi } from '@osf/shared/models/common/json-api/links.model'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ItemResponse, ListResponse } from '@osf/shared/models/common/json-api/responses.model'; import { ProviderReviewsWorkflow } from '../enums'; import { PreprintWord } from './preprint-provider.model'; -export interface PreprintProviderDetailsJsonApi { - id: string; - type: 'preprint-providers'; - attributes: { - name: string; - description: string; - advisory_board: StringOrNull; - example: string; - domain: string; - footer_links: string; - preprint_word: PreprintWord; - permissions: ReviewPermissions[]; - assets: { - wide_white: string; - square_color_no_transparent: string; - favicon: string; - }; - allow_submissions: boolean; - assertions_enabled: boolean; - reviews_workflow: ProviderReviewsWorkflow | null; - facebook_app_id: StringOrNull; - reviews_comments_private: StringOrNull; - reviews_comments_anonymous: StringOrNull; - }; - embeds?: { - brand: { - data: BrandDataJsonApi; - }; - }; - links: { - iri: string; +export type PreprintProviderResponseJsonApi = ItemResponse; +export type PreprintProvidersListResponseJsonApi = ListResponse; + +export interface PreprintProviderDetailsJsonApi extends JsonApiResource< + 'preprint-providers', + PreprintProviderAttributesJsonApi +> { + embeds?: PreprintProviderEmbedsJsonApi; + links: ResourceLinksJsonApi; +} + +interface PreprintProviderAttributesJsonApi { + advisory_board: StringOrNull; + allow_submissions: boolean; + assertions_enabled: boolean; + assets: { + favicon: string; + square_color_no_transparent: string; + wide_white: string; }; + description: string; + domain: string; + example: string; + facebook_app_id: StringOrNull; + footer_links: string; + name: string; + permissions: ReviewPermissions[]; + preprint_word: PreprintWord; + reviews_comments_anonymous: StringOrNull; + reviews_comments_private: StringOrNull; + reviews_workflow: ProviderReviewsWorkflow | null; +} + +interface PreprintProviderEmbedsJsonApi { + brand?: Embed; } diff --git a/src/app/features/preprints/models/preprint-request-action-json-api.model.ts b/src/app/features/preprints/models/preprint-request-action-json-api.model.ts index 4c9e53bef..777fbb899 100644 --- a/src/app/features/preprints/models/preprint-request-action-json-api.model.ts +++ b/src/app/features/preprints/models/preprint-request-action-json-api.model.ts @@ -1,24 +1,25 @@ -import { JsonApiResponse } from '@osf/shared/models/common/json-api.model'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ListResponse } from '@osf/shared/models/common/json-api/responses.model'; import { UserDataErrorResponseJsonApi } from '@osf/shared/models/user/user-json-api.model'; -export type PreprintRequestActionsJsonApiResponse = JsonApiResponse; +export type PreprintRequestActionsJsonApiResponse = ListResponse; -export interface PreprintRequestActionDataJsonApi { - id: string; - type: 'preprint_request_actions'; - attributes: PreprintRequestActionsAttributesJsonApi; - embeds: PreprintRequestEmbedsJsonApi; +export interface PreprintRequestActionDataJsonApi extends JsonApiResource< + 'preprint_request_actions', + PreprintRequestActionAttributesJsonApi +> { + embeds: PreprintRequestActionEmbedsJsonApi; } -interface PreprintRequestActionsAttributesJsonApi { - trigger: string; +interface PreprintRequestActionAttributesJsonApi { comment: string; - from_state: string; - to_state: string; date_created: Date; date_modified: Date; + from_state: string; + to_state: string; + trigger: string; } -interface PreprintRequestEmbedsJsonApi { +interface PreprintRequestActionEmbedsJsonApi { creator: UserDataErrorResponseJsonApi; } diff --git a/src/app/features/preprints/models/preprint-request-json-api.model.ts b/src/app/features/preprints/models/preprint-request-json-api.model.ts index fca82bcde..0d406799b 100644 --- a/src/app/features/preprints/models/preprint-request-json-api.model.ts +++ b/src/app/features/preprints/models/preprint-request-json-api.model.ts @@ -1,23 +1,25 @@ -import { PreprintRequestMachineState, PreprintRequestType } from '@osf/features/preprints/enums'; -import { JsonApiResponse } from '@osf/shared/models/common/json-api.model'; +import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model'; +import { ListResponse } from '@osf/shared/models/common/json-api/responses.model'; import { UserDataErrorResponseJsonApi } from '@osf/shared/models/user/user-json-api.model'; -export type PreprintRequestsJsonApiResponse = JsonApiResponse; +import { PreprintRequestMachineState, PreprintRequestType } from '../enums'; -export interface PreprintRequestDataJsonApi { - id: string; - type: 'preprint_requests'; - attributes: PreprintRequestAttributesJsonApi; +export type PreprintRequestsJsonApiResponse = ListResponse; + +export interface PreprintRequestDataJsonApi extends JsonApiResource< + 'preprint_requests', + PreprintRequestAttributesJsonApi +> { embeds: PreprintRequestEmbedsJsonApi; } interface PreprintRequestAttributesJsonApi { - request_type: PreprintRequestType; - machine_state: PreprintRequestMachineState; comment: string; created: Date; - modified: Date; date_last_transitioned: Date; + machine_state: PreprintRequestMachineState; + modified: Date; + request_type: PreprintRequestType; } interface PreprintRequestEmbedsJsonApi { diff --git a/src/app/features/preprints/services/preprint-files.service.ts b/src/app/features/preprints/services/preprint-files.service.ts index 0f0de7945..804f32e47 100644 --- a/src/app/features/preprints/services/preprint-files.service.ts +++ b/src/app/features/preprints/services/preprint-files.service.ts @@ -4,22 +4,17 @@ import { inject, Injectable } from '@angular/core'; import { ENVIRONMENT } from '@core/provider/environment.provider'; import { PreprintsMapper } from '@osf/features/preprints/mappers'; -import { - PreprintAttributesJsonApi, - PreprintFilesLinks, - PreprintLinksJsonApi, - PreprintModel, - PreprintRelationshipsJsonApi, -} from '@osf/features/preprints/models'; -import { ApiData } from '@osf/shared/models/common/json-api.model'; import { FileFolderModel } from '@osf/shared/models/files/file-folder.model'; import { FileFolderResponseJsonApi, FileFoldersResponseJsonApi, } from '@osf/shared/models/files/file-folder-json-api.model'; +import { PreprintDataJsonApi } from '@osf/shared/models/preprints/preprint-json-api.model'; import { JsonApiService } from '@osf/shared/services/json-api.service'; import { FilesMapper } from '@shared/mappers/files/files.mapper'; +import { PreprintFilesLinks, PreprintModel } from '../models'; + @Injectable({ providedIn: 'root', }) @@ -33,24 +28,21 @@ export class PreprintFilesService { updateFileRelationship(preprintId: string, fileId: string): Observable { return this.jsonApiService - .patch>( - `${this.apiUrl}/preprints/${preprintId}/`, - { - data: { - type: 'preprints', - id: preprintId, - attributes: {}, - relationships: { - primary_file: { - data: { - type: 'files', - id: fileId, - }, + .patch(`${this.apiUrl}/preprints/${preprintId}/`, { + data: { + type: 'preprints', + id: preprintId, + attributes: {}, + relationships: { + primary_file: { + data: { + type: 'files', + id: fileId, }, }, }, - } - ) + }, + }) .pipe(map((response) => PreprintsMapper.fromPreprintJsonApi(response))); } diff --git a/src/app/features/preprints/services/preprint-licenses.service.ts b/src/app/features/preprints/services/preprint-licenses.service.ts index 5d8a3a5f8..6f8de72cf 100644 --- a/src/app/features/preprints/services/preprint-licenses.service.ts +++ b/src/app/features/preprints/services/preprint-licenses.service.ts @@ -4,18 +4,14 @@ import { inject, Injectable } from '@angular/core'; import { ENVIRONMENT } from '@core/provider/environment.provider'; import { PreprintsMapper } from '@osf/features/preprints/mappers'; -import { - PreprintAttributesJsonApi, - PreprintLicensePayloadJsonApi, - PreprintLinksJsonApi, - PreprintRelationshipsJsonApi, -} from '@osf/features/preprints/models'; +import { PreprintDataJsonApi } from '@osf/shared/models/preprints/preprint-json-api.model'; import { JsonApiService } from '@osf/shared/services/json-api.service'; import { LicensesMapper } from '@shared/mappers/licenses.mapper'; -import { ApiData } from '@shared/models/common/json-api.model'; import { LicenseModel, LicenseOptions } from '@shared/models/license/license.model'; import { LicensesResponseJsonApi } from '@shared/models/license/licenses-json-api.model'; +import { PreprintLicensePayloadJsonApi } from '../models'; + @Injectable({ providedIn: 'root', }) @@ -61,9 +57,7 @@ export class PreprintLicensesService { }; return this.jsonApiService - .patch< - ApiData - >(`${this.apiUrl}/preprints/${preprintId}/`, payload) + .patch(`${this.apiUrl}/preprints/${preprintId}/`, payload) .pipe(map((response) => PreprintsMapper.fromPreprintJsonApi(response))); } } diff --git a/src/app/features/preprints/services/preprint-providers.service.ts b/src/app/features/preprints/services/preprint-providers.service.ts index 3463e59ed..9e2f18f61 100644 --- a/src/app/features/preprints/services/preprint-providers.service.ts +++ b/src/app/features/preprints/services/preprint-providers.service.ts @@ -6,11 +6,11 @@ import { ENVIRONMENT } from '@core/provider/environment.provider'; import { PreprintProvidersMapper } from '@osf/features/preprints/mappers'; import { PreprintProviderDetails, - PreprintProviderDetailsJsonApi, + PreprintProviderResponseJsonApi, PreprintProviderShortInfo, + PreprintProvidersListResponseJsonApi, } from '@osf/features/preprints/models'; import { JsonApiService } from '@osf/shared/services/json-api.service'; -import { JsonApiResponse } from '@shared/models/common/json-api.model'; import { SubjectModel } from '@shared/models/subject/subject.model'; import { SubjectsResponseJsonApi } from '@shared/models/subject/subjects-json-api.model'; @@ -27,15 +27,13 @@ export class PreprintProvidersService { getPreprintProviderById(id: string): Observable { return this.jsonApiService - .get>(`${this.apiUrl}${id}/?embed=brand`) + .get(`${this.apiUrl}${id}/?embed=brand`) .pipe(map((response) => PreprintProvidersMapper.fromPreprintProviderDetailsGetResponse(response.data))); } getPreprintProvidersToAdvertise(): Observable { return this.jsonApiService - .get< - JsonApiResponse - >(`${this.apiUrl}?filter[advertise_on_discover_page]=true&reload=true`) + .get(`${this.apiUrl}?filter[advertise_on_discover_page]=true&reload=true`) .pipe( map((response) => PreprintProvidersMapper.toPreprintProviderShortInfoFromGetResponse( @@ -47,7 +45,7 @@ export class PreprintProvidersService { getPreprintProvidersAllowingSubmissions(): Observable { return this.jsonApiService - .get>(`${this.apiUrl}?filter[allow_submissions]=true`) + .get(`${this.apiUrl}?filter[allow_submissions]=true`) .pipe(map((response) => PreprintProvidersMapper.toPreprintProviderShortInfoFromGetResponse(response.data))); } diff --git a/src/app/features/preprints/services/preprints-projects.service.ts b/src/app/features/preprints/services/preprints-projects.service.ts index 1f1eed57b..a228863a2 100644 --- a/src/app/features/preprints/services/preprints-projects.service.ts +++ b/src/app/features/preprints/services/preprints-projects.service.ts @@ -5,22 +5,17 @@ import { inject, Injectable } from '@angular/core'; import { ENVIRONMENT } from '@core/provider/environment.provider'; import { Primitive, StringOrNull } from '@osf/shared/helpers/types.helper'; import { IdNameModel } from '@osf/shared/models/common/id-name.model'; -import { ApiData } from '@osf/shared/models/common/json-api.model'; import { CreateProjectPayloadJsoApi, NodeResponseJsonApi, NodesResponseJsonApi, } from '@osf/shared/models/nodes/nodes-json-api.model'; +import { PreprintDataJsonApi } from '@osf/shared/models/preprints/preprint-json-api.model'; import { JsonApiService } from '@osf/shared/services/json-api.service'; import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { PreprintsMapper } from '../mappers'; -import { - PreprintAttributesJsonApi, - PreprintLinksJsonApi, - PreprintModel, - PreprintRelationshipsJsonApi, -} from '../models'; +import { PreprintModel } from '../models'; @Injectable({ providedIn: 'root', @@ -70,24 +65,21 @@ export class PreprintsProjectsService { updatePreprintProjectRelationship(preprintId: string, projectId: string): Observable { return this.jsonApiService - .patch>( - `${this.apiUrl}/preprints/${preprintId}/`, - { - data: { - type: 'preprints', - id: preprintId, - attributes: {}, - relationships: { - node: { - data: { - type: 'nodes', - id: projectId, - }, + .patch(`${this.apiUrl}/preprints/${preprintId}/`, { + data: { + type: 'preprints', + id: preprintId, + attributes: {}, + relationships: { + node: { + data: { + type: 'nodes', + id: projectId, }, }, }, - } - ) + }, + }) .pipe(map((response) => PreprintsMapper.fromPreprintJsonApi(response))); } diff --git a/src/app/features/preprints/services/preprints.service.ts b/src/app/features/preprints/services/preprints.service.ts index fad44bbdd..75fea39fb 100644 --- a/src/app/features/preprints/services/preprints.service.ts +++ b/src/app/features/preprints/services/preprints.service.ts @@ -5,29 +5,25 @@ import { Router } from '@angular/router'; import { ENVIRONMENT } from '@core/provider/environment.provider'; import { RegistryModerationMapper } from '@osf/features/moderation/mappers'; -import { ReviewActionsResponseJsonApi } from '@osf/features/moderation/models'; +import { ReviewActionsResponseJsonApi } from '@osf/features/moderation/models/review-action-json-api.model'; import { PreprintRequestActionsMapper } from '@osf/features/preprints/mappers/preprint-request-actions.mapper'; import { PreprintRequestAction } from '@osf/features/preprints/models/preprint-request-action.model'; import { searchPreferencesToJsonApiQueryParams } from '@osf/shared/helpers/search-pref-to-json-api-query-params.helper'; import { StringOrNull } from '@osf/shared/helpers/types.helper'; import { - ApiData, - JsonApiResponse, - JsonApiResponseWithMeta, - ResponseJsonApi, -} from '@osf/shared/models/common/json-api.model'; + PreprintAttributesJsonApi, + PreprintDataJsonApi, + PreprintMetricsResponseJsonApi, + PreprintResponseJsonApi, + PreprintsListResponseJsonApi, +} from '@osf/shared/models/preprints/preprint-json-api.model'; import { SearchFilters } from '@osf/shared/models/search-filters.model'; import { JsonApiService } from '@osf/shared/services/json-api.service'; import { preprintSortFieldMap } from '../constants'; import { PreprintRequestMapper, PreprintsMapper } from '../mappers'; import { - PreprintAttributesJsonApi, - PreprintEmbedsJsonApi, - PreprintLinksJsonApi, - PreprintMetaJsonApi, PreprintModel, - PreprintRelationshipsJsonApi, PreprintRequest, PreprintRequestActionsJsonApiResponse, PreprintRequestsJsonApiResponse, @@ -67,60 +63,39 @@ export class PreprintsService { createPreprint(title: string, abstract: string, providerId: string) { const payload = PreprintsMapper.toCreatePayload(title, abstract, providerId); return this.jsonApiService - .post< - JsonApiResponse< - ApiData, - null - > - >(`${this.apiUrl}/preprints/`, payload) + .post(`${this.apiUrl}/preprints/`, payload) .pipe(map((response) => PreprintsMapper.fromPreprintJsonApi(response.data))); } getById(id: string) { return this.jsonApiService - .get< - JsonApiResponse< - ApiData, - null - > - >(`${this.apiUrl}/preprints/${id}/`) + .get(`${this.apiUrl}/preprints/${id}/`) .pipe(map((response) => PreprintsMapper.fromPreprintJsonApi(response.data))); } getByIdWithEmbeds(id: string) { const params = { 'embed[]': ['license', 'identifiers'] }; - return this.jsonApiService - .get< - JsonApiResponseWithMeta< - ApiData, - PreprintMetaJsonApi, - null - > - >(`${this.apiUrl}/preprints/${id}/`, params) - .pipe( - map((response) => PreprintsMapper.fromPreprintWithEmbedsJsonApi(response)), - catchError((error) => { - if (error.error?.errors?.[0]?.meta?.flagged_content) { - this.router.navigate(['/spam-content']); - } - return throwError(() => error); - }) - ); + + return this.jsonApiService.get(`${this.apiUrl}/preprints/${id}/`, params).pipe( + map((response) => PreprintsMapper.fromPreprintWithEmbedsJsonApi(response)), + catchError((error) => { + if (error.error?.errors?.[0]?.meta?.flagged_content) { + this.router.navigate(['/spam-content']); + } + return throwError(() => error); + }) + ); } getPreprintMetrics(id: string) { const params = { 'metrics[views]': 'total', 'metrics[downloads]': 'total' }; - return this.jsonApiService - .get< - JsonApiResponseWithMeta, PreprintMetaJsonApi, null> - >(`${this.apiUrl}/preprints/${id}/`, params) - .pipe( - map((response) => ({ - downloads: response.meta.metrics.downloads, - views: response.meta.metrics.views, - })) - ); + return this.jsonApiService.get(`${this.apiUrl}/preprints/${id}/`, params).pipe( + map((response) => ({ + downloads: response.meta.metrics.downloads, + views: response.meta.metrics.views, + })) + ); } deletePreprint(id: string) { @@ -131,16 +106,13 @@ export class PreprintsService { const apiPayload = this.mapPreprintDomainToApiPayload(payload); return this.jsonApiService - .patch>( - `${this.apiUrl}/preprints/${id}/`, - { - data: { - type: 'preprints', - id, - attributes: apiPayload, - }, - } - ) + .patch(`${this.apiUrl}/preprints/${id}/`, { + data: { + type: 'preprints', + id, + attributes: apiPayload, + }, + }) .pipe(map((response) => PreprintsMapper.fromPreprintJsonApi(response))); } @@ -151,12 +123,7 @@ export class PreprintsService { createNewVersion(prevVersionPreprintId: string) { return this.jsonApiService - .post< - JsonApiResponse< - ApiData, - null - > - >(`${this.apiUrl}/preprints/${prevVersionPreprintId}/versions/`) + .post(`${this.apiUrl}/preprints/${prevVersionPreprintId}/versions/`) .pipe(map((response) => PreprintsMapper.fromPreprintJsonApi(response.data))); } @@ -172,9 +139,7 @@ export class PreprintsService { getPreprintVersionIds(preprintId: string): Observable { return this.jsonApiService - .get< - ResponseJsonApi[]> - >(`${this.apiUrl}/preprints/${preprintId}/versions/`) + .get(`${this.apiUrl}/preprints/${preprintId}/versions/`) .pipe(map((response) => response.data.map((data) => data.id))); } @@ -188,9 +153,7 @@ export class PreprintsService { searchPreferencesToJsonApiQueryParams(params, pageNumber, pageSize, filters, preprintSortFieldMap); return this.jsonApiService - .get< - ResponseJsonApi[]> - >(`${this.apiUrl}/users/me/preprints/`, params) + .get(`${this.apiUrl}/users/me/preprints/`, params) .pipe(map((response) => PreprintsMapper.fromMyPreprintJsonApi(response))); } diff --git a/src/app/features/project/overview/components/link-resource-dialog/link-resource-dialog.component.spec.ts b/src/app/features/project/overview/components/link-resource-dialog/link-resource-dialog.component.spec.ts index eef31eabb..9ee681704 100644 --- a/src/app/features/project/overview/components/link-resource-dialog/link-resource-dialog.component.spec.ts +++ b/src/app/features/project/overview/components/link-resource-dialog/link-resource-dialog.component.spec.ts @@ -10,7 +10,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { SearchInputComponent } from '@osf/shared/components/search-input/search-input.component'; import { ResourceSearchMode } from '@osf/shared/enums/resource-search-mode.enum'; import { ResourceType } from '@osf/shared/enums/resource-type.enum'; -import { MyResourcesItem } from '@osf/shared/models/my-resources/my-resources.model'; +import { MyResourcesItem } from '@osf/shared/models/my-resources/my-resources-item.model'; import { MyResourcesSelectors } from '@osf/shared/stores/my-resources'; import { NodeLinksSelectors } from '@osf/shared/stores/node-links'; diff --git a/src/app/features/project/overview/components/link-resource-dialog/link-resource-dialog.component.ts b/src/app/features/project/overview/components/link-resource-dialog/link-resource-dialog.component.ts index 279a2bc55..4760056f0 100644 --- a/src/app/features/project/overview/components/link-resource-dialog/link-resource-dialog.component.ts +++ b/src/app/features/project/overview/components/link-resource-dialog/link-resource-dialog.component.ts @@ -29,7 +29,7 @@ import { SearchInputComponent } from '@osf/shared/components/search-input/search import { DEFAULT_TABLE_PARAMS } from '@osf/shared/constants/default-table-params.constants'; import { ResourceSearchMode } from '@osf/shared/enums/resource-search-mode.enum'; import { ResourceType } from '@osf/shared/enums/resource-type.enum'; -import { MyResourcesItem } from '@osf/shared/models/my-resources/my-resources.model'; +import { MyResourcesItem } from '@osf/shared/models/my-resources/my-resources-item.model'; import { MyResourcesSearchFilters } from '@osf/shared/models/my-resources/my-resources-search-filters.model'; import { GetMyProjects, GetMyRegistrations, MyResourcesSelectors } from '@osf/shared/stores/my-resources'; import { CreateNodeLink, DeleteNodeLink, NodeLinksSelectors } from '@osf/shared/stores/node-links'; diff --git a/src/app/features/project/overview/mappers/project-overview.mapper.ts b/src/app/features/project/overview/mappers/project-overview.mapper.ts index c6fabdfe8..186b39b44 100644 --- a/src/app/features/project/overview/mappers/project-overview.mapper.ts +++ b/src/app/features/project/overview/mappers/project-overview.mapper.ts @@ -12,16 +12,13 @@ export class ProjectOverviewMapper { ...nodeAttributes, rootParentId: relationships?.root?.data?.id, parentId: relationships?.parent?.data?.id, - forksCount: relationships.forks?.links?.related?.meta - ? (relationships.forks?.links?.related?.meta['count'] as number) + forksCount: relationships?.forks?.links?.related?.meta + ? (relationships?.forks?.links?.related?.meta['count'] as number) : 0, - viewOnlyLinksCount: relationships.view_only_links?.links?.related?.meta - ? (relationships.view_only_links?.links?.related?.meta['count'] as number) + viewOnlyLinksCount: relationships?.view_only_links?.links?.related?.meta + ? (relationships?.view_only_links?.links?.related?.meta['count'] as number) : 0, - links: { - iri: data.links?.iri, - }, - licenseId: relationships.license?.data?.id, + licenseId: relationships?.license?.data?.id, }; } } diff --git a/src/app/features/project/overview/models/project-overview.model.ts b/src/app/features/project/overview/models/project-overview.model.ts index 2c155b330..f1bd65c38 100644 --- a/src/app/features/project/overview/models/project-overview.model.ts +++ b/src/app/features/project/overview/models/project-overview.model.ts @@ -1,12 +1,6 @@ -import { MetaJsonApi } from '@osf/shared/models/common/json-api.model'; import { ContributorModel } from '@osf/shared/models/contributors/contributor.model'; import { BaseNodeModel } from '@osf/shared/models/nodes/base-node.model'; -export interface ProjectOverviewWithMeta { - project: ProjectOverviewModel; - meta?: MetaJsonApi; -} - export interface ProjectOverviewModel extends BaseNodeModel { forksCount: number; viewOnlyLinksCount: number; @@ -14,9 +8,4 @@ export interface ProjectOverviewModel extends BaseNodeModel { rootParentId?: string; licenseId?: string; contributors?: ContributorModel[]; - links: ProjectOverviewLinksModel; -} - -interface ProjectOverviewLinksModel { - iri: string; } diff --git a/src/app/features/project/overview/services/project-overview.service.ts b/src/app/features/project/overview/services/project-overview.service.ts index 7133193be..5a0caba1e 100644 --- a/src/app/features/project/overview/services/project-overview.service.ts +++ b/src/app/features/project/overview/services/project-overview.service.ts @@ -12,7 +12,6 @@ import { LicensesMapper } from '@osf/shared/mappers/licenses.mapper'; import { BaseNodeMapper } from '@osf/shared/mappers/nodes'; import { NodePreprintMapper } from '@osf/shared/mappers/nodes/node-preprint.mapper'; import { NodeStorageMapper } from '@osf/shared/mappers/nodes/node-storage.mapper'; -import { JsonApiResponse } from '@osf/shared/models/common/json-api.model'; import { IdentifiersResponseJsonApi } from '@osf/shared/models/identifiers/identifier-json-api.model'; import { InstitutionsJsonApiResponse } from '@osf/shared/models/institutions/institution-json-api.model'; import { Institution } from '@osf/shared/models/institutions/institutions.model'; @@ -30,7 +29,7 @@ import { IdentifierModel } from '@shared/models/identifiers/identifier.model'; import { LicenseModel } from '@shared/models/license/license.model'; import { ProjectOverviewMapper } from '../mappers'; -import { PrivacyStatusModel, ProjectOverviewWithMeta } from '../models'; +import { PrivacyStatusModel, ProjectOverviewModel } from '../models'; @Injectable({ providedIn: 'root', @@ -43,13 +42,15 @@ export class ProjectOverviewService { return `${this.environment.apiDomainUrl}/v2`; } - getProjectById(projectId: string): Observable { + getProjectById(projectId: string): Observable> { const params: Record = { related_counts: 'forks,view_only_links' }; return this.jsonApiService.get(`${this.apiUrl}/nodes/${projectId}/`, params).pipe( map((response) => ({ - project: ProjectOverviewMapper.getProjectOverview(response.data), - meta: response.meta, + data: ProjectOverviewMapper.getProjectOverview(response.data), + totalCount: 1, + pageSize: 1, + isAnonymous: response.meta?.anonymous ?? false, })) ); } @@ -123,7 +124,7 @@ export class ProjectOverviewService { }; return this.jsonApiService - .post>(`${this.apiUrl}/nodes/`, payload) + .post(`${this.apiUrl}/nodes/`, payload) .pipe(map((response) => BaseNodeMapper.getNodeData(response.data))); } @@ -157,7 +158,7 @@ export class ProjectOverviewService { } return this.jsonApiService - .post>(`${this.apiUrl}/nodes/${projectId}/children/`, payload, params) + .post(`${this.apiUrl}/nodes/${projectId}/children/`, payload, params) .pipe( switchMap((response) => { const componentId = response.data.id; diff --git a/src/app/features/project/overview/store/project-overview.state.ts b/src/app/features/project/overview/store/project-overview.state.ts index 16a944ac1..e8799ccd1 100644 --- a/src/app/features/project/overview/store/project-overview.state.ts +++ b/src/app/features/project/overview/store/project-overview.state.ts @@ -58,11 +58,11 @@ export class ProjectOverviewState { tap((response) => { ctx.patchState({ project: { - data: response.project, + data: response.data, isLoading: false, error: null, }, - isAnonymous: response.meta?.anonymous ?? false, + isAnonymous: response.isAnonymous, }); }), catchError((error) => handleSectionError(ctx, 'project', error)) diff --git a/src/app/features/project/project-addons/project-addons.component.html b/src/app/features/project/project-addons/project-addons.component.html index 3fcf71ec0..4d4691b15 100644 --- a/src/app/features/project/project-addons/project-addons.component.html +++ b/src/app/features/project/project-addons/project-addons.component.html @@ -1,4 +1,4 @@ - +