@runnerpro/backend 1.7.5 → 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/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;
@@ -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
- 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, };
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,OAAO,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,gCAAgC,EAAE,MAAM,eAAe,CAAC;AACvG,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AACjH,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,WAAW,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAClH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAEjF,OAAO,EACL,gBAA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BAAiB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAClH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAExE,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,KAAK,EACL,UAAU,EACV,SAAS,EACT,IAAI,EACJ,QAAQ,EACR,GAAG,EACH,OAAO,EACP,WAAW,EACX,aAAa,EACb,SAAS,EACT,SAAS,EACT,cAAc,EACd,gCAAgC,EAChC,IAAI,EACJ,OAAO,EACP,WAAW,EACX,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,2BAA2B,EAC3B,qBAAqB,GACtB,CAAC"}
@@ -0,0 +1,8 @@
1
+ declare const getTitleDescriptionTranslated: (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"}
@@ -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"}
@@ -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.5",
3
+ "version": "1.7.6",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"