Skip to content
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
29 changes: 27 additions & 2 deletions codbex-uoms/api/ConverterController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ConverterController {
private readonly repository = new UoMRepository();

@Get("/:source/:target/:value")
public convertValue(_: any, ctx: any): number {
public convertValue(_: any, ctx: any): number | undefined {
try {
const source = ctx.pathParameters.source;
const target = ctx.pathParameters.target;
Expand All @@ -29,6 +29,7 @@ class ConverterController {
}
]
})[0];

const entityTarget = this.repository.findAll({
conditions: [
{
Expand All @@ -38,13 +39,37 @@ class ConverterController {
}
]
})[0];

if (entitySource && entityTarget) {
if (entitySource.Dimension !== entityTarget.Dimension) {
HttpUtils.sendResponseBadRequest("Both Source and Target Unit of Measures should have the same Dimension");
HttpUtils.sendResponseBadRequest(
"Both Source and Target Unit of Measures should have the same Dimension"
);
return;
}

if (
entitySource.Numerator == null ||
entitySource.Denominator == null ||
entityTarget.Numerator == null ||
entityTarget.Denominator == null
) {
HttpUtils.sendResponseBadRequest(
"Invalid conversion factors defined"
);
return;
}

if (entitySource.Denominator === 0 || entityTarget.Numerator === 0) {
HttpUtils.sendResponseBadRequest(
"Invalid conversion configuration (division by zero)"
);
return;
}

const valueBase = value * entitySource.Numerator / entitySource.Denominator;
const valueTarget = valueBase * entityTarget.Denominator / entityTarget.Numerator;

return valueTarget;
} else {
HttpUtils.sendResponseNotFound("Unit of Measures not found: [" + source + "] and/or [" + target + "]");
Expand Down
32 changes: 16 additions & 16 deletions codbex-uoms/codbex-uoms.edm

Large diffs are not rendered by default.

86 changes: 44 additions & 42 deletions codbex-uoms/codbex-uoms.gen
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@
"brandUrl": "https://www.codbex.com/",
"title": "UOMs Management Module",
"description": "Managing UOMs Data",
"fileName": "codbex-uoms",
"genFolderName": "codbex-uoms",
"dataSource": "DefaultDB",
"roles": [
{
"entityName": "Dimension",
"roleRead": "codbex-uoms.Dimensions.DimensionReadOnly",
"roleWrite": "codbex-uoms.Dimensions.DimensionFullAccess"
},
{
"entityName": "UoM",
"roleRead": "codbex-uoms.UnitsOfMeasures.UoMReadOnly",
"roleWrite": "codbex-uoms.UnitsOfMeasures.UoMFullAccess"
}
],
"tprefix": "codbex-uoms-model",
"projectName": "codbex-uoms",
"workspaceName": "workspace",
"filePath": "codbex-uoms.model",
"templateId": "template-application-angular-v2/template/template.js",
"fileName": "codbex-uoms",
"genFolderName": "codbex-uoms",
"dataSource": "DefaultDB",
"perspectives": {
"Settings": {
"views": [
Expand All @@ -26,19 +39,6 @@
"role": ""
}
},
"roles": [
{
"entityName": "Dimension",
"roleRead": "codbex-uoms.Dimensions.DimensionReadOnly",
"roleWrite": "codbex-uoms.Dimensions.DimensionFullAccess"
},
{
"entityName": "UoM",
"roleRead": "codbex-uoms.UnitsOfMeasures.UoMReadOnly",
"roleWrite": "codbex-uoms.UnitsOfMeasures.UoMFullAccess"
}
],
"tprefix": "codbex-uoms-model",
"models": [
{
"properties": [
Expand Down Expand Up @@ -71,6 +71,7 @@
"dataName": "DIMENSION_NAME",
"dataNullable": false,
"dataType": "VARCHAR",
"dataUnique": true,
"description": "",
"isRequiredProperty": true,
"name": "Name",
Expand All @@ -82,7 +83,6 @@
"dataNotNull": true,
"dataAutoIncrement": false,
"dataPrimaryKey": false,
"dataUnique": false,
"isCalculatedProperty": false,
"widgetLabel": "Name",
"widgetDropdownUrl": "",
Expand All @@ -98,6 +98,7 @@
"dataName": "DIMENSION_SAP",
"dataNullable": true,
"dataType": "VARCHAR",
"dataUnique": true,
"description": "",
"name": "SAP",
"tooltip": "",
Expand All @@ -108,7 +109,6 @@
"dataNotNull": false,
"dataAutoIncrement": false,
"dataPrimaryKey": false,
"dataUnique": false,
"isRequiredProperty": false,
"isCalculatedProperty": false,
"widgetLabel": "SAP",
Expand Down Expand Up @@ -183,20 +183,20 @@
{
"dataLength": "100",
"dataName": "UOM_NAME",
"dataNullable": true,
"dataNullable": false,
"dataType": "VARCHAR",
"dataUnique": true,
"description": "",
"isRequiredProperty": true,
"name": "Name",
"tooltip": "",
"widgetIsMajor": true,
"widgetLength": "100",
"widgetSize": "fd-col-md--4 fd-col--6",
"widgetType": "TEXTBOX",
"dataNotNull": false,
"dataNotNull": true,
"dataAutoIncrement": false,
"dataPrimaryKey": false,
"dataUnique": false,
"isRequiredProperty": false,
"isCalculatedProperty": false,
"widgetLabel": "Name",
"widgetDropdownUrl": "",
Expand All @@ -210,20 +210,20 @@
{
"dataLength": "20",
"dataName": "UOM_ISO",
"dataNullable": true,
"dataNullable": false,
"dataType": "VARCHAR",
"dataUnique": true,
"description": "",
"isRequiredProperty": true,
"name": "ISO",
"tooltip": "",
"widgetIsMajor": true,
"widgetLength": "20",
"widgetSize": "",
"widgetType": "TEXTBOX",
"dataNotNull": false,
"dataNotNull": true,
"dataAutoIncrement": false,
"dataPrimaryKey": false,
"dataUnique": false,
"isRequiredProperty": false,
"isCalculatedProperty": false,
"widgetLabel": "ISO",
"widgetDropdownUrl": "",
Expand All @@ -236,9 +236,10 @@
},
{
"dataName": "UOM_DIMENSION",
"dataNullable": true,
"dataNullable": false,
"dataType": "INTEGER",
"description": "",
"isRequiredProperty": true,
"name": "Dimension",
"tooltip": "",
"widgetDropDownKey": "Id",
Expand All @@ -250,12 +251,11 @@
"relationshipName": "UoM_Dimension",
"relationshipEntityName": "Dimension",
"relationshipEntityPerspectiveName": "Settings",
"relationshipEntityPerspectiveLabel": "",
"dataNotNull": false,
"relationshipEntityPerspectiveLabel": "Entities",
"dataNotNull": true,
"dataAutoIncrement": false,
"dataPrimaryKey": false,
"dataUnique": false,
"isRequiredProperty": false,
"isCalculatedProperty": false,
"widgetLabel": "Dimension",
"widgetDropdownUrl": "/services/ts/codbex-uoms/gen/codbex-uoms/api/Settings/DimensionService.ts",
Expand All @@ -269,6 +269,7 @@
"dataName": "UOM_SAP",
"dataNullable": true,
"dataType": "VARCHAR",
"dataUnique": true,
"description": "",
"name": "SAP",
"tooltip": "",
Expand All @@ -283,7 +284,6 @@
"dataNotNull": false,
"dataAutoIncrement": false,
"dataPrimaryKey": false,
"dataUnique": false,
"isRequiredProperty": false,
"isCalculatedProperty": false,
"widgetLabel": "SAP",
Expand All @@ -297,20 +297,20 @@
},
{
"dataName": "UOM_NUMERATOR",
"dataNullable": true,
"dataNullable": false,
"dataType": "BIGINT",
"description": "",
"isRequiredProperty": true,
"name": "Numerator",
"tooltip": "",
"widgetIsMajor": true,
"widgetLength": "20",
"widgetSize": "fd-col-md--4 fd-col--6",
"widgetType": "NUMBER",
"dataNotNull": false,
"dataNotNull": true,
"dataAutoIncrement": false,
"dataPrimaryKey": false,
"dataUnique": false,
"isRequiredProperty": false,
"isCalculatedProperty": false,
"widgetLabel": "Numerator",
"widgetDropdownUrl": "",
Expand All @@ -321,20 +321,20 @@
},
{
"dataName": "UOM_DENOMINATOR",
"dataNullable": true,
"dataNullable": false,
"dataType": "BIGINT",
"description": "",
"isRequiredProperty": true,
"name": "Denominator",
"tooltip": "",
"widgetIsMajor": true,
"widgetLength": "20",
"widgetSize": "fd-col-md--4 fd-col--6",
"widgetType": "NUMBER",
"dataNotNull": false,
"dataNotNull": true,
"dataAutoIncrement": false,
"dataPrimaryKey": false,
"dataUnique": false,
"isRequiredProperty": false,
"isCalculatedProperty": false,
"widgetLabel": "Denominator",
"widgetDropdownUrl": "",
Expand All @@ -344,21 +344,22 @@
"inputRule": ""
},
{
"dataDefaultValue": "0",
"dataName": "UOM_ROUNDING",
"dataNullable": true,
"dataNullable": false,
"dataType": "INTEGER",
"description": "",
"isRequiredProperty": true,
"name": "Rounding",
"tooltip": "",
"widgetIsMajor": true,
"widgetLength": "20",
"widgetSize": "fd-col-md--2 fd-col--3",
"widgetType": "NUMBER",
"dataNotNull": false,
"dataNotNull": true,
"dataAutoIncrement": false,
"dataPrimaryKey": false,
"dataUnique": false,
"isRequiredProperty": false,
"isCalculatedProperty": false,
"widgetLabel": "Rounding",
"widgetDropdownUrl": "",
Expand All @@ -368,8 +369,9 @@
"inputRule": ""
},
{
"dataDefaultValue": "false",
"dataName": "UOM_BASE",
"dataNullable": true,
"dataNullable": false,
"dataType": "BOOLEAN",
"description": "",
"name": "Base",
Expand All @@ -378,7 +380,7 @@
"widgetLength": "20",
"widgetSize": "fd-col-md--2 fd-col--3",
"widgetType": "CHECKBOX",
"dataNotNull": false,
"dataNotNull": true,
"dataAutoIncrement": false,
"dataPrimaryKey": false,
"dataUnique": false,
Expand Down
Loading