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 all 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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/runtime/package.json
@@ -1,6 +1,6 @@
{
"name": "@nmshd/runtime",
"version": "4.1.5",
"version": "4.2.0",
"description": "The enmeshed client runtime.",
"homepage": "https://enmeshed.eu",
"repository": {
Expand Down
116 changes: 116 additions & 0 deletions packages/runtime/src/useCases/common/Schemas.ts
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
Expand Up @@ -13,6 +13,9 @@ export interface GetOwnSharedAttributesRequest {
onlyValid?: boolean;
query?: GetOwnSharedAttributeRequestQuery;
hideTechnical?: boolean;
/**
* default: true
*/
onlyLatestVersions?: boolean;
}

Expand Down
Expand Up @@ -12,6 +12,9 @@ export interface GetPeerSharedAttributesRequest {
onlyValid?: boolean;
query?: GetPeerSharedAttributesRequestQuery;
hideTechnical?: boolean;
/**
* default: true
*/
onlyLatestVersions?: boolean;
}

Expand Down
@@ -1,12 +1,24 @@
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 {
/**
* default: true
*/
onlyLatestVersions?: boolean;
query?: GetRepositoryAttributesRequestQuery;
}

export interface GetRepositoryAttributesRequestQuery {
createdAt?: string;
"content.tags"?: string | string[];
"content.validFrom"?: string | string[];
"content.validTo"?: string | string[];
"content.value.@type"?: string | string[];
}

export interface GetRepositoryAttributesResponse extends Array<LocalAttributeDTO> {}
Expand All @@ -26,15 +38,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
Expand Up @@ -9,6 +9,9 @@ import { AttributeMapper } from "./AttributeMapper";
export interface GetSharedVersionsOfRepositoryAttributeRequest {
attributeId: AttributeIdString;
peers?: AddressString[];
/**
* default: true
*/
onlyLatestVersions?: boolean;
}

Expand Down
Expand Up @@ -9,6 +9,9 @@ import { AttributeMapper } from "../../consumption";
export interface GetAttributesForRelationshipRequest {
id: RelationshipIdString;
hideTechnical?: boolean;
/**
* default: true
*/
onlyLatestVersions?: boolean;
}

Expand Down