@runnerpro/backend 1.7.4 → 1.7.6
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.
- package/lib/cjs/image/generateShareMap.js +1 -1
- package/lib/cjs/index.js +3 -1
- package/lib/cjs/translation/titleDescriptionTranslated.js +38 -0
- package/lib/cjs/types/image/generateShareMap.d.ts +2 -2
- package/lib/cjs/types/image/generateShareMap.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +2 -1
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/translation/titleDescriptionTranslated.d.ts +8 -0
- package/lib/cjs/types/translation/titleDescriptionTranslated.d.ts.map +1 -0
- package/lib/cjs/types/workout/estructuraWorkout.d.ts +2 -1
- package/lib/cjs/types/workout/estructuraWorkout.d.ts.map +1 -1
- package/lib/cjs/types/workout/saveWorkoutAplication.d.ts +17 -0
- package/lib/cjs/types/workout/saveWorkoutAplication.d.ts.map +1 -0
- package/lib/cjs/workout/estructuraWorkout.js +37 -1
- package/lib/cjs/workout/saveWorkoutAplication.js +93 -0
- package/package.json +4 -3
|
@@ -25,7 +25,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
25
25
|
// install fonts
|
|
26
26
|
canvas_1.GlobalFonts.registerFromPath(path_1.default.join(__dirname, '../../..', 'static/fonts', 'SofiaSans-Bold.ttf'), 'SofiaSansBold');
|
|
27
27
|
canvas_1.GlobalFonts.registerFromPath(path_1.default.join(__dirname, '../../..', 'static/fonts', 'SofiaSans-Regular.ttf'), 'SofiaSans');
|
|
28
|
-
const generateShareMap = (image, idWorkout, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
const generateShareMap = (image, idWorkout, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
29
|
const useDefaultPhoto = (options === null || options === void 0 ? void 0 : options.useDefaultPhoto) || false;
|
|
30
30
|
const [workout] = yield (0, index_1.query)('SELECT [ID], [ID CLIENTE], [TYPE], [DISTANCE], [DURATION], [DESNIVEL] FROM [WORKOUT] WHERE [ID] = ?', [idWorkout]);
|
|
31
31
|
const [cliente] = yield (0, index_1.query)('SELECT [PREFERRED LANGUAGE] FROM [CLIENTE] WHERE [ID] = ?', [workout.idCliente]);
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPlanificacionPrueba7dias = exports.sendWorkoutToWatch = exports.getDefaultWorkoutImage = exports.generateShareMap = exports.reduceSizeImage = exports.getLetter = exports.getNumberByLetter = exports.appendSheet = exports.writeSheet = exports.findCellByValue = exports.readSheet = exports.NOTION_DATABASES_ID = exports.notionEditPage = exports.notionAddPage = exports.notionGetDatabase = exports.notionGetUsers = exports.getCountNotificaciones = exports.chatExposed = exports.chatApi = exports.chat = exports.getExerciseTranslatedDescription = exports.useTranslation = exports.LANGUAGES = exports.translate = exports.CHANNEL_SLACK = exports.notifySlack = exports.fetchIA = exports.err = exports.sendMail = exports.pool = exports.toPgArray = exports.batchQuery = exports.query = exports.sleep = exports.sendNotification = void 0;
|
|
3
|
+
exports.saveWorkoutAplication = exports.getPlanificacionPrueba7dias = exports.sendWorkoutToWatch = exports.getDefaultWorkoutImage = exports.generateShareMap = exports.reduceSizeImage = exports.getLetter = exports.getNumberByLetter = exports.appendSheet = exports.writeSheet = exports.findCellByValue = exports.readSheet = exports.NOTION_DATABASES_ID = exports.notionEditPage = exports.notionAddPage = exports.notionGetDatabase = exports.notionGetUsers = exports.getCountNotificaciones = exports.chatExposed = exports.chatApi = exports.chat = exports.getExerciseTranslatedDescription = exports.useTranslation = exports.LANGUAGES = exports.translate = exports.CHANNEL_SLACK = exports.notifySlack = exports.fetchIA = exports.err = exports.sendMail = exports.pool = exports.toPgArray = exports.batchQuery = exports.query = exports.sleep = exports.sendNotification = void 0;
|
|
4
4
|
const sendNotification_1 = require("./sendNotification");
|
|
5
5
|
Object.defineProperty(exports, "sendNotification", { enumerable: true, get: function () { return sendNotification_1.sendNotification; } });
|
|
6
6
|
const sleep_1 = require("./sleep");
|
|
@@ -52,3 +52,5 @@ const sendToWatch_1 = require("./workout/sendToWatch");
|
|
|
52
52
|
Object.defineProperty(exports, "sendWorkoutToWatch", { enumerable: true, get: function () { return sendToWatch_1.sendWorkoutToWatch; } });
|
|
53
53
|
const planificacionPrueba7dias_1 = require("./workout/planificacionPrueba7dias");
|
|
54
54
|
Object.defineProperty(exports, "getPlanificacionPrueba7dias", { enumerable: true, get: function () { return planificacionPrueba7dias_1.getPlanificacionPrueba7dias; } });
|
|
55
|
+
const saveWorkoutAplication_1 = require("./workout/saveWorkoutAplication");
|
|
56
|
+
Object.defineProperty(exports, "saveWorkoutAplication", { enumerable: true, get: function () { return saveWorkoutAplication_1.saveWorkoutAplication; } });
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getTitleDescriptionTranslated = void 0;
|
|
13
|
+
const db_1 = require("../db");
|
|
14
|
+
const index_1 = require("./index");
|
|
15
|
+
const common_1 = require("@runnerpro/common");
|
|
16
|
+
const getTitleDescriptionTranslated = (idCliente, titleOriginal, descriptionOriginal) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
let title;
|
|
18
|
+
let description;
|
|
19
|
+
let titlePreferredLanguage;
|
|
20
|
+
let descriptionPreferredLanguage;
|
|
21
|
+
const [cliente] = yield (0, db_1.query)('SELECT [PREFERRED LANGUAGE] FROM [CLIENTE] WHERE [ID] = ?', [idCliente]);
|
|
22
|
+
if ((cliente === null || cliente === void 0 ? void 0 : cliente.preferredLanguage) && cliente.preferredLanguage !== common_1.LANGUAGES.ES) {
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
title = titleOriginal ? yield (0, index_1.translate)(titleOriginal, { fromLanguage: cliente.preferredLanguage, toLanguage: common_1.LANGUAGES.ES }) : null;
|
|
25
|
+
description = descriptionOriginal
|
|
26
|
+
? // @ts-ignore
|
|
27
|
+
yield (0, index_1.translate)(descriptionOriginal, { fromLanguage: cliente.preferredLanguage, toLanguage: common_1.LANGUAGES.ES })
|
|
28
|
+
: null;
|
|
29
|
+
titlePreferredLanguage = titleOriginal;
|
|
30
|
+
descriptionPreferredLanguage = descriptionOriginal;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
title = titleOriginal;
|
|
34
|
+
description = descriptionOriginal;
|
|
35
|
+
}
|
|
36
|
+
return { title, description, titlePreferredLanguage, descriptionPreferredLanguage };
|
|
37
|
+
});
|
|
38
|
+
exports.getTitleDescriptionTranslated = getTitleDescriptionTranslated;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
declare const generateShareMap: (image: any, idWorkout: any, options
|
|
3
|
-
export { generateShareMap
|
|
2
|
+
declare const generateShareMap: (image: any, idWorkout: any, options?: {}) => Promise<Buffer>;
|
|
3
|
+
export { generateShareMap };
|
|
4
4
|
//# sourceMappingURL=generateShareMap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateShareMap.d.ts","sourceRoot":"","sources":["../../../../src/image/generateShareMap.ts"],"names":[],"mappings":";AAcA,QAAA,MAAM,gBAAgB,+DAkBrB,CAAC;AA0HF,OAAO,
|
|
1
|
+
{"version":3,"file":"generateShareMap.d.ts","sourceRoot":"","sources":["../../../../src/image/generateShareMap.ts"],"names":[],"mappings":";AAcA,QAAA,MAAM,gBAAgB,+DAkBrB,CAAC;AA0HF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -14,5 +14,6 @@ import { generateShareMap } from './image/generateShareMap';
|
|
|
14
14
|
import { getDefaultWorkoutImage } from './image/getDefaultWorkoutImage';
|
|
15
15
|
import { sendWorkoutToWatch } from './workout/sendToWatch';
|
|
16
16
|
import { getPlanificacionPrueba7dias } from './workout/planificacionPrueba7dias';
|
|
17
|
-
|
|
17
|
+
import { saveWorkoutAplication } from './workout/saveWorkoutAplication';
|
|
18
|
+
export { sendNotification, sleep, query, batchQuery, toPgArray, pool, sendMail, err, fetchIA, notifySlack, CHANNEL_SLACK, translate, LANGUAGES, useTranslation, getExerciseTranslatedDescription, chat, chatApi, chatExposed, getCountNotificaciones, notionGetUsers, notionGetDatabase, notionAddPage, notionEditPage, NOTION_DATABASES_ID, readSheet, findCellByValue, writeSheet, appendSheet, getNumberByLetter, getLetter, reduceSizeImage, generateShareMap, getDefaultWorkoutImage, sendWorkoutToWatch, getPlanificacionPrueba7dias, saveWorkoutAplication, };
|
|
18
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,GAAG,EAAE,MAAM,O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escriptionTranslated: (idCliente: any, titleOriginal: any, descriptionOriginal: any) => Promise<{
|
|
2
|
+
title: any;
|
|
3
|
+
description: any;
|
|
4
|
+
titlePreferredLanguage: any;
|
|
5
|
+
descriptionPreferredLanguage: any;
|
|
6
|
+
}>;
|
|
7
|
+
export { getTitleDescriptionTranslated };
|
|
8
|
+
//# sourceMappingURL=titleDescriptionTranslated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"titleDescriptionTranslated.d.ts","sourceRoot":"","sources":["../../../../src/translation/titleDescriptionTranslated.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,6BAA6B;;;;;EAsBlC,CAAC;AAEF,OAAO,EAAE,6BAA6B,EAAE,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
declare const getStructuraWorkout: (workout: any, estructura: any) => any;
|
|
2
2
|
declare const saveWorkoutEstructuraNotDone: (idWorkout: any, data: any) => Promise<void>;
|
|
3
3
|
declare const savePlantillaEstructuraNotDone: (idPlantilla: any, data: any) => Promise<void>;
|
|
4
|
-
|
|
4
|
+
declare const saveDoneStructuraWorkout: (idWorkout: any, estructura: any, workoutType: any) => Promise<void>;
|
|
5
|
+
export { getStructuraWorkout, saveWorkoutEstructuraNotDone, savePlantillaEstructuraNotDone, saveDoneStructuraWorkout };
|
|
5
6
|
//# sourceMappingURL=estructuraWorkout.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estructuraWorkout.d.ts","sourceRoot":"","sources":["../../../../src/workout/estructuraWorkout.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"estructuraWorkout.d.ts","sourceRoot":"","sources":["../../../../src/workout/estructuraWorkout.ts"],"names":[],"mappings":"AA4DA,QAAA,MAAM,mBAAmB,wCAiCxB,CAAC;AAmCF,QAAA,MAAM,4BAA4B,8CAkBjC,CAAC;AAEF,QAAA,MAAM,8BAA8B,gDAkBnC,CAAC;AAEF,QAAA,MAAM,wBAAwB,sEAkC7B,CAAC;AAEF,OAAO,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,8BAA8B,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const saveWorkoutAplication: ({ date, type, title, description, distance, duration, power, desnivel, polyline, idCliente, aplicationType, aplicationId, queryConditionExist }: {
|
|
2
|
+
date: any;
|
|
3
|
+
type: any;
|
|
4
|
+
title: any;
|
|
5
|
+
description: any;
|
|
6
|
+
distance: any;
|
|
7
|
+
duration: any;
|
|
8
|
+
power: any;
|
|
9
|
+
desnivel: any;
|
|
10
|
+
polyline: any;
|
|
11
|
+
idCliente: any;
|
|
12
|
+
aplicationType: any;
|
|
13
|
+
aplicationId: any;
|
|
14
|
+
queryConditionExist: any;
|
|
15
|
+
}, data: any) => Promise<void>;
|
|
16
|
+
export { saveWorkoutAplication };
|
|
17
|
+
//# sourceMappingURL=saveWorkoutAplication.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"saveWorkoutAplication.d.ts","sourceRoot":"","sources":["../../../../src/workout/saveWorkoutAplication.ts"],"names":[],"mappings":"AAUA,QAAA,MAAM,qBAAqB;;;;;;;;;;;;;;8BAsD1B,CAAC;AAuCF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -9,8 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.savePlantillaEstructuraNotDone = exports.saveWorkoutEstructuraNotDone = exports.getStructuraWorkout = void 0;
|
|
12
|
+
exports.saveDoneStructuraWorkout = exports.savePlantillaEstructuraNotDone = exports.saveWorkoutEstructuraNotDone = exports.getStructuraWorkout = void 0;
|
|
13
13
|
const db_1 = require("../db");
|
|
14
|
+
const common_1 = require("@runnerpro/common");
|
|
14
15
|
const calculateZone = (values) => {
|
|
15
16
|
const percentage = Number(values.pacePercentage);
|
|
16
17
|
if (percentage <= 70)
|
|
@@ -149,3 +150,38 @@ const savePlantillaEstructuraNotDone = (idPlantilla, data) => __awaiter(void 0,
|
|
|
149
150
|
}
|
|
150
151
|
});
|
|
151
152
|
exports.savePlantillaEstructuraNotDone = savePlantillaEstructuraNotDone;
|
|
153
|
+
const saveDoneStructuraWorkout = (idWorkout, estructura, workoutType) => __awaiter(void 0, void 0, void 0, function* () {
|
|
154
|
+
const estructuraBBDD = yield (0, db_1.query)('SELECT * FROM [WORKOUT STRUCTURE] WHERE [ID WORKOUT] = ? ORDER BY [INDEX]', [idWorkout]);
|
|
155
|
+
let i = 0;
|
|
156
|
+
for (const row of estructuraBBDD) {
|
|
157
|
+
let distance = 0;
|
|
158
|
+
let duration = 0;
|
|
159
|
+
let distancePlanned = 0;
|
|
160
|
+
let durationPlanned = 0;
|
|
161
|
+
const pace = estructura ? estructura[i].valueMetric2 : row.valueMetric2;
|
|
162
|
+
const pacePlanned = row.valueMetric2;
|
|
163
|
+
if (Number(row.typeMetric1) === 1) {
|
|
164
|
+
distancePlanned = row.valueMetric1;
|
|
165
|
+
distance = row.valueMetric1;
|
|
166
|
+
durationPlanned = (0, common_1.getWorkoutParamsByType)(workoutType).calculateDuration({ distance: row.valueMetric1, pace: pacePlanned });
|
|
167
|
+
duration = (0, common_1.getWorkoutParamsByType)(workoutType).calculateDuration({ distance: row.valueMetric1, pace });
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
durationPlanned = row.valueMetric1;
|
|
171
|
+
duration = row.valueMetric1;
|
|
172
|
+
if (Number(row.type) === 3) {
|
|
173
|
+
// @ts-ignore
|
|
174
|
+
distancePlanned = null;
|
|
175
|
+
// @ts-ignore
|
|
176
|
+
distance = null;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
distancePlanned = (0, common_1.getWorkoutParamsByType)(workoutType).calculateDistance({ duration: row.valueMetric1, pace: pacePlanned, decimals: 2 });
|
|
180
|
+
distance = (0, common_1.getWorkoutParamsByType)(workoutType).calculateDistance({ duration: row.valueMetric1, pace, decimals: 2 });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
i++;
|
|
184
|
+
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]);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
exports.saveDoneStructuraWorkout = saveDoneStructuraWorkout;
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.saveWorkoutAplication = void 0;
|
|
16
|
+
const db_1 = require("../db");
|
|
17
|
+
const titleDescriptionTranslated_1 = require("../translation/titleDescriptionTranslated");
|
|
18
|
+
const storage_1 = require("@google-cloud/storage");
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const axios_1 = __importDefault(require("axios"));
|
|
21
|
+
const generateShareMap_1 = require("../image/generateShareMap");
|
|
22
|
+
const getDefaultWorkoutImage_1 = require("../image/getDefaultWorkoutImage");
|
|
23
|
+
const moment_1 = __importDefault(require("moment"));
|
|
24
|
+
const estructuraWorkout_1 = require("./estructuraWorkout");
|
|
25
|
+
const saveWorkoutAplication = ({ date, type, title, description, distance, duration, power, desnivel, polyline, idCliente, aplicationType, aplicationId, queryConditionExist }, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
const [exist] = yield (0, db_1.query)(`
|
|
27
|
+
SELECT [ID], [TYPE]
|
|
28
|
+
FROM [WORKOUT]
|
|
29
|
+
WHERE
|
|
30
|
+
([ID CLIENTE] = ? AND [DATE] = ? AND ${queryConditionExist} AND [DONE] = FALSE AND [SHOW CLIENT] = TRUE)
|
|
31
|
+
OR
|
|
32
|
+
([ID APLICATION] = ? AND [TIPO APLICATION] = ?)
|
|
33
|
+
`, [idCliente, (0, moment_1.default)(date).format('YYYY-MM-DD'), aplicationId, aplicationType]);
|
|
34
|
+
let idWorkout;
|
|
35
|
+
if (!exist) {
|
|
36
|
+
const { title: titleNoTranslate, description: descriptionNoTranslate, titlePreferredLanguage, descriptionPreferredLanguage, } = yield (0, titleDescriptionTranslated_1.getTitleDescriptionTranslated)(idCliente, title, description);
|
|
37
|
+
[{ id: idWorkout }] = yield (0, db_1.query)(`
|
|
38
|
+
INSERT INTO [WORKOUT] ([ID CLIENTE], [DATE], [TITLE], [DESCRIPTION], [TITLE PREFERRED LANGUAGE], [DESCRIPTION PREFERRED LANGUAGE], [TYPE], [DONE], [SHOW CLIENT])
|
|
39
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, TRUE, TRUE) RETURNING [ID]
|
|
40
|
+
`, [
|
|
41
|
+
idCliente,
|
|
42
|
+
(0, moment_1.default)(date).format('YYYY-MM-DD'),
|
|
43
|
+
titleNoTranslate,
|
|
44
|
+
descriptionNoTranslate,
|
|
45
|
+
titlePreferredLanguage,
|
|
46
|
+
descriptionPreferredLanguage,
|
|
47
|
+
type,
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
idWorkout = exist.id;
|
|
52
|
+
yield (0, estructuraWorkout_1.saveDoneStructuraWorkout)(exist.id, null, exist.type);
|
|
53
|
+
}
|
|
54
|
+
yield (0, db_1.query)(`
|
|
55
|
+
UPDATE [WORKOUT] SET [DISTANCE] = ?, [DURATION] = ?, [POTENCIA] = ?, [DESNIVEL] = ?, [TIPO APLICATION] = ?, [ID APLICATION] = ?, [DONE] = TRUE, [RAW] = ?
|
|
56
|
+
WHERE [ID] = ?
|
|
57
|
+
`, [distance, duration, power, desnivel, aplicationType, aplicationId, JSON.stringify(data), idWorkout]);
|
|
58
|
+
yield saveMap(idWorkout, polyline);
|
|
59
|
+
saveShareWorkoutImage(idWorkout, type);
|
|
60
|
+
});
|
|
61
|
+
exports.saveWorkoutAplication = saveWorkoutAplication;
|
|
62
|
+
const saveMap = (idWorkout, polyline) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
if (!polyline)
|
|
64
|
+
return;
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
const serviceKey = path_1.default.join(process.cwd(), process.env.FIREBASE_STORAGE_CREDENTIALS);
|
|
67
|
+
const storage = new storage_1.Storage({ keyFilename: serviceKey });
|
|
68
|
+
const encodedPolyline = encodeURIComponent(polyline);
|
|
69
|
+
const result = yield axios_1.default.get(`https://api.mapbox.com/styles/v1/david-runnerpro/clqwrghcj013401qr5cch6z45/static/path-3+ea5b1b-100(${encodedPolyline})/auto/1080x1080?access_token=pk.eyJ1IjoiZGF2aWQtcnVubmVycHJvIiwiYSI6ImNscXdrZW56YTA0MTQybWxmNWx2b3Z6NjYifQ.g3vCR3HDRobLyr_4WFAeJA&logo=false`, { responseType: 'arraybuffer' });
|
|
70
|
+
const imageBuffer = Buffer.from(result.data, 'binary');
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
yield storage.bucket(process.env.CLOUD_STORAGE_BUCKET_PUBLIC).file(`Workout/${idWorkout}`).save(imageBuffer);
|
|
73
|
+
const urlMap = `https://storage.googleapis.com/${process.env.CLOUD_STORAGE_BUCKET_PUBLIC}/Workout/${idWorkout}`;
|
|
74
|
+
yield (0, db_1.query)('UPDATE [WORKOUT] SET [HAVE MAP IMAGE] = TRUE, [PHOTO URL] = ? WHERE [ID] = ?', [urlMap, idWorkout]);
|
|
75
|
+
});
|
|
76
|
+
const saveShareWorkoutImage = (id, type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
const serviceKey = path_1.default.join(process.cwd(), process.env.FIREBASE_STORAGE_CREDENTIALS);
|
|
79
|
+
const storage = new storage_1.Storage({ keyFilename: serviceKey });
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
const [exists] = yield storage.bucket(process.env.CLOUD_STORAGE_BUCKET_PUBLIC).file(`Workout/${id}`).exists();
|
|
82
|
+
let image;
|
|
83
|
+
if (!exists)
|
|
84
|
+
image = (0, getDefaultWorkoutImage_1.getDefaultWorkoutImage)(type);
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
else
|
|
87
|
+
[image] = yield storage.bucket(process.env.CLOUD_STORAGE_BUCKET_PUBLIC).file(`Workout/${id}`).download();
|
|
88
|
+
const shareMap = yield (0, generateShareMap_1.generateShareMap)(image, id);
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
yield storage.bucket(process.env.CLOUD_STORAGE_BUCKET_PUBLIC).file(`Workout/${id}-share`).save(shareMap);
|
|
91
|
+
const urlShare = `https://storage.googleapis.com/${process.env.CLOUD_STORAGE_BUCKET_PUBLIC}/Workout/${id}-share`;
|
|
92
|
+
yield (0, db_1.query)('UPDATE [WORKOUT] SET [PHOTO URL SHARE] = ? WHERE [ID] = ?', [urlShare, id]);
|
|
93
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runnerpro/backend",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.6",
|
|
4
4
|
"description": "A collection of common backend functions",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/cjs/index.js"
|
|
@@ -62,13 +62,14 @@
|
|
|
62
62
|
"uuidv4": "^6.2.13"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
+
"@google-cloud/storage": "^7.11.3",
|
|
65
66
|
"@google-cloud/translate": "^8.3.0",
|
|
66
67
|
"@notionhq/client": "^2.2.15",
|
|
67
68
|
"exifr": "^7.1.3",
|
|
68
69
|
"googleapis": "^144.0.0",
|
|
69
70
|
"multer": "^1.4.5-lts.1",
|
|
70
|
-
"
|
|
71
|
-
"
|
|
71
|
+
"oauth-signature": "1.5.0",
|
|
72
|
+
"socket.io": "^4.7.2"
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
|