Skip to content

Commit

Permalink
feat(datamodel): add gaurds
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalshaikh42 committed Apr 1, 2020
1 parent 44c5bdd commit 2ffdf04
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
Expand Up @@ -4,8 +4,7 @@ import { JsonSerializable } from '@biosimulations/datamodel/utils';
import {
ParameterChangeDTO,
isAlgorithmParameterDTO,
AlgorithmParameterDTO,
ModelParameterDTO,
isModelParameterDTO,
} from '@biosimulations/datamodel/core';

export class ParameterChange implements JsonSerializable<ParameterChangeDTO> {
Expand All @@ -22,9 +21,9 @@ export class ParameterChange implements JsonSerializable<ParameterChangeDTO> {
constructor(data: ParameterChangeDTO) {
const param = data.parameter;
if (isAlgorithmParameterDTO(param)) {
this.algParam = new AlgorithmParameter(param as AlgorithmParameterDTO);
} else {
this.parameter = new ModelParameter(data.parameter as ModelParameterDTO);
this.algParam = new AlgorithmParameter(param);
} else if (isModelParameterDTO(param)) {
this.parameter = new ModelParameter(param);
}

this.value = data.value;
Expand Down
@@ -1,13 +1,20 @@
import { DTO } from '@biosimulations/datamodel/utils';
import { DTO, isOfType } from '@biosimulations/datamodel/utils';
import { AlgorithmDTO } from './algorithm.dto';

export interface AlgorithmParameterCore {
class AlgorithmParameterCore {
id?: string;
name?: string;
value?: number;
kisaoId?: number;
}
export const isAlgorithmParameterDTO = (param: any): param is AlgorithmDTO =>
'kisaoId' in param;

export type AlgorithmParameterDTO = DTO<AlgorithmParameterCore>;

/*
* // TODO can this be made generic?
* Perhaps can create a method that takes in a param as well as new instantiated "core" class
* would then use reflect to check all parameters?
*/

export const isAlgorithmParameterDTO = (param: any): param is AlgorithmDTO =>
'kisaoId' in param && 'id' in param && 'name' in param && 'value' in param;
1 change: 1 addition & 0 deletions biosimulations/libs/datamodel/core/src/lib/common/index.ts
@@ -1,5 +1,6 @@
export { PersonDTO } from './person.dto';
export { isAlgorithmParameterDTO } from './algorithm-parameter.dto';
export { isModelParameterDTO } from './model-parameter.dto';
export { IdentifierDTO } from './identifier.dto';
export { AlgorithmDTO } from './algorithm.dto';
export { AlgorithmParameterDTO } from './algorithm-parameter.dto';
Expand Down
@@ -1,10 +1,13 @@
import { DTO } from '@biosimulations/datamodel/utils';

export interface ModelParameterCore {
export class ModelParameterCore {
id: string;
name: string;
value: number;
units: string;
}

export type ModelParameterDTO = DTO<ModelParameterCore>;

export const isModelParameterDTO = (param: any): param is ModelParameterDTO =>
'units' in param && 'id' in param && 'name' in param && 'value' in param;
@@ -1,2 +1,2 @@
export * from './types';
export { isOfType } from './guard';
export * from './guard';
1 change: 0 additions & 1 deletion biosimulations/libs/datamodel/utils/src/lib/types.ts
Expand Up @@ -35,7 +35,6 @@ type Complete<T> = {

/**
* An object that can be created from a JSON representation and has a serialize method to return its JSON representation
*
*/
interface JsonSerializable<T extends DTO<T>> {
serialize(): T;
Expand Down

0 comments on commit 2ffdf04

Please sign in to comment.