@runnerpro/backend 1.0.26 → 1.1.1
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 +2 -1
- package/lib/cjs/notion/index.js +8 -2
- package/lib/cjs/translation/index.js +35 -1
- package/lib/cjs/types/index.d.ts +2 -2
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/notion/index.d.ts +1 -0
- package/lib/cjs/types/notion/index.d.ts.map +1 -1
- package/lib/cjs/types/translation/index.d.ts +8 -1
- package/lib/cjs/types/translation/index.d.ts.map +1 -1
- package/package.json +1 -1
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; } });
|
package/lib/cjs/notion/index.js
CHANGED
|
@@ -11,8 +11,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.NOTION_DATABASES_ID = exports.notionAddPage = exports.notionGetDatabase = exports.notionGetUsers = void 0;
|
|
13
13
|
const client_1 = require("@notionhq/client");
|
|
14
|
+
/*
|
|
15
|
+
Obtener ID de una BBDD de Notion
|
|
16
|
+
1º Ir al link de la base de datos (no a la página, si no a la BBDD directamente)
|
|
17
|
+
2º Coger el ID de la url -> notion.so/ID?v=VERSION
|
|
18
|
+
3º Separar el ID en - con en los mimos lugares que las otras BBDD
|
|
19
|
+
4º Arriba a la derecha en los 3 puntos horizontales -> Conexiones -> Conectar con API (logo de RunnerPro)
|
|
20
|
+
*/
|
|
14
21
|
const NOTION_DATABASES_ID = {
|
|
15
22
|
REGISTRADOS_PRUEBA_7_DIAS: '25732354-92bd-4bb5-8937-0ad583b795ab',
|
|
23
|
+
OBSERVAR_CLIENTE: '47fc4035-7028-41c2-8b81-8e91d44a989b',
|
|
16
24
|
};
|
|
17
25
|
exports.NOTION_DATABASES_ID = NOTION_DATABASES_ID;
|
|
18
26
|
const getNotionDatabaseProperties = (databaseId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -38,7 +46,6 @@ const notionGetDatabase = (databaseId) => {
|
|
|
38
46
|
exports.notionGetDatabase = notionGetDatabase;
|
|
39
47
|
const notionAddPage = (databaseId, values) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
48
|
const properties = yield getNotionDatabaseProperties(databaseId);
|
|
41
|
-
console.log(properties);
|
|
42
49
|
// Transform values into properties format
|
|
43
50
|
const propertiesValues = {};
|
|
44
51
|
Object.keys(values).forEach((key) => {
|
|
@@ -73,7 +80,6 @@ const notionAddPage = (databaseId, values) => __awaiter(void 0, void 0, void 0,
|
|
|
73
80
|
};
|
|
74
81
|
}
|
|
75
82
|
});
|
|
76
|
-
console.log(propertiesValues);
|
|
77
83
|
return notion.pages.create({
|
|
78
84
|
parent: {
|
|
79
85
|
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;
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -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;
|
|
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,5 +1,6 @@
|
|
|
1
1
|
declare const NOTION_DATABASES_ID: {
|
|
2
2
|
REGISTRADOS_PRUEBA_7_DIAS: string;
|
|
3
|
+
OBSERVAR_CLIENTE: string;
|
|
3
4
|
};
|
|
4
5
|
declare const notionGetUsers: () => Promise<import("@notionhq/client/build/src/api-endpoints").ListUsersResponse>;
|
|
5
6
|
declare const notionGetDatabase: (databaseId: any) => Promise<(import("@notionhq/client/build/src/api-endpoints").PartialDatabaseObjectResponse | import("@notionhq/client/build/src/api-endpoints").DatabaseObjectResponse | import("@notionhq/client/build/src/api-endpoints").PageObjectResponse | import("@notionhq/client/build/src/api-endpoints").PartialPageObjectResponse)[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/notion/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/notion/index.ts"],"names":[],"mappings":"AASA,QAAA,MAAM,mBAAmB;;;CAGxB,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
|
-
|
|
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;
|
|
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"}
|