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

style(examples): 2021-09-20 linter warnings batch 17 / 26; part 2 #2425

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BambooHarvest } from "../../generated/openapi/typescript-axios";
import { RuntimeError } from "run-time-error";

/**
* Responsible for converting model entities such as the `BambooHarvest` to and
Expand All @@ -21,17 +22,44 @@ export class BambooHarvestConverter {
* @param arr The array containing the values of properties describing a
* `BambooHarvest` model entity.
*/
public static ofSolidityStruct(arr: any[]): BambooHarvest {
public static ofSolidityStruct(arr: unknown[]): BambooHarvest {
const id = arr[BambooHarvestConverter.SOLIDITY_FIELD_ID];
if (typeof id !== "string") {
const errMsg = `Expected the value of arr[${BambooHarvestConverter.SOLIDITY_FIELD_ID}] to be a string`;
throw new RuntimeError(errMsg);
}
const location = arr[BambooHarvestConverter.SOLIDITY_FIELD_LOCATION];
if (typeof location !== "string") {
const errMsg = `Expected the value of arr[${BambooHarvestConverter.SOLIDITY_FIELD_LOCATION}] to be a string`;
throw new RuntimeError(errMsg);
}
const startedAt = arr[BambooHarvestConverter.SOLIDITY_FIELD_STARTED_AT];
if (typeof startedAt !== "string") {
const errMsg = `Expected the value of arr[${BambooHarvestConverter.SOLIDITY_FIELD_STARTED_AT}] to be a string`;
throw new RuntimeError(errMsg);
}
const endedAt = arr[BambooHarvestConverter.SOLIDITY_FIELD_ENDED_AT];
if (typeof endedAt !== "string") {
const errMsg = `Expected the value of arr[${BambooHarvestConverter.SOLIDITY_FIELD_ENDED_AT}] to be a string`;
throw new RuntimeError(errMsg);
}
const harvester = arr[BambooHarvestConverter.SOLIDITY_FIELD_HARVESTER];
if (typeof harvester !== "string") {
const errMsg = `Expected the value of arr[${BambooHarvestConverter.SOLIDITY_FIELD_HARVESTER}] to be a string`;
throw new RuntimeError(errMsg);
}
return {
id: arr[BambooHarvestConverter.SOLIDITY_FIELD_ID],
location: arr[BambooHarvestConverter.SOLIDITY_FIELD_LOCATION],
startedAt: arr[BambooHarvestConverter.SOLIDITY_FIELD_STARTED_AT],
endedAt: arr[BambooHarvestConverter.SOLIDITY_FIELD_ENDED_AT],
harvester: arr[BambooHarvestConverter.SOLIDITY_FIELD_HARVESTER],
id,
location,
startedAt,
endedAt,
harvester,
};
}

public static ofSolidityStructList(arrayOfArrays: any[][]): BambooHarvest[] {
public static ofSolidityStructList(
arrayOfArrays: unknown[][],
): BambooHarvest[] {
return arrayOfArrays.map(BambooHarvestConverter.ofSolidityStruct);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Bookshelf } from "../../generated/openapi/typescript-axios/index";
import { RuntimeError } from "run-time-error";

/**
* Responsible for converting model entities such as the `Bookshelf` to and
Expand All @@ -19,15 +20,31 @@ export class BookshelfConverter {
* @param arr The array containing the values of properties describing a
* `Bookshelf` model entity.
*/
public static ofSolidityStruct(arr: any[]): Bookshelf {
public static ofSolidityStruct(arr: unknown[]): Bookshelf {
const id = arr[BookshelfConverter.SOLIDITY_FIELD_ID];
if (typeof id !== "string") {
const errMsg = `Expected the value of arr[${BookshelfConverter.SOLIDITY_FIELD_ID}] to be a string`;
throw new RuntimeError(errMsg);
}
const shelfCount = arr[BookshelfConverter.SOLIDITY_FIELD_SHELF_COUNT];
if (typeof shelfCount !== "number") {
const errMsg = `Expected the value of arr[${BookshelfConverter.SOLIDITY_FIELD_SHELF_COUNT}] to be a number`;
throw new RuntimeError(errMsg);
}
const bambooHarvestId =
arr[BookshelfConverter.SOLIDITY_FIELD_BAMBOO_HARVEST_ID];
if (typeof bambooHarvestId !== "string") {
const errMsg = `Expected the value of arr[${BookshelfConverter.SOLIDITY_FIELD_BAMBOO_HARVEST_ID}] to be a string`;
throw new RuntimeError(errMsg);
}
return {
id: arr[BookshelfConverter.SOLIDITY_FIELD_ID],
shelfCount: arr[BookshelfConverter.SOLIDITY_FIELD_SHELF_COUNT],
bambooHarvestId: arr[BookshelfConverter.SOLIDITY_FIELD_BAMBOO_HARVEST_ID],
id,
shelfCount,
bambooHarvestId,
};
}

public static ofSolidityStructList(arrayOfArrays: any[][]): Bookshelf[] {
public static ofSolidityStructList(arrayOfArrays: unknown[][]): Bookshelf[] {
return arrayOfArrays.map(BookshelfConverter.ofSolidityStruct);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { v4 as uuidv4 } from "uuid";
import { RuntimeError } from "run-time-error";

import { Component, Inject, Input, OnInit } from "@angular/core";
import { FormGroup, FormBuilder, Validators } from "@angular/forms";
import { ModalController } from "@ionic/angular";

import { ApiClient } from "@hyperledger/cactus-api-client";
import { BambooHarvest } from "@hyperledger/cactus-example-supply-chain-business-logic-plugin";
import { Logger, LoggerProvider } from "@hyperledger/cactus-common";

import { QUORUM_DEMO_LEDGER_ID } from "../../../constants";
import { Logger, LoggerProvider } from "@hyperledger/cactus-common";
import { isBambooHarvest } from "../is-bamboo-harvest";

@Component({
selector: "app-bamboo-harvest-detail",
Expand Down Expand Up @@ -52,8 +54,12 @@ export class BambooHarvestDetailPage implements OnInit {
});
}

public onClickFormSubmit(value: any): void {
public onClickFormSubmit(value: unknown): void {
this.log.debug("form submitted", value);
if (!isBambooHarvest(value)) {
const errMsg = `Expected the value to be of type BambooHarvest`;
throw new RuntimeError(errMsg);
}
this.bambooHarvest = value;
this.modalController.dismiss(this.bambooHarvest);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { BambooHarvest } from "@hyperledger/cactus-example-supply-chain-business-logic-plugin";

export function isBambooHarvest(x: unknown): x is BambooHarvest {
return (
!!x &&
typeof (x as BambooHarvest).id === "string" &&
typeof (x as BambooHarvest).location === "string" &&
typeof (x as BambooHarvest).startedAt === "string" &&
typeof (x as BambooHarvest).endedAt === "string" &&
typeof (x as BambooHarvest).harvester === "string"
);
}