Skip to content

Commit

Permalink
style: 2021-09-20 linter warnings batch 17 / 26; part 2
Browse files Browse the repository at this point in the history
Fixes #2092

Signed-off-by: adrianbatuto <adrian.batuto@accenture.com>
  • Loading branch information
adrianbatuto committed Jun 15, 2023
1 parent 7abf3dd commit 756c56d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 14 deletions.
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
Expand Up @@ -10,6 +10,18 @@ import { BambooHarvest } from "@hyperledger/cactus-example-supply-chain-business
import { QUORUM_DEMO_LEDGER_ID } from "../../../constants";
import { Logger, LoggerProvider } from "@hyperledger/cactus-common";

import { RuntimeError } from "run-time-error";

function isBambooHarvest(value: unknown): value is BambooHarvest {
const harvest = value as BambooHarvest;
return (
typeof harvest.id === "string" &&
typeof harvest.location === "string" &&
typeof harvest.startedAt === "string" &&
typeof harvest.endedAt === "string" &&
typeof harvest.harvester === "string"
);
}
@Component({
selector: "app-bamboo-harvest-detail",
templateUrl: "./bamboo-harvest-detail.page.html",
Expand Down Expand Up @@ -52,9 +64,13 @@ export class BambooHarvestDetailPage implements OnInit {
});
}

public onClickFormSubmit(value: any): void {
public onClickFormSubmit(value: unknown): void {
this.log.debug("form submitted", value);
this.bambooHarvest = value;
if (!isBambooHarvest(value)) {
const errMsg = `Expected the value to be of type BambooHarvest`;
throw new RuntimeError(errMsg);
}
this.bambooHarvest = value as BambooHarvest;
this.modalController.dismiss(this.bambooHarvest);
}

Expand Down

0 comments on commit 756c56d

Please sign in to comment.