handlerIncreaseVariable.js 790 B

123456789101112131415161718192021222324252627282930
  1. import objectPath from 'object-path';
  2. export async function increaseVariable({ id, data }) {
  3. const refVariables = this.engine.referenceData.variables;
  4. const variableExist = objectPath.has(refVariables, data.variableName);
  5. if (!variableExist) {
  6. throw new Error(`Cant find "${data.variableName}" variable`);
  7. }
  8. const currentVar = +objectPath.get(refVariables, data.variableName);
  9. if (Number.isNaN(currentVar)) {
  10. throw new Error(
  11. `The "${data.variableName}" variable value is not a number`
  12. );
  13. }
  14. objectPath.set(
  15. this.engine.referenceData.variables,
  16. data.variableName,
  17. currentVar + data.increaseBy
  18. );
  19. return {
  20. data: refVariables[data.variableName],
  21. nextBlockId: this.getBlockConnections(id),
  22. };
  23. }
  24. export default increaseVariable;