Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feature/add query to filter attributes to GetRepositoryAttributesUseCase #34

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
116 changes: 116 additions & 0 deletions packages/runtime/src/useCases/common/Schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16946,6 +16946,122 @@ export const GetRepositoryAttributesRequest: any = {
"properties": {
"onlyLatestVersions": {
"type": "boolean"
},
"query": {
"$ref": "#/definitions/GetRepositoryAttributesRequestQuery"
}
},
"additionalProperties": false
},
"GetRepositoryAttributesRequestQuery": {
"type": "object",
"properties": {
"createdAt": {
"type": "string"
},
"content.@type": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"content.tags": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"content.validFrom": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"content.validTo": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"content.key": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"content.isTechnical": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"content.confidentiality": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"content.value.@type": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
},
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface GetOwnSharedAttributesRequest {
onlyValid?: boolean;
query?: GetOwnSharedAttributeRequestQuery;
hideTechnical?: boolean;
onlyLatestVersions?: boolean;
onlyLatestVersions?: boolean; // default: true
}

export interface GetOwnSharedAttributeRequestQuery {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface GetPeerSharedAttributesRequest {
onlyValid?: boolean;
query?: GetPeerSharedAttributesRequestQuery;
hideTechnical?: boolean;
onlyLatestVersions?: boolean;
onlyLatestVersions?: boolean; // default: true
}

export interface GetPeerSharedAttributesRequestQuery {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { Result } from "@js-soft/ts-utils";
import { AttributesController } from "@nmshd/consumption";
import { Inject } from "typescript-ioc";
import { AttributeMapper } from "..";
import { AttributeMapper, GetAttributesRequestQuery, GetAttributesUseCase } from "..";
import { LocalAttributeDTO } from "../../../types";
import { SchemaRepository, SchemaValidator, UseCase } from "../../common";
import { SchemaRepository, SchemaValidator, UseCase, flattenObject } from "../../common";

export interface GetRepositoryAttributesRequest {
onlyLatestVersions?: boolean;
onlyLatestVersions?: boolean; // default: true
query?: GetRepositoryAttributesRequestQuery;
}

export interface GetRepositoryAttributesRequestQuery {
createdAt?: string;
"content.@type"?: string | string[];
jkoenig134 marked this conversation as resolved.
Show resolved Hide resolved
"content.tags"?: string | string[];
"content.validFrom"?: string | string[];
"content.validTo"?: string | string[];
"content.key"?: string | string[];
jkoenig134 marked this conversation as resolved.
Show resolved Hide resolved
"content.isTechnical"?: string | string[];
"content.confidentiality"?: string | string[];
"content.value.@type"?: string | string[];
}

export interface GetRepositoryAttributesResponse extends Array<LocalAttributeDTO> {}
Expand All @@ -26,15 +39,16 @@ export class GetRepositoryAttributesUseCase extends UseCase<GetRepositoryAttribu
}

protected async executeInternal(request: GetRepositoryAttributesRequest): Promise<Result<GetRepositoryAttributesResponse>> {
const query: any = {
shareInfo: { $exists: false }
};
const query: GetAttributesRequestQuery = request.query ?? {};
const flattenedQuery = flattenObject(query);
const dbQuery = GetAttributesUseCase.queryTranslator.parse(flattenedQuery);
jkoenig134 marked this conversation as resolved.
Show resolved Hide resolved
dbQuery.shareInfo = { $exists: false };

if (typeof request.onlyLatestVersions === "undefined" || request.onlyLatestVersions) {
query["succeededBy"] = { $exists: false };
dbQuery["succeededBy"] = { $exists: false };
}

const attributes = await this.attributesController.getLocalAttributes(query);
const attributes = await this.attributesController.getLocalAttributes(dbQuery);

return Result.ok(AttributeMapper.toAttributeDTOList(attributes));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AttributeMapper } from "./AttributeMapper";
export interface GetSharedVersionsOfRepositoryAttributeRequest {
attributeId: AttributeIdString;
peers?: AddressString[];
onlyLatestVersions?: boolean;
onlyLatestVersions?: boolean; // default: true
}

class Validator extends SchemaValidator<GetSharedVersionsOfRepositoryAttributeRequest> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AttributeMapper } from "../../consumption";
export interface GetAttributesForRelationshipRequest {
id: RelationshipIdString;
hideTechnical?: boolean;
onlyLatestVersions?: boolean;
onlyLatestVersions?: boolean; // default: true
}

export interface GetAttributesForRelationshipResponse extends Array<LocalAttributeDTO> {}
Expand Down