Service - Unit Type

From Izara Wiki
Jump to navigation Jump to search

Overview

Each unitStandard is connected to a unitType which defines unitTrackedPropertys and how to handle them. unitPacking probably also uses the unitType structure.

Repository

https://bitbucket.org/izara-supply-units/izara-supply-units-unit-type

Unit Type configuration

unitType settings cannot be changed once created, so if want to adjust them would need to create a new unitType, this is because too much logic and data for unitStandard instances rely on unitType settings, data could break if settings changed.

objectSchemas

{
	objectType: "unitType",
	storageResources:{
		"xxx":{
			storageType: "graph",
			graphServerTag: "xx",
		}
	},
	fieldNames: {
		unitTypeId: {
			type: "string",
            randomOnCreate: true
		},
	},
	identifiers: [
		{
			fieldName: "unitTypeId"
		},
	]
},
{
	objectType: "unitTypeTrackedProperty",
    belongTo: { // maybe in future when add RBAC to unitType
		serviceTag: "iii",
		objectType: "jjj"
	},
	storageResources:{
		"xxx":{
			storageType: "graph",
			graphServerTag: "xx",
		}
	},
	fieldNames: {
		unitTypeTrackedPropertyId: {
			type: "string",
            randomOnCreate: true
		},
		precision: { // sets whether decimals are allowed and precision level
			type: "integer" ,
			requiredOnCreate: true,
		},	
		canNegative: { // default false, sets whether only zero and positive values are allowed
			type: "boolean" ,
			requiredOnCreate: true,
		},
		inactiveIfZero: { // default false, if value of this property goes to zero automatically removes activeUnit relationship and adds inactiveUnit relationship
			type: "boolean" ,
			requiredOnCreate: true,
		},		
		isCurrency: { // default false, sets whether unitTrackedProperty value is a currency amount
			type: "boolean" ,
			requiredOnCreate: true,
		},
	},
	identifiers: [
		{
			fieldName: "unitTypeTrackedPropertyId"
		},
	]
},
  • currency is handled special because conversions can be performed
  • multiple unitType instances can link to the same unitTypeTrackedProperty
  • examples: yards, weight, cost (see calculatedProperties in Service - Transform Units)
{
	objectType: "unitTrackedProperty",
    belongTo: { // in future add RBAC to eg Units
		serviceTag: "unitStandard",
		objectType: "unitStandard"
	},
	storageResources:{
		"xxx":{
			storageType: "graph",
			graphServerTag: "xx",
		}
	},
	fieldNames: {
		unitTrackedPropertyId: {
			type: "string",
            randomOnCreate: true
		},
		propertyValue: {
			type: "string", // so can adjust any type of property, will need cast type in logic
			requiredOnCreate: true,
			canUpdate: true,
		},
	},
	identifiers: [
		{
			fieldName: "unitTrackedPropertyId"
		},
	]
},

relationshipSchemas

[
  {
    "isUnitType": {
      storageResources:{
		"xxx":{
			storageType: "graph",
			graphServerTag: "xx",
		}
      },
      links: [
        {
          storageResourceTags: ["xxx"],
          canDelete: false,
          from: {
            objType: {
              serviceTag: "unitManager",
              objectType: "unit"
            },
            linkType: "many",
          },
          to: {
            objType: {
              serviceTag: "unitType",
              objectType: "unitType"
            },
            linkType: "one",
          }
        }
      ]
    }
  }
]
[
  {
    "hasUnitTypeTrackedProperty": {
      storageResources:{
		"xxx":{
			storageType: "graph",
			graphServerTag: "xx",
		}
      },
      links: [
        {
          storageResourceTags: ["xxx"],
          canDelete: false,
          from: {
            objType: {
              serviceTag: "unitType",
              objectType: "unitType"
            },
            linkType: "many",
          },
          to: {
            objType: {
              serviceTag: "unitType",
              objectType: "unitTypeTrackedProperty"
            },
            linkType: "one",
          }
        }
      ]
    }
  }
]
[
  {
    "isUnitTypeTrackedProperty": {
      storageResources:{
		"xxx":{
			storageType: "graph",
			graphServerTag: "xx",
		}
      },
      links: [
        {
          storageResourceTags: ["xxx"],
          canDelete: false,
          from: {
            objType: {
              serviceTag: "unitType",
              objectType: "unitTrackedProperty"
            },
            linkType: "many",
          },
          to: {
            objType: {
              serviceTag: "unitType",
              objectType: "unitTypeTrackedProperty"
            },
            linkType: "one",
          }
        }
      ]
    }
  }
]
  • links each unitTrackedProperty to it's matching unitTypeTrackedProperty
[
  {
    "hasUnitTrackedProperty": {
      storageResources:{
		"xxx":{
			storageType: "graph",
			graphServerTag: "xx",
		}
      },
      links: [
        {
          storageResourceTags: ["xxx"],
          canDelete: true,
          from: {
            objType: {
              serviceTag: "unitManager",
              objectType: "unit"
            },
            linkType: "one",
          },
          to: {
            objType: {
              serviceTag: "unitType",
              objectType: "unitTrackedProperty"
            },
            linkType: "many",
          }
        }
      ]
    }
  }
]
  • Units current unitTrackedProperty for each unitTypeTrackedProperty
[
  {
    "oldUnitTrackedProperty": {
      storageResources:{
		"xxx":{
			storageType: "graph",
			graphServerTag: "xx",
		}
      },
      fieldNames: {
			"fromTimestamp": {
			  type: "timestamp",
			  requiredOnCreate: true,
			},
			"toTimestamp": {
			  type: "timestamp",
			  requiredOnCreate: true,
			}
		},   
      links: [
        {
          storageResourceTags: ["xxx"],
          canDelete: true,
          from: {
            objType: {
              serviceTag: "unitManager",
              objectType: "unit"
            },
            linkType: "one",
          },
          to: {
            objType: {
              serviceTag: "unitType",
              objectType: "unitTrackedProperty"
            },
            linkType: "many",
          }
        }
      ]
    }
  }
]
  • old unitTrackedProperties for a unit, maintains a history of unitTrackedProperty propertyValue changes
  • when a change is made to a unitTrackedProperty propertyValue a new unitTrackedProperty is created and hasUnitTrackedProperty links to unitStandard, while old hasUnitTrackedProperty relationship is removed and replaced with a oldUnitTrackedProperty

Working documents

Unit Type