Skip to content

Commit

Permalink
fix: handle possibly undefined requests
Browse files Browse the repository at this point in the history
  • Loading branch information
slavistan committed Dec 20, 2023
1 parent 076e687 commit 48d6ddb
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/modules/coreHttpApi/controllers/AttributesController.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { ConsumptionServices, TransportServices } from "@nmshd/runtime";
import { ConsumptionServices } from "@nmshd/runtime";
import { Inject } from "typescript-ioc";
import { Accept, Context, GET, POST, Path, PathParam, Return, ServiceContext } from "typescript-rest";
import { Envelope } from "../../../infrastructure";
import { BaseController } from "../common/BaseController";

@Path("/api/v2/Attributes")
export class AttributesController extends BaseController {
public constructor(
@Inject private readonly transportServices: TransportServices,
@Inject private readonly consumptionServices: ConsumptionServices
) {
public constructor(@Inject private readonly consumptionServices: ConsumptionServices) {
super();
}

Expand All @@ -19,8 +16,8 @@ export class AttributesController extends BaseController {
/* We left 'owner' and '@type' optional in the openapi spec for
* backwards compatibility. If set, they have to be removed here or the runtime
* use case will throw an error. */
if (typeof request.content?.owner !== "undefined") delete request.content.owner;
if (request.content?.["@type"] === "IdentityAttribute") delete request.content["@type"];
if (typeof request?.content?.owner !== "undefined") delete request.content.owner;
if (request?.content?.["@type"] === "IdentityAttribute") delete request.content["@type"];

const result = await this.consumptionServices.attributes.createIdentityAttribute(request);
return this.created(result);
Expand Down Expand Up @@ -54,7 +51,7 @@ export class AttributesController extends BaseController {
@Path("/SucceedAttribute")
@Accept("application/json")
public async succeedAttribute(request: any): Promise<Return.NewResource<Envelope>> {
const predecessorResult = await this.consumptionServices.attributes.getAttribute(request.predecessorId);
const predecessorResult = await this.consumptionServices.attributes.getAttribute(request?.predecessorId);
const predecessor = predecessorResult.value;
let result: any;
if (predecessor.content["@type"] === "IdentityAttribute") {
Expand Down

0 comments on commit 48d6ddb

Please sign in to comment.