@runnerpro/backend 1.15.0 → 1.15.3
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/chat/api/conversation.js +22 -8
- package/lib/cjs/index.js +1 -3
- package/lib/cjs/types/chat/api/conversation.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +1 -2
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/lib/cjs/chat/sendMessageChatToClient.js +0 -59
- package/lib/cjs/types/chat/sendMessageChatToClient.d.ts +0 -3
- package/lib/cjs/types/chat/sendMessageChatToClient.d.ts.map +0 -1
|
@@ -65,14 +65,17 @@ exports.conversationRoute = conversationRoute;
|
|
|
65
65
|
const getConversation = (req, res, { isClient }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
66
|
const idCliente = isClient ? req.session.userid : req.query.id;
|
|
67
67
|
const [header] = yield (0, index_1.query)('SELECT [NAME], [PREFERRED LANGUAGE] FROM [CLIENTE] WHERE [ID] = ?', [idCliente]);
|
|
68
|
-
let messages = yield (0, index_1.query)(`SELECT
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
let messages = yield (0, index_1.query)(`SELECT "CHAT MESSAGE".*,
|
|
69
|
+
"WORKOUT"."DATE" AS "WORKOUT DATE", "WORKOUT"."TYPE" AS "WORKOUT TYPE", "WORKOUT"."TITLE" AS "WORKOUT TITLE", "WORKOUT"."TITLE PREFERRED LANGUAGE" AS "WORKOUT TITLE",
|
|
70
|
+
"WORKOUT"."DURATION" AS "WORKOUT DURATION", "WORKOUT"."DISTANCE" AS "WORKOUT DISTANCE", "WORKOUT"."RESUMEN" AS "WORKOUT RESUMEN",
|
|
71
|
+
"WORKOUT"."PHOTO URL SHARE" AS "WORKOUT PHOTO URL SHARE", "WORKOUT"."PHOTO URL" AS "WORKOUT PHOTO URL", "FEELINGS", "FEELINGS DESCRIPTION",
|
|
72
|
+
"ENTRENADOR"."NAME" AS "ENTRENADOR NAME", "ENTRENADOR"."PHOTO" AS "ENTRENADOR PHOTO"
|
|
73
|
+
FROM "CHAT MESSAGE"
|
|
74
|
+
LEFT JOIN "WORKOUT" ON "WORKOUT"."ID" = "CHAT MESSAGE"."ID WORKOUT"
|
|
75
|
+
LEFT JOIN "CLIENTE" ON "CLIENTE"."ID" = "CHAT MESSAGE"."ID CLIENTE"
|
|
76
|
+
LEFT JOIN "ENTRENADOR" ON "ENTRENADOR"."ID" = COALESCE("CHAT MESSAGE"."ID SENDER VIEW", "CLIENTE"."ID ENTRENADOR PRINCIPAL")
|
|
77
|
+
WHERE "CHAT MESSAGE"."ID CLIENTE" = ? AND (${isClient} = FALSE OR "CHAT MESSAGE"."SHOW CLIENT" = TRUE)
|
|
78
|
+
ORDER BY "CHAT MESSAGE"."DATE" DESC
|
|
76
79
|
LIMIT 100`, [idCliente]);
|
|
77
80
|
const reacciones = yield (0, index_1.query)('SELECT [ID], [EMOJI], [ID CHAT], [ID SENDER] FROM [CHAT MESSAGE REACCION] WHERE [ID CHAT] IN (?)', [
|
|
78
81
|
messages.map((m) => m.id),
|
|
@@ -281,6 +284,15 @@ const sendMessage = (req, res, { sendNotification, firebaseMessaging, isClient }
|
|
|
281
284
|
// });
|
|
282
285
|
// }
|
|
283
286
|
}
|
|
287
|
+
const idSenderView = yield getSenderView({ userid, idCliente });
|
|
288
|
+
yield (0, index_1.query)('UPDATE [CHAT MESSAGE] SET [ID SENDER VIEW] = ? WHERE [ID] = ?', [idSenderView, message.id]);
|
|
289
|
+
});
|
|
290
|
+
const getSenderView = ({ userid, idCliente }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
291
|
+
const [cliente] = yield (0, index_1.query)('SELECT [ID ENTRENADOR PRINCIPAL], [ID ENTRENADOR SECUNDARIO] FROM [CLIENTE] WHERE [ID] = ?', [idCliente]);
|
|
292
|
+
if (cliente.idEntrenadorPrincipal === userid)
|
|
293
|
+
return cliente.idEntrenadorPrincipal;
|
|
294
|
+
else
|
|
295
|
+
return Math.random() < 0.4 ? cliente.idEntrenadorPrincipal : cliente.idEntrenadorSecundario; // 40% entrenador principal o 60% entrenador secundario
|
|
284
296
|
});
|
|
285
297
|
const sendEmoji = (req, res, { sendNotification, firebaseMessaging, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
286
298
|
const { emoji, messageId } = req.body;
|
|
@@ -384,6 +396,8 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
|
|
|
384
396
|
body: `Rubén: ${(0, index_2.t)(textFile, cliente.preferredLanguage)}`,
|
|
385
397
|
screen: common_1.NOTIFICATION_SCREEN_TYPES.CHAT,
|
|
386
398
|
});
|
|
399
|
+
const idSenderView = yield getSenderView({ userid, idCliente });
|
|
400
|
+
yield (0, index_1.query)('UPDATE [CHAT MESSAGE] SET [ID SENDER VIEW] = ? WHERE [ID] = ?', [idSenderView, idFile]);
|
|
387
401
|
}
|
|
388
402
|
});
|
|
389
403
|
const getThumbnailFromVideo = (videoPath, duration) => __awaiter(void 0, void 0, void 0, function* () {
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendPrompt = exports.saveResponseTime = exports.
|
|
3
|
+
exports.sendPrompt = exports.saveResponseTime = 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.longRunningQuery = exports.queryWithClient = 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");
|
|
@@ -56,8 +56,6 @@ const planificacionPrueba7dias_1 = require("./workout/planificacionPrueba7dias")
|
|
|
56
56
|
Object.defineProperty(exports, "getPlanificacionPrueba7dias", { enumerable: true, get: function () { return planificacionPrueba7dias_1.getPlanificacionPrueba7dias; } });
|
|
57
57
|
const saveWorkoutAplication_1 = require("./workout/saveWorkoutAplication");
|
|
58
58
|
Object.defineProperty(exports, "saveWorkoutAplication", { enumerable: true, get: function () { return saveWorkoutAplication_1.saveWorkoutAplication; } });
|
|
59
|
-
const sendMessageChatToClient_1 = require("./chat/sendMessageChatToClient");
|
|
60
|
-
Object.defineProperty(exports, "sendMessageChatToClient", { enumerable: true, get: function () { return sendMessageChatToClient_1.sendMessageChatToClient; } });
|
|
61
59
|
const saveResponseTime_1 = require("./chat/saveResponseTime");
|
|
62
60
|
Object.defineProperty(exports, "saveResponseTime", { enumerable: true, get: function () { return saveResponseTime_1.saveResponseTime; } });
|
|
63
61
|
const prompt_1 = require("./prompt");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SA0BpD,CAAC;
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SA0BpD,CAAC;AAuhBF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -15,8 +15,7 @@ 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
|
-
import { sendMessageChatToClient } from './chat/sendMessageChatToClient';
|
|
19
18
|
import { saveResponseTime } from './chat/saveResponseTime';
|
|
20
19
|
import { sendPrompt } from './prompt';
|
|
21
|
-
export { sendNotification, sleep, query, queryWithClient, longRunningQuery, 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,
|
|
20
|
+
export { sendNotification, sleep, query, queryWithClient, longRunningQuery, 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, saveResponseTime, sendPrompt, };
|
|
22
21
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,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ACL,gBAAgB,EAChB,KAAK,EACL,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,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,EACrB,gBAAgB,EAChB,UAAU,GACX,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,59 +0,0 @@
|
|
|
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.sendMessageChatToClient = void 0;
|
|
13
|
-
const messaging_1 = require("firebase-admin/messaging");
|
|
14
|
-
const index_1 = require("../err/index");
|
|
15
|
-
const index_2 = require("../sendNotification/index");
|
|
16
|
-
const index_3 = require("../db/index");
|
|
17
|
-
const common_1 = require("@runnerpro/common");
|
|
18
|
-
const saveResponseTime_1 = require("./saveResponseTime");
|
|
19
|
-
const sendMessageChatToClient = (idCliente, text, textPreferredLanguage, preferredLanguage, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
const { notification, entrenador, markAsRead = true, saveResponseTime: canSaveResponseTime = true } = options;
|
|
21
|
-
let idEntrenador;
|
|
22
|
-
if (entrenador)
|
|
23
|
-
idEntrenador = entrenador;
|
|
24
|
-
else {
|
|
25
|
-
const [entrenadorBBDD] = yield (0, index_3.query)('SELECT [ID ENTRENADOR] FROM [CLIENTE ENTRENADOR] WHERE [ID CLIENTE] = ? LIMIT 1', [idCliente]);
|
|
26
|
-
if (!entrenadorBBDD)
|
|
27
|
-
return;
|
|
28
|
-
idEntrenador = entrenadorBBDD.idEntrenador;
|
|
29
|
-
}
|
|
30
|
-
// Mark as read
|
|
31
|
-
if (markAsRead) {
|
|
32
|
-
yield (0, index_3.query)('UPDATE [CHAT MESSAGE] SET [READ] = TRUE WHERE [ID CLIENTE] = ? AND [READ] = FALSE AND ([ID SENDER] = ? OR [ID SENDER] IS NULL)', [
|
|
33
|
-
idCliente,
|
|
34
|
-
idCliente,
|
|
35
|
-
]);
|
|
36
|
-
}
|
|
37
|
-
// Save response time
|
|
38
|
-
if (canSaveResponseTime)
|
|
39
|
-
yield (0, saveResponseTime_1.saveResponseTime)(idCliente);
|
|
40
|
-
// Si no hay texto, es solo para que se marque como leido
|
|
41
|
-
if (text.length > 1) {
|
|
42
|
-
if (notification) {
|
|
43
|
-
try {
|
|
44
|
-
yield (0, index_2.sendNotification)({
|
|
45
|
-
firebaseMessaging: (0, messaging_1.getMessaging)(),
|
|
46
|
-
idCliente,
|
|
47
|
-
title: '💬 Nuevo mensaje de tu entrenador',
|
|
48
|
-
body: `Rubén: ${textPreferredLanguage || text}`,
|
|
49
|
-
screen: common_1.NOTIFICATION_SCREEN_TYPES.CHAT,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
catch (e) {
|
|
53
|
-
(0, index_1.err)(null, null, e, null);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
yield (0, index_3.query)('INSERT INTO [CHAT MESSAGE] ([ID CLIENTE], [ID SENDER], [TEXT], [TEXT PREFERRED LANGUAGE], [PREFERRED LANGUAGE], [TYPE]) VALUES (?, ?, ?, ?, ?, 1)', [idCliente, idEntrenador, text, textPreferredLanguage, preferredLanguage]);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
exports.sendMessageChatToClient = sendMessageChatToClient;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sendMessageChatToClient.d.ts","sourceRoot":"","sources":["../../../../src/chat/sendMessageChatToClient.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,uBAAuB,gHA0C5B,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
|