Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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,
}));
}

Expand All @@ -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,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ import {
InstitutionIndexValueSearchIncludedJsonApi,
InstitutionSearchFilter,
InstitutionSearchResultCountJsonApi,
} from '@osf/features/admin-institutions/models';
} from '../models';

export function mapIndexCardResults(
included: InstitutionIndexValueSearchIncludedJsonApi[] | undefined
): InstitutionSearchFilter[] {
if (!included) {
return [];
}

export function mapIndexCardResults(included: InstitutionIndexValueSearchIncludedJsonApi[]): InstitutionSearchFilter[] {
const indexCardMap = included.reduce(
(acc, item) => {
if (item.type === 'index-card') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export interface InstitutionDepartment {
id: string;
name: string;
numberOfUsers: number;
selfLink: string;
}
Original file line number Diff line number Diff line change
@@ -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<InstitutionDepartmentDataJsonApi>;

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;
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
import { JsonApiResponse } from '@shared/models/common/json-api.model';
import { ToOneRelData } from '@osf/shared/models/common/json-api/relationships.model';
import { JsonApiResource } from '@osf/shared/models/common/json-api/resource.model';
import { JsonApiResponse } from '@osf/shared/models/common/json-api/responses.model';

export interface InstitutionSearchResultCountJsonApi {
attributes: {
cardSearchResultCount: number;
};
id: string;
type: string;
relationships: {
indexCard: {
data: {
id: string;
type: string;
};
};
};
export type InstitutionIndexValueSearchIncludedJsonApi =
| InstitutionSearchResultCountJsonApi
| InstitutionIndexCardFilterJsonApi;

export type InstitutionIndexValueSearchJsonApi = JsonApiResponse<null, InstitutionIndexValueSearchIncludedJsonApi[]>;
export type InstitutionIndexCardFilterJsonApi = JsonApiResource<'index-card', InstitutionIndexCardAttributesJsonApi>;

interface InstitutionIndexCardResourceMetadataJsonApi {
'@id': string;
displayLabel?: { '@value': string }[];
name: { '@value': string }[];
}

export interface InstitutionIndexCardFilterJsonApi {
attributes: {
resourceIdentifier: string[];
resourceMetadata: {
displayLabel: { '@value': string }[];
'@id': string;
name: { '@value': string }[];
};
};
id: string;
type: string;
interface InstitutionIndexCardAttributesJsonApi {
resourceIdentifier: string[];
resourceMetadata: InstitutionIndexCardResourceMetadataJsonApi;
}

export type InstitutionIndexValueSearchIncludedJsonApi =
| InstitutionSearchResultCountJsonApi
| InstitutionIndexCardFilterJsonApi;
interface InstitutionSearchResultAttributesJsonApi {
cardSearchResultCount: number;
}

interface InstitutionSearchResultRelationshipsJsonApi {
indexCard: ToOneRelData;
}

export interface InstitutionIndexValueSearchJsonApi extends JsonApiResponse<
null,
InstitutionIndexValueSearchIncludedJsonApi[]
export interface InstitutionSearchResultCountJsonApi extends Omit<
JsonApiResource<string, InstitutionSearchResultAttributesJsonApi>,
'attributes'
> {
data: null;
included: InstitutionIndexValueSearchIncludedJsonApi[];
attributes?: InstitutionSearchResultAttributesJsonApi;
relationships: InstitutionSearchResultRelationshipsJsonApi;
}
Original file line number Diff line number Diff line change
@@ -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<InstitutionSummaryMetricsDataJsonApi>;

export type InstitutionSummaryMetricsDataJsonApi = JsonApiResource<
'institution-summary-metrics',
InstitutionSummaryMetricsAttributesJsonApi
>;

export interface InstitutionSummaryMetricsAttributesJsonApi {
report_yearmonth: string;
user_count: number;
Expand All @@ -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<string, unknown>;
};
};
data: {
id: string;
type: 'institutions';
};
};
}

export interface InstitutionSummaryMetricsDataJsonApi {
id: string;
type: 'institution-summary-metrics';
attributes: InstitutionSummaryMetricsAttributesJsonApi;
relationships: InstitutionSummaryMetricsRelationshipsJsonApi;
links: Record<string, unknown>;
}

export interface InstitutionSummaryMetricsJsonApi {
data: InstitutionSummaryMetricsDataJsonApi;
meta: {
version: string;
};
}
Original file line number Diff line number Diff line change
@@ -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<InstitutionUserDataJsonApi>;

export interface InstitutionUserDataJsonApi extends JsonApiResource<
'institution-users',
InstitutionUserAttributesJsonApi
> {
relationships: InstitutionUserRelationshipsJsonApi;
}

interface InstitutionUserAttributesJsonApi {
user_name: string;
department: string | null;
orcid_id: string | null;
Expand All @@ -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<string, unknown>;
}

export interface InstitutionUsersJsonApi {
data: InstitutionUserDataJsonApi[];
meta: MetaJsonApi;
interface InstitutionUserRelationshipsJsonApi {
user: ToOneRel<'user'>;
institution: ToOneRel<'institution'>;
}
Original file line number Diff line number Diff line change
@@ -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<SendMessageDataJsonApi>;

export type SendMessageDataJsonApi = JsonApiResource<'send-message', SendMessageAttributesJsonApi>;

interface SendMessageAttributesJsonApi {
message_text: string;
message_type: string;
bcc_sender: boolean;
reply_to: boolean;
}
10 changes: 5 additions & 5 deletions src/app/features/analytics/mappers/related-counts.mapper.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}
}
19 changes: 8 additions & 11 deletions src/app/features/analytics/models/node-analytics-json-api.model.ts
Original file line number Diff line number Diff line change
@@ -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<NodeAnalyticsDataJsonApi>;
export type NodeAnalyticsResponseJsonApi = ItemResponse<NodeAnalyticsDataJsonApi>;

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;
}
Expand Down
Loading
Loading