Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
dd712db
Add type-parameter to Envelope and BaseController
sebbi08 Oct 28, 2025
a28c2e0
add type parameter to controller methods return type
sebbi08 Oct 28, 2025
8361289
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Oct 28, 2025
2f9f493
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Oct 29, 2025
bd82292
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Oct 29, 2025
2fe28d1
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Oct 29, 2025
c997efc
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Oct 30, 2025
b7a1403
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Oct 30, 2025
3279245
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 1, 2025
14e6ef6
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 1, 2025
2acaf42
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 3, 2025
2d9ed42
Merge branch 'main' into add-generic-to-envelope
jkoenig134 Nov 3, 2025
b6c4aa6
Merge branch 'main' into add-generic-to-envelope
jkoenig134 Nov 3, 2025
a6a727f
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 4, 2025
d7426fc
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 4, 2025
aad27fc
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 5, 2025
5a53768
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 6, 2025
6050d6b
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 6, 2025
02fe870
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 6, 2025
470c564
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 11, 2025
14c5d63
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 13, 2025
7d95e57
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 14, 2025
98a83b2
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 14, 2025
10ba87c
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 17, 2025
f634201
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 17, 2025
b6136f8
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 18, 2025
6519e84
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 19, 2025
ed3c8aa
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 19, 2025
eb6532d
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 20, 2025
06bc364
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 20, 2025
fa43167
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 20, 2025
9f4f503
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 22, 2025
a83055a
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 22, 2025
dc327a8
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 24, 2025
1999159
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 26, 2025
5bc237d
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 26, 2025
b1ed516
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 28, 2025
c76f534
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 28, 2025
c2db13b
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 28, 2025
0f9a3b5
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Nov 30, 2025
0618e8f
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 1, 2025
8cc7054
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 2, 2025
429369d
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 2, 2025
dca30f2
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 3, 2025
b7d467e
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 3, 2025
82ebfee
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 4, 2025
ad178a8
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 5, 2025
66f0ff5
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 8, 2025
3af887d
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 9, 2025
c3d4c3a
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 9, 2025
f9a991e
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 10, 2025
20539dd
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 10, 2025
54dca57
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 11, 2025
368d87f
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 11, 2025
93f6a67
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 11, 2025
f49b673
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 12, 2025
af59a54
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 12, 2025
43a053b
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 12, 2025
3055a5b
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 13, 2025
0c824cd
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 14, 2025
7197f5e
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 15, 2025
66ecb26
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 16, 2025
cd453ba
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 17, 2025
e6f074d
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 19, 2025
17c6eb0
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Dec 20, 2025
093ac9c
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 7, 2026
561273d
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 7, 2026
944791a
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 7, 2026
2c2b83f
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 9, 2026
23b6922
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 12, 2026
f1c62af
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 12, 2026
1568f95
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 13, 2026
80245f0
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 14, 2026
986f901
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 15, 2026
34d2f5f
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 15, 2026
d4b607a
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 21, 2026
a3574c7
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 22, 2026
a801409
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 22, 2026
e7d1495
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 22, 2026
774e903
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 23, 2026
b798278
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 23, 2026
28733d3
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 24, 2026
906d4b3
Merge branch 'main' into add-generic-to-envelope
mergify[bot] Jan 25, 2026
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
12 changes: 6 additions & 6 deletions packages/types/src/infrastructure/httpServer/BaseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import { Envelope } from "./common/Envelope";
import { Mimetype } from "./common/Mimetype";

export abstract class BaseController {
protected created<T>(result: Result<T>): Return.NewResource<Envelope> {
return new Return.NewResource<Envelope>("_", this.json<T>(result));
protected created<T>(result: Result<T>): Return.NewResource<Envelope<T>> {
return new Return.NewResource<Envelope<T>>("_", this.json<T>(result));
}

protected ok<T>(result: Result<T>): Envelope {
return this.json(result);
protected ok<T>(result: Result<T>): Envelope<T> {
return this.json<T>(result);
}

protected noContent<T>(result: Result<T>): void {
this.guard(result);
this.guard<T>(result);
return;
}

private json<T>(result: Result<T>): Envelope {
private json<T>(result: Result<T>): Envelope<T> {
this.guard(result);
return Envelope.ok(result.value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ConnectorMode } from "../../../ConnectorMode";
import { HttpError, HttpErrorJSON } from "./HttpError";

export class Envelope {
export class Envelope<T> {
protected constructor(
public result?: any,
public result?: T,
public error?: HttpErrorJSON
) {}

public static ok(result: any): Envelope {
public static ok<T>(result: T): Envelope<T> {
return new Envelope(result, undefined);
}

public static error(error: HttpError, connectorMode: ConnectorMode): Envelope {
public static error(error: HttpError, connectorMode: ConnectorMode): Envelope<undefined> {
switch (connectorMode) {
case "debug":
return new Envelope(undefined, error.toJSON("verbose"));
Expand Down
6 changes: 3 additions & 3 deletions src/modules/coreHttpApi/controllers/AccountController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseController, Envelope } from "@nmshd/connector-types";
import { TransportServices } from "@nmshd/runtime";
import { GetIdentityInfoResponse, SyncInfo, TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, GET, Path, POST, Security } from "@nmshd/typescript-rest";

Expand All @@ -13,7 +13,7 @@ export class AccountController extends BaseController {
@GET
@Path("/IdentityInfo")
@Accept("application/json")
public async getIdentityInfo(): Promise<Envelope> {
public async getIdentityInfo(): Promise<Envelope<GetIdentityInfoResponse>> {
const result = await this.transportServices.account.getIdentityInfo();
return this.ok(result);
}
Expand All @@ -30,7 +30,7 @@ export class AccountController extends BaseController {
@GET
@Path("/SyncInfo")
@Accept("application/json")
public async getSyncInfo(): Promise<Envelope> {
public async getSyncInfo(): Promise<Envelope<SyncInfo>> {
const result = await this.transportServices.account.getSyncInfo();
return this.ok(result);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseController, Envelope } from "@nmshd/connector-types";
import { TransportServices } from "@nmshd/runtime";
import { AnnouncementDTO, TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, GET, Path, QueryParam, Security } from "@nmshd/typescript-rest";

Expand All @@ -12,7 +12,7 @@ export class AnnouncementsController extends BaseController {

@GET
@Accept("application/json")
public async getAnnouncements(@QueryParam("language") language: string): Promise<Envelope> {
public async getAnnouncements(@QueryParam("language") language: string): Promise<Envelope<AnnouncementDTO[]>> {
const result = await this.transportServices.announcements.getAnnouncements({ language: language as any });
return this.ok(result);
}
Expand Down
63 changes: 42 additions & 21 deletions src/modules/coreHttpApi/controllers/AttributesController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { BaseController, Envelope } from "@nmshd/connector-types";
import { ConsumptionServices, RuntimeErrors } from "@nmshd/runtime";
import {
AttributeTagCollectionDTO,
CanCreateOwnIdentityAttributeResponse,
ConsumptionServices,
DeleteAttributeAndNotifyResponse,
LocalAttributeDTO,
LocalAttributeForwardingDetailsDTO,
NotifyPeerAboutOwnIdentityAttributeSuccessionResponse,
RuntimeErrors,
SucceedOwnIdentityAttributeResponse,
SucceedRelationshipAttributeAndNotifyPeerResponse,
ValidateIQLQueryResponse
} from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Context, DELETE, GET, POST, PUT, Path, PathParam, QueryParam, Return, Security, ServiceContext } from "@nmshd/typescript-rest";
import { Accept, Context, DELETE, GET, Path, PathParam, POST, PUT, QueryParam, Return, Security, ServiceContext } from "@nmshd/typescript-rest";

@Security("core:attributes")
@Path("/api/core/v1/Attributes")
Expand All @@ -13,22 +25,25 @@ export class AttributesController extends BaseController {
@PUT
@Path("CanCreate")
@Accept("application/json")
public async canCreateOwnIdentityAttribute(request: any): Promise<Envelope> {
public async canCreateOwnIdentityAttribute(request: any): Promise<Envelope<CanCreateOwnIdentityAttributeResponse>> {
const result = await this.consumptionServices.attributes.canCreateOwnIdentityAttribute(request);
return this.ok(result);
}

@POST
@Accept("application/json")
public async createOwnIdentityAttribute(request: any): Promise<Return.NewResource<Envelope>> {
public async createOwnIdentityAttribute(request: any): Promise<Return.NewResource<Envelope<LocalAttributeDTO>>> {
const result = await this.consumptionServices.attributes.createOwnIdentityAttribute(request);
return this.created(result);
}

@POST
@Path("/:predecessorId/Succeed")
@Accept("application/json")
public async succeedAttribute(@PathParam("predecessorId") predecessorId: string, request: any): Promise<Return.NewResource<Envelope>> {
public async succeedAttribute(
@PathParam("predecessorId") predecessorId: string,
request: any
): Promise<Return.NewResource<Envelope<SucceedOwnIdentityAttributeResponse | SucceedRelationshipAttributeAndNotifyPeerResponse>>> {
const result = await this.consumptionServices.attributes.getAttribute({ id: predecessorId });
if (result.isError) {
throw RuntimeErrors.general.recordNotFoundWithMessage(`Predecessor attribute '${predecessorId}' not found.`);
Expand All @@ -54,22 +69,28 @@ export class AttributesController extends BaseController {
@POST
@Path("/:id/NotifyPeer")
@Accept("application/json")
public async notifyPeerAboutOwnIdentityAttributeSuccession(@PathParam("id") attributeId: string, request: any): Promise<Return.NewResource<Envelope>> {
public async notifyPeerAboutOwnIdentityAttributeSuccession(
@PathParam("id") attributeId: string,
request: any
): Promise<Return.NewResource<Envelope<NotifyPeerAboutOwnIdentityAttributeSuccessionResponse>>> {
const result = await this.consumptionServices.attributes.notifyPeerAboutOwnIdentityAttributeSuccession({ attributeId: attributeId, peer: request.peer });
return this.created(result);
}

@GET
@Accept("application/json")
public async getAttributes(@Context context: ServiceContext): Promise<Envelope> {
public async getAttributes(@Context context: ServiceContext): Promise<Envelope<LocalAttributeDTO[]>> {
const result = await this.consumptionServices.attributes.getAttributes({ query: context.request.query });
return this.ok(result);
}

@GET
@Path("/Own/Identity")
@Accept("application/json")
public async getOwnIdentityAttributes(@Context context: ServiceContext, @QueryParam("onlyLatestVersions") onlyLatestVersions?: boolean): Promise<Envelope> {
public async getOwnIdentityAttributes(
@Context context: ServiceContext,
@QueryParam("onlyLatestVersions") onlyLatestVersions?: boolean
): Promise<Envelope<LocalAttributeDTO[]>> {
const query: Record<string, any> = this.extractQuery(context.request.query, ["onlyLatestVersions"]);
const result = await this.consumptionServices.attributes.getOwnIdentityAttributes({ onlyLatestVersions, query });
return this.ok(result);
Expand All @@ -83,7 +104,7 @@ export class AttributesController extends BaseController {
@PathParam("peer") peer: string,
@QueryParam("onlyLatestVersions") onlyLatestVersions?: boolean,
@QueryParam("hideTechnical") hideTechnical?: boolean
): Promise<Envelope> {
): Promise<Envelope<LocalAttributeDTO[]>> {
const query: Record<string, any> = this.extractQuery(context.request.query, ["onlyLatestVersions", "hideTechnical"]);
const result = await this.consumptionServices.attributes.getOwnAttributesSharedWithPeer({ peer, onlyLatestVersions, hideTechnical, query });
return this.ok(result);
Expand All @@ -97,7 +118,7 @@ export class AttributesController extends BaseController {
@PathParam("peer") peer: string,
@QueryParam("onlyLatestVersions") onlyLatestVersions?: boolean,
@QueryParam("hideTechnical") hideTechnical?: boolean
): Promise<Envelope> {
): Promise<Envelope<LocalAttributeDTO[]>> {
const query: Record<string, any> = this.extractQuery(context.request.query, ["onlyLatestVersions", "hideTechnical"]);
const result = await this.consumptionServices.attributes.getPeerAttributes({ peer, onlyLatestVersions, hideTechnical, query });
return this.ok(result);
Expand All @@ -106,15 +127,15 @@ export class AttributesController extends BaseController {
@GET
@Path("/:id/ForwardingDetails")
@Accept("application/json")
public async getForwardingDetailsForAttribute(@Context context: ServiceContext, @PathParam("id") attributeId: string): Promise<Envelope> {
public async getForwardingDetailsForAttribute(@Context context: ServiceContext, @PathParam("id") attributeId: string): Promise<Envelope<LocalAttributeForwardingDetailsDTO[]>> {
const result = await this.consumptionServices.attributes.getForwardingDetailsForAttribute({ attributeId, query: context.request.query });
return this.ok(result);
}

@GET
@Path("/:id/Versions")
@Accept("application/json")
public async getVersionsOfAttribute(@PathParam("id") attributeId: string): Promise<Envelope> {
public async getVersionsOfAttribute(@PathParam("id") attributeId: string): Promise<Envelope<LocalAttributeDTO[]>> {
const result = await this.consumptionServices.attributes.getVersionsOfAttribute({
attributeId
});
Expand All @@ -128,70 +149,70 @@ export class AttributesController extends BaseController {
@PathParam("id") attributeId: string,
@QueryParam("peer") peer: string,
@QueryParam("onlyLatestVersions") onlyLatestVersions?: boolean
): Promise<Envelope> {
): Promise<Envelope<LocalAttributeDTO[]>> {
const result = await this.consumptionServices.attributes.getVersionsOfAttributeSharedWithPeer({ attributeId, onlyLatestVersions, peer });
return this.ok(result);
}

@GET
@Path("/TagCollection")
@Accept("application/json")
public async getAttributeTagCollection(): Promise<Envelope> {
public async getAttributeTagCollection(): Promise<Envelope<AttributeTagCollectionDTO>> {
const result = await this.consumptionServices.attributes.getAttributeTagCollection();
return this.ok(result);
}

@POST
@Path("/ExecuteIdentityAttributeQuery")
@Accept("application/json")
public async executeIdentityAttributeQuery(request: any): Promise<Envelope> {
public async executeIdentityAttributeQuery(request: any): Promise<Envelope<LocalAttributeDTO[]>> {
const result = await this.consumptionServices.attributes.executeIdentityAttributeQuery(request);
return this.ok(result);
}

@POST
@Path("/ExecuteRelationshipAttributeQuery")
@Accept("application/json")
public async executeRelationshipAttributeQuery(request: any): Promise<Envelope> {
public async executeRelationshipAttributeQuery(request: any): Promise<Envelope<LocalAttributeDTO>> {
const result = await this.consumptionServices.attributes.executeRelationshipAttributeQuery(request);
return this.ok(result);
}

@POST
@Path("/ExecuteThirdPartyRelationshipAttributeQuery")
@Accept("application/json")
public async executeThirdPartyRelationshipAttributeQuery(request: any): Promise<Envelope> {
public async executeThirdPartyRelationshipAttributeQuery(request: any): Promise<Envelope<LocalAttributeDTO[]>> {
const result = await this.consumptionServices.attributes.executeThirdPartyRelationshipAttributeQuery(request);
return this.ok(result);
}

@POST
@Path("/ExecuteIQLQuery")
@Accept("application/json")
public async executeIQLQuery(request: any): Promise<Envelope> {
public async executeIQLQuery(request: any): Promise<Envelope<LocalAttributeDTO[]>> {
const result = await this.consumptionServices.attributes.executeIQLQuery(request);
return this.ok(result);
}

@POST
@Path("/ValidateIQLQuery")
@Accept("application/json")
public async validateIQLQuery(request: any): Promise<Envelope> {
public async validateIQLQuery(request: any): Promise<Envelope<ValidateIQLQueryResponse>> {
const result = await this.consumptionServices.attributes.validateIQLQuery(request);
return this.ok(result);
}

@GET
@Path("/:id")
@Accept("application/json")
public async getAttribute(@PathParam("id") id: string): Promise<Envelope> {
public async getAttribute(@PathParam("id") id: string): Promise<Envelope<LocalAttributeDTO>> {
const result = await this.consumptionServices.attributes.getAttribute({ id });
return this.ok(result);
}

@DELETE
@Path(":id")
public async deleteAttributeAndNotify(@PathParam("id") attributeId: string): Promise<Envelope> {
public async deleteAttributeAndNotify(@PathParam("id") attributeId: string): Promise<Envelope<DeleteAttributeAndNotifyResponse>> {
const result = await this.consumptionServices.attributes.deleteAttributeAndNotify({ attributeId });
return this.ok(result);
}
Expand Down
6 changes: 3 additions & 3 deletions src/modules/coreHttpApi/controllers/ChallengesController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseController, Envelope } from "@nmshd/connector-types";
import { TransportServices } from "@nmshd/runtime";
import { ChallengeDTO, TransportServices, ValidateChallengeResponse } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import { Accept, Path, POST, Return, Security } from "@nmshd/typescript-rest";

Expand All @@ -12,15 +12,15 @@ export class ChallengesController extends BaseController {

@POST
@Accept("application/json")
public async createChallenge(request: any): Promise<Return.NewResource<Envelope>> {
public async createChallenge(request: any): Promise<Return.NewResource<Envelope<ChallengeDTO>>> {
const result = await this.transportServices.challenges.createChallenge(request);
return this.created(result);
}

@POST
@Path("/Validate")
@Accept("application/json")
public async validateChallenge(request: any): Promise<Envelope> {
public async validateChallenge(request: any): Promise<Envelope<ValidateChallengeResponse>> {
const result = await this.transportServices.challenges.validateChallenge(request);
return this.ok(result);
}
Expand Down
22 changes: 13 additions & 9 deletions src/modules/coreHttpApi/controllers/FilesController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseController, Envelope, Mimetype } from "@nmshd/connector-types";
import { Reference } from "@nmshd/core-types";
import { OwnerRestriction, TransportServices } from "@nmshd/runtime";
import { FileDTO, OwnerRestriction, TokenDTO, TransportServices } from "@nmshd/runtime";
import { Inject } from "@nmshd/typescript-ioc";
import {
Accept,
Expand Down Expand Up @@ -37,7 +37,7 @@ export class FilesController extends BaseController {
@FileParam("file") file?: Express.Multer.File,
@FormParam("description") description?: string,
@FormParam("tags") tags?: string[]
): Promise<Return.NewResource<Envelope>> {
): Promise<Return.NewResource<Envelope<FileDTO>>> {
const result = await this.transportServices.files.uploadOwnFile({
content: file?.buffer,
expiresAt,
Expand All @@ -53,7 +53,7 @@ export class FilesController extends BaseController {
@POST
@Path("/Peer")
@Accept("application/json")
public async loadPeerFile(request: any): Promise<Return.NewResource<Envelope>> {
public async loadPeerFile(request: any): Promise<Return.NewResource<Envelope<FileDTO>>> {
const result = await this.transportServices.files.getOrLoadFile(request);
return this.created(result);
}
Expand All @@ -75,31 +75,35 @@ export class FilesController extends BaseController {

@GET
@Accept("application/json")
public async getFiles(@Context context: ServiceContext): Promise<Envelope> {
public async getFiles(@Context context: ServiceContext): Promise<Envelope<FileDTO[]>> {
const result = await this.transportServices.files.getFiles({ query: context.request.query });
return this.ok(result);
}

@GET
@Path("/Own")
@Accept("application/json")
public async getOwnFiles(@Context context: ServiceContext): Promise<Envelope> {
public async getOwnFiles(@Context context: ServiceContext): Promise<Envelope<FileDTO[]>> {
const result = await this.transportServices.files.getFiles({ query: context.request.query, ownerRestriction: OwnerRestriction.Own });
return this.ok(result);
}

@GET
@Path("/Peer")
@Accept("application/json")
public async getPeerFiles(@Context context: ServiceContext): Promise<Envelope> {
public async getPeerFiles(@Context context: ServiceContext): Promise<Envelope<FileDTO[]>> {
const result = await this.transportServices.files.getFiles({ query: context.request.query, ownerRestriction: OwnerRestriction.Peer });
return this.ok(result);
}

@GET
@Path("/:idOrReference")
@Accept("application/json", "image/png")
public async getFile(@PathParam("idOrReference") idOrReference: string, @ContextAccept accept: string, @ContextResponse response: express.Response): Promise<Envelope | void> {
public async getFile(
@PathParam("idOrReference") idOrReference: string,
@ContextAccept accept: string,
@ContextResponse response: express.Response
): Promise<Envelope<FileDTO> | void> {
const fileId = idOrReference.startsWith("FIL") ? idOrReference : Reference.from(idOrReference).id.toString();

const result = await this.transportServices.files.getFile({ id: fileId });
Expand All @@ -120,7 +124,7 @@ export class FilesController extends BaseController {
@ContextAccept accept: string,
@ContextResponse response: express.Response,
request: any
): Promise<Return.NewResource<Envelope> | void> {
): Promise<Return.NewResource<Envelope<TokenDTO>> | void> {
const result = await this.transportServices.files.createTokenForFile({
fileId: id,
expiresAt: request.expiresAt,
Expand All @@ -146,7 +150,7 @@ export class FilesController extends BaseController {

@PATCH
@Path("/:id/RegenerateOwnershipToken")
public async regenerateOwnershipToken(@PathParam("id") id: string): Promise<Envelope> {
public async regenerateOwnershipToken(@PathParam("id") id: string): Promise<Envelope<FileDTO>> {
const result = await this.transportServices.files.regenerateFileOwnershipToken({ id });
return this.ok(result);
}
Expand Down
Loading
Loading