Skip to content

Commit

Permalink
feature/add query to filter attributes to GetRepositoryAttributesUseC…
Browse files Browse the repository at this point in the history
…ase (#34)

* feat: add query to filter attributes to GetRepositoryAttributesUseCase

* fix: tests

* chore: enable all tests

* chore: move comment to jsdoc and remove unneeded querys

* chore: bump version and update deps

* chore: bump libs

* chore: remove any cast

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Stanislaw Hüll <hdstansen@gmail.com>
Co-authored-by: Stanislaw Hüll <stanislaw.huell@js-soft.com>
Co-authored-by: Julian König <julian.koenig@js-soft.com>
  • Loading branch information
5 people committed Feb 29, 2024
1 parent 8bcf439 commit e94e677
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 9 deletions.
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
Original file line number Diff line number Diff line change
@@ -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
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,6 +13,9 @@ export interface GetOwnSharedAttributesRequest {
onlyValid?: boolean;
query?: GetOwnSharedAttributeRequestQuery;
hideTechnical?: boolean;
/**
* default: true
*/
onlyLatestVersions?: boolean;
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
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,6 +9,9 @@ import { AttributeMapper } from "./AttributeMapper";
export interface GetSharedVersionsOfRepositoryAttributeRequest {
attributeId: AttributeIdString;
peers?: AddressString[];
/**
* default: true
*/
onlyLatestVersions?: boolean;
}

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

Expand Down

0 comments on commit e94e677

Please sign in to comment.