@runnerpro/backend 1.15.2 → 1.15.4
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 +24 -11
- package/lib/cjs/index.js +3 -3
- package/lib/cjs/types/chat/api/conversation.d.ts +6 -1
- package/lib/cjs/types/chat/api/conversation.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +2 -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
|
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.conversationRoute = void 0;
|
|
26
|
+
exports.updateSenderView = exports.conversationRoute = void 0;
|
|
27
27
|
const fs_1 = __importDefault(require("fs"));
|
|
28
28
|
const path_1 = __importDefault(require("path"));
|
|
29
29
|
const util_1 = require("util");
|
|
@@ -65,16 +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
|
-
FROM
|
|
74
|
-
LEFT JOIN
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
|
78
79
|
LIMIT 100`, [idCliente]);
|
|
79
80
|
const reacciones = yield (0, index_1.query)('SELECT [ID], [EMOJI], [ID CHAT], [ID SENDER] FROM [CHAT MESSAGE REACCION] WHERE [ID CHAT] IN (?)', [
|
|
80
81
|
messages.map((m) => m.id),
|
|
@@ -283,7 +284,18 @@ const sendMessage = (req, res, { sendNotification, firebaseMessaging, isClient }
|
|
|
283
284
|
// });
|
|
284
285
|
// }
|
|
285
286
|
}
|
|
287
|
+
yield updateSenderView({ userid, idCliente, idMessage: message.id });
|
|
286
288
|
});
|
|
289
|
+
const updateSenderView = ({ userid, idCliente, idMessage }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
290
|
+
const [cliente] = yield (0, index_1.query)('SELECT [ID ENTRENADOR PRINCIPAL], [ID ENTRENADOR SECUNDARIO] FROM [CLIENTE] WHERE [ID] = ?', [idCliente]);
|
|
291
|
+
let idSenderView;
|
|
292
|
+
if (cliente.idEntrenadorPrincipal === userid)
|
|
293
|
+
idSenderView = cliente.idEntrenadorPrincipal;
|
|
294
|
+
else
|
|
295
|
+
idSenderView = Math.random() < 0.4 ? cliente.idEntrenadorPrincipal : cliente.idEntrenadorSecundario; // 40% entrenador principal o 60% entrenador secundario
|
|
296
|
+
yield (0, index_1.query)('UPDATE [CHAT MESSAGE] SET [ID SENDER VIEW] = ? WHERE [ID] = ?', [idSenderView, idMessage]);
|
|
297
|
+
});
|
|
298
|
+
exports.updateSenderView = updateSenderView;
|
|
287
299
|
const sendEmoji = (req, res, { sendNotification, firebaseMessaging, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
288
300
|
const { emoji, messageId } = req.body;
|
|
289
301
|
const { userid } = req.session;
|
|
@@ -386,6 +398,7 @@ const sendFile = (req, res, { sendNotification, firebaseMessaging, isClient, buc
|
|
|
386
398
|
body: `Rubén: ${(0, index_2.t)(textFile, cliente.preferredLanguage)}`,
|
|
387
399
|
screen: common_1.NOTIFICATION_SCREEN_TYPES.CHAT,
|
|
388
400
|
});
|
|
401
|
+
yield updateSenderView({ userid, idCliente, idMessage: idFile });
|
|
389
402
|
}
|
|
390
403
|
});
|
|
391
404
|
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.
|
|
3
|
+
exports.updateSenderView = 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,9 +56,9 @@ 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");
|
|
64
62
|
Object.defineProperty(exports, "sendPrompt", { enumerable: true, get: function () { return prompt_1.sendPrompt; } });
|
|
63
|
+
const conversation_1 = require("./chat/api/conversation");
|
|
64
|
+
Object.defineProperty(exports, "updateSenderView", { enumerable: true, get: function () { return conversation_1.updateSenderView; } });
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
declare const conversationRoute: ({ router, ...params }: any) => void;
|
|
2
|
-
|
|
2
|
+
declare const updateSenderView: ({ userid, idCliente, idMessage }: {
|
|
3
|
+
userid: any;
|
|
4
|
+
idCliente: any;
|
|
5
|
+
idMessage: any;
|
|
6
|
+
}) => Promise<void>;
|
|
7
|
+
export { conversationRoute, updateSenderView };
|
|
3
8
|
//# sourceMappingURL=conversation.d.ts.map
|
|
@@ -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;AA4PF,QAAA,MAAM,gBAAgB;;;;mBAQrB,CAAC;AAsRF,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,CAAC"}
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ 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
|
-
|
|
20
|
+
import { updateSenderView } from './chat/api/conversation';
|
|
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, saveResponseTime, sendPrompt, updateSenderView, };
|
|
22
22
|
//# 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,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC7F,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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 @@
|
|
|
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"}
|