@runnerpro/backend 1.17.24 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
1
  declare const getStructuraWorkout: (workout: any, estructura: any) => any;
2
- export { getStructuraWorkout };
2
+ declare const saveDoneStructuraWorkout: (idWorkout: any, estructura: any, workoutType: any) => Promise<void>;
3
+ export { getStructuraWorkout, saveDoneStructuraWorkout };
3
4
  //# sourceMappingURL=estructuraWorkout.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"estructuraWorkout.d.ts","sourceRoot":"","sources":["../../../../src/workout/estructuraWorkout.ts"],"names":[],"mappings":"AAqCA,QAAA,MAAM,mBAAmB,wCAiCxB,CAAC;AAGF,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
1
+ {"version":3,"file":"estructuraWorkout.d.ts","sourceRoot":"","sources":["../../../../src/workout/estructuraWorkout.ts"],"names":[],"mappings":"AAuCA,QAAA,MAAM,mBAAmB,wCAiCxB,CAAC;AAEF,QAAA,MAAM,wBAAwB,sEAkC7B,CAAC;AAGF,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,CAAC"}
@@ -1,6 +1,17 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getStructuraWorkout = void 0;
12
+ exports.saveDoneStructuraWorkout = exports.getStructuraWorkout = void 0;
13
+ const db_1 = require("../db");
14
+ const common_1 = require("@runnerpro/common");
4
15
  const calculateZone = (values) => {
5
16
  const percentage = Number(values.pacePercentage);
6
17
  if (percentage <= 70)
@@ -56,3 +67,38 @@ const getStructuraWorkout = (workout, estructura) => {
56
67
  }
57
68
  };
58
69
  exports.getStructuraWorkout = getStructuraWorkout;
70
+ const saveDoneStructuraWorkout = (idWorkout, estructura, workoutType) => __awaiter(void 0, void 0, void 0, function* () {
71
+ const estructuraBBDD = yield (0, db_1.query)('SELECT * FROM [WORKOUT STRUCTURE] WHERE [ID WORKOUT] = ? ORDER BY [INDEX]', [idWorkout]);
72
+ let i = 0;
73
+ for (const row of estructuraBBDD) {
74
+ let distance = 0;
75
+ let duration = 0;
76
+ let distancePlanned = 0;
77
+ let durationPlanned = 0;
78
+ const pace = estructura ? estructura[i].valueMetric2 : row.valueMetric2;
79
+ const pacePlanned = row.valueMetric2;
80
+ if (Number(row.typeMetric1) === 1) {
81
+ distancePlanned = row.valueMetric1;
82
+ distance = row.valueMetric1;
83
+ durationPlanned = (0, common_1.getWorkoutParamsByType)(workoutType).calculateDuration({ distance: row.valueMetric1, pace: pacePlanned });
84
+ duration = (0, common_1.getWorkoutParamsByType)(workoutType).calculateDuration({ distance: row.valueMetric1, pace });
85
+ }
86
+ else {
87
+ durationPlanned = row.valueMetric1;
88
+ duration = row.valueMetric1;
89
+ if (Number(row.type) === 3) {
90
+ // @ts-ignore
91
+ distancePlanned = null;
92
+ // @ts-ignore
93
+ distance = null;
94
+ }
95
+ else {
96
+ distancePlanned = (0, common_1.getWorkoutParamsByType)(workoutType).calculateDistance({ duration: row.valueMetric1, pace: pacePlanned, decimals: 2 });
97
+ distance = (0, common_1.getWorkoutParamsByType)(workoutType).calculateDistance({ duration: row.valueMetric1, pace, decimals: 2 });
98
+ }
99
+ }
100
+ i++;
101
+ yield (0, db_1.query)('UPDATE [WORKOUT STRUCTURE] SET [DISTANCE PLANNED] = ?, [DISTANCE] = ?, [DURATION PLANNED] = ?, [DURATION] = ?, [DESNIVEL] = ? WHERE [INDEX] = ? AND [ID WORKOUT] = ?', [distancePlanned, distance, durationPlanned, duration, row.desnivelPlanned, row.index, idWorkout]);
102
+ }
103
+ });
104
+ exports.saveDoneStructuraWorkout = saveDoneStructuraWorkout;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.17.24",
3
+ "version": "1.18.0",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"