@runnerpro/backend 1.0.26 → 1.1.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.
package/lib/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NOTION_DATABASES_ID = exports.notionAddPage = exports.notionGetDatabase = exports.notionGetUsers = exports.getCountNotificaciones = exports.chatExposed = exports.chatApi = exports.chat = exports.useTranslation = exports.LANGUAGES = exports.translate = exports.fetchIA = exports.err = exports.sendMail = exports.batchQuery = exports.query = exports.sleep = exports.sendNotification = void 0;
3
+ exports.NOTION_DATABASES_ID = exports.notionAddPage = exports.notionGetDatabase = exports.notionGetUsers = exports.getCountNotificaciones = exports.chatExposed = exports.chatApi = exports.chat = exports.getExerciseTranslatedDescription = exports.useTranslation = exports.LANGUAGES = exports.translate = exports.fetchIA = exports.err = exports.sendMail = 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");
@@ -18,6 +18,7 @@ const translation_1 = require("./translation");
18
18
  Object.defineProperty(exports, "translate", { enumerable: true, get: function () { return translation_1.translate; } });
19
19
  Object.defineProperty(exports, "LANGUAGES", { enumerable: true, get: function () { return translation_1.LANGUAGES; } });
20
20
  Object.defineProperty(exports, "useTranslation", { enumerable: true, get: function () { return translation_1.useTranslation; } });
21
+ Object.defineProperty(exports, "getExerciseTranslatedDescription", { enumerable: true, get: function () { return translation_1.getExerciseTranslatedDescription; } });
21
22
  const chat_1 = require("./chat");
22
23
  Object.defineProperty(exports, "chat", { enumerable: true, get: function () { return chat_1.chat; } });
23
24
  Object.defineProperty(exports, "chatApi", { enumerable: true, get: function () { return chat_1.chatApi; } });
@@ -38,7 +38,6 @@ const notionGetDatabase = (databaseId) => {
38
38
  exports.notionGetDatabase = notionGetDatabase;
39
39
  const notionAddPage = (databaseId, values) => __awaiter(void 0, void 0, void 0, function* () {
40
40
  const properties = yield getNotionDatabaseProperties(databaseId);
41
- console.log(properties);
42
41
  // Transform values into properties format
43
42
  const propertiesValues = {};
44
43
  Object.keys(values).forEach((key) => {
@@ -73,7 +72,6 @@ const notionAddPage = (databaseId, values) => __awaiter(void 0, void 0, void 0,
73
72
  };
74
73
  }
75
74
  });
76
- console.log(propertiesValues);
77
75
  return notion.pages.create({
78
76
  parent: {
79
77
  database_id: databaseId,
@@ -12,11 +12,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.useTranslation = exports.translate = exports.LANGUAGES = void 0;
15
+ exports.getExerciseTranslatedDescription = exports.useTranslation = exports.translate = exports.LANGUAGES = void 0;
16
16
  const translate_1 = require("@google-cloud/translate");
17
17
  const common_1 = require("@runnerpro/common");
18
18
  Object.defineProperty(exports, "LANGUAGES", { enumerable: true, get: function () { return common_1.LANGUAGES; } });
19
19
  const fs_1 = __importDefault(require("fs"));
20
+ const index_1 = require("../db/index");
20
21
  const translate = (text, { fromLanguage, toLanguage }) => __awaiter(void 0, void 0, void 0, function* () {
21
22
  const projectId = process.env.GCP_PROYECT_ID;
22
23
  const location = 'global';
@@ -64,3 +65,36 @@ const useTranslation = (language, path) => {
64
65
  };
65
66
  };
66
67
  exports.useTranslation = useTranslation;
68
+ const getExerciseTranslatedDescription = ({ exercise, language }) => __awaiter(void 0, void 0, void 0, function* () {
69
+ if (language === common_1.LANGUAGES.ES)
70
+ return { description: null, language: null };
71
+ // Para acceder a la descripción, el key es -> descriptionEs
72
+ const descriptionLanguageKey = `description${language[0].toUpperCase()}${language[1].toLowerCase()}`;
73
+ let description;
74
+ // Algunos exercise vienen del frontend y no tienen la descripción traducida en la variable exercise
75
+ if (exercise[descriptionLanguageKey]) {
76
+ description = exercise[descriptionLanguageKey];
77
+ }
78
+ else {
79
+ const [exerciseData] = yield (0, index_1.query)(`SELECT [DESCRIPTION], [DESCRIPTION ${language.toUpperCase()}] FROM [EXERCISE] WHERE [ID] = ?`, [
80
+ exercise.idExercise || exercise.exercise.id,
81
+ ]);
82
+ // Si la descripción del ejercicio es la de por defecto al insertar un ejercicio, entonces se coge la traducción de la bbdd
83
+ if (exerciseData.description === exercise.description) {
84
+ description = exerciseData[descriptionLanguageKey];
85
+ }
86
+ else if (exercise.description === '') {
87
+ description = '';
88
+ }
89
+ else {
90
+ // Si el entrenador ha cambiado la descripción del ejercicio, se traduce la descripción que viene del frontend
91
+ // @ts-ignore
92
+ description = yield translate(exercise.description, { fromLanguage: common_1.LANGUAGES.ES, toLanguage: language });
93
+ }
94
+ }
95
+ return {
96
+ description,
97
+ language,
98
+ };
99
+ });
100
+ exports.getExerciseTranslatedDescription = getExerciseTranslatedDescription;
@@ -4,8 +4,8 @@ import { query, batchQuery } from './db';
4
4
  import { sendMail } from './sendMail';
5
5
  import { err } from './err';
6
6
  import { fetchIA } from './fetch/fetchIA';
7
- import { translate, LANGUAGES, useTranslation } from './translation';
7
+ import { translate, LANGUAGES, useTranslation, getExerciseTranslatedDescription } from './translation';
8
8
  import { chat, chatApi, chatExposed, getCountNotificaciones } from './chat';
9
9
  import { notionGetUsers, notionGetDatabase, notionAddPage, NOTION_DATABASES_ID } from './notion';
10
- export { sendNotification, sleep, query, batchQuery, sendMail, err, fetchIA, translate, LANGUAGES, useTranslation, chat, chatApi, chatExposed, getCountNotificaciones, notionGetUsers, notionGetDatabase, notionAddPage, NOTION_DATABASES_ID, };
10
+ export { sendNotification, sleep, query, batchQuery, sendMail, err, fetchIA, translate, LANGUAGES, useTranslation, getExerciseTranslatedDescription, chat, chatApi, chatExposed, getCountNotificaciones, notionGetUsers, notionGetDatabase, notionAddPage, NOTION_DATABASES_ID, };
11
11
  //# 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,MAAM,MAAM,CAAC;AACzC,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,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEjG,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,KAAK,EACL,UAAU,EACV,QAAQ,EACR,GAAG,EACH,OAAO,EACP,SAAS,EACT,SAAS,EACT,cAAc,EACd,IAAI,EACJ,OAAO,EACP,WAAW,EACX,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,mBAAmB,GACpB,CAAC"}
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,MAAM,MAAM,CAAC;AACzC,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,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,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEjG,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,KAAK,EACL,UAAU,EACV,QAAQ,EACR,GAAG,EACH,OAAO,EACP,SAAS,EACT,SAAS,EACT,cAAc,EACd,gCAAgC,EAChC,IAAI,EACJ,OAAO,EACP,WAAW,EACX,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,mBAAmB,GACpB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/notion/index.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,mBAAmB;;CAExB,CAAC;AAcF,QAAA,MAAM,cAAc,qFAEnB,CAAC;AAEF,QAAA,MAAM,iBAAiB,uVAMtB,CAAC;AAEF,QAAA,MAAM,aAAa,kHA2ClB,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,aAAa,EAAE,mBAAmB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/notion/index.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,mBAAmB;;CAExB,CAAC;AAcF,QAAA,MAAM,cAAc,qFAEnB,CAAC;AAEF,QAAA,MAAM,iBAAiB,uVAMtB,CAAC;AAEF,QAAA,MAAM,aAAa,kHAwClB,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,aAAa,EAAE,mBAAmB,EAAE,CAAC"}
@@ -7,5 +7,12 @@ declare const translate: (text: string, { fromLanguage, toLanguage }: {
7
7
  declare const useTranslation: (language: string, path: string) => {
8
8
  t: (text: string, interpolation: any) => any;
9
9
  };
10
- export { LANGUAGES, translate, useTranslation };
10
+ declare const getExerciseTranslatedDescription: ({ exercise, language }: {
11
+ exercise: any;
12
+ language: any;
13
+ }) => Promise<{
14
+ description: any;
15
+ language: any;
16
+ }>;
17
+ export { LANGUAGES, translate, useTranslation, getExerciseTranslatedDescription };
11
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/translation/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,KAAK,cAAc,GAAG,MAAM,OAAO,SAAS,CAAC;AAE7C,QAAA,MAAM,SAAS,SACP,MAAM;kBACkC,cAAc;gBAAc,cAAc;MACvF,QAAQ,MAAM,CAwBhB,CAAC;AAEF,QAAA,MAAM,cAAc,aAAc,MAAM,QAAQ,MAAM;cAExC,MAAM,iBAAiB,GAAG;CAkBvC,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/translation/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAI9C,KAAK,cAAc,GAAG,MAAM,OAAO,SAAS,CAAC;AAE7C,QAAA,MAAM,SAAS,SACP,MAAM;kBACkC,cAAc;gBAAc,cAAc;MACvF,QAAQ,MAAM,CAwBhB,CAAC;AAEF,QAAA,MAAM,cAAc,aAAc,MAAM,QAAQ,MAAM;cAExC,MAAM,iBAAiB,GAAG;CAkBvC,CAAC;AAEF,QAAA,MAAM,gCAAgC;;;;;;EA4BrC,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,gCAAgC,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.0.26",
3
+ "version": "1.1.0",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"