@runnerpro/backend 1.14.0 → 1.14.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.
|
@@ -56,6 +56,8 @@ const conversationRoute = (_a) => {
|
|
|
56
56
|
router.get('/conversation/thumbnail/:id', (req, res, next) => getConversationThumbnail(req, res, params).catch((error) => (0, index_1.err)(req, res, error, next)));
|
|
57
57
|
router.get('/conversation/file/:id', (req, res, next) => getConversationFile(req, res, params).catch((error) => (0, index_1.err)(req, res, error, next)));
|
|
58
58
|
router.post('/conversation/send', (req, res, next) => sendMessage(req, res, params).catch((error) => (0, index_1.err)(req, res, error, next)));
|
|
59
|
+
router.post('/conversation/send-emoji', (req, res, next) => sendEmoji(req, res, params).catch((error) => (0, index_1.err)(req, res, error, next)));
|
|
60
|
+
router.delete('/conversation/emoji/:id', (req, res, next) => deleteEmoji(req, res).catch((error) => (0, index_1.err)(req, res, error, next)));
|
|
59
61
|
router.post('/conversation/send-file', uploadFile.single('file'), (req, res, next) => sendFile(req, res, params).catch((error) => (0, index_1.err)(req, res, error, next)));
|
|
60
62
|
router.post('/conversation/read', (req, res, next) => readMessage(req, res, params).catch((error) => (0, index_1.err)(req, res, error, next)));
|
|
61
63
|
};
|
|
@@ -72,6 +74,9 @@ const getConversation = (req, res, { isClient }) => __awaiter(void 0, void 0, vo
|
|
|
72
74
|
WHERE [CHAT MESSAGE].[ID CLIENTE] = ? AND (${isClient} = FALSE OR [CHAT MESSAGE].[SHOW CLIENT] = TRUE)
|
|
73
75
|
ORDER BY [CHAT MESSAGE].[DATE] DESC
|
|
74
76
|
LIMIT 100`, [idCliente]);
|
|
77
|
+
const [reacciones] = yield (0, index_1.query)('SELECT [EMOJI], [ID CHAT], [ID SENDER] FROM [CHAT MESSAGE REACCION] WHERE [ID CHAT] IN (?)', [
|
|
78
|
+
messages.map((m) => m.id),
|
|
79
|
+
]);
|
|
75
80
|
messages = messages.reverse();
|
|
76
81
|
// Si el cliente no habla español, se muestran los mensajes en el idioma del cliente. El entrenador siempre ve los mensajes en español que están en la columna [TEXT]
|
|
77
82
|
if (header.preferredLanguage !== common_1.LANGUAGES.ES && isClient) {
|
|
@@ -82,6 +87,7 @@ const getConversation = (req, res, { isClient }) => __awaiter(void 0, void 0, vo
|
|
|
82
87
|
message.reply = messages.find((m) => m.id === message.replyMessageId);
|
|
83
88
|
if (message.workoutTitlePreferredLanguage)
|
|
84
89
|
message.workoutTitle = message.workoutTitlePreferredLanguage;
|
|
90
|
+
fillReacciones(message, reacciones);
|
|
85
91
|
return message;
|
|
86
92
|
});
|
|
87
93
|
}
|
|
@@ -89,6 +95,7 @@ const getConversation = (req, res, { isClient }) => __awaiter(void 0, void 0, vo
|
|
|
89
95
|
messages = messages.map((message) => {
|
|
90
96
|
if (message.replyMessageId)
|
|
91
97
|
message.reply = messages.find((m) => m.id === message.replyMessageId);
|
|
98
|
+
fillReacciones(message, reacciones);
|
|
92
99
|
return message;
|
|
93
100
|
});
|
|
94
101
|
}
|
|
@@ -97,6 +104,9 @@ const getConversation = (req, res, { isClient }) => __awaiter(void 0, void 0, vo
|
|
|
97
104
|
if (isClient)
|
|
98
105
|
yield markReadMessage({ isClient, idCliente });
|
|
99
106
|
});
|
|
107
|
+
const fillReacciones = (message, reacciones) => {
|
|
108
|
+
message.reacciones = reacciones.filter((r) => Number(r.idChat) === Number(message.id));
|
|
109
|
+
};
|
|
100
110
|
const deleteConversationMessage = (req, res, { isClient }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
111
|
const { id } = req.params;
|
|
102
112
|
if (!(yield canEditOrDeleteMessage({ idMessage: id, isClient, userid: req.session.userid })))
|
|
@@ -260,6 +270,37 @@ const sendMessage = (req, res, { sendNotification, firebaseMessaging, isClient }
|
|
|
260
270
|
// }
|
|
261
271
|
}
|
|
262
272
|
});
|
|
273
|
+
const sendEmoji = (req, res, { sendNotification, firebaseMessaging, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
274
|
+
const { emoji, messageId } = req.body;
|
|
275
|
+
const { userid } = req.session;
|
|
276
|
+
const idCliente = isClient ? userid : req.body.idCliente;
|
|
277
|
+
const [isClientMessage] = yield (0, index_1.query)('SELECT [ID CLIENTE] FROM [CHAT MESSAGE] WHERE [ID] = ?', [messageId]);
|
|
278
|
+
if (isClientMessage.idCliente !== idCliente)
|
|
279
|
+
return res.send({ idReaction: null });
|
|
280
|
+
const [reaction] = yield (0, index_1.query)(`INSERT INTO [CHAT MESSAGE REACCION] ([EMOJI], [ID CHAT], [ID SENDER]) VALUES (?, ?, ?) RETURNING [ID]`, [
|
|
281
|
+
emoji,
|
|
282
|
+
messageId,
|
|
283
|
+
userid,
|
|
284
|
+
]);
|
|
285
|
+
res.send({ idReaction: reaction.id });
|
|
286
|
+
if (!isClient) {
|
|
287
|
+
sendNotification({
|
|
288
|
+
firebaseMessaging,
|
|
289
|
+
idCliente,
|
|
290
|
+
body: `Rubén ha reaccionado a un mensaje '${emoji}'`,
|
|
291
|
+
screen: common_1.NOTIFICATION_SCREEN_TYPES.CHAT,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
const deleteEmoji = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
296
|
+
const { id } = req.params;
|
|
297
|
+
const { userid } = req.session;
|
|
298
|
+
const [isUserReaction] = yield (0, index_1.query)('SELECT [ID SENDER] FROM [CHAT MESSAGE REACCION] WHERE [ID] = ?', [id]);
|
|
299
|
+
if (isUserReaction.idSender !== userid)
|
|
300
|
+
return res.send({ status: 'ok' });
|
|
301
|
+
yield (0, index_1.query)('DELETE FROM [CHAT MESSAGE REACCION] WHERE [ID] = ?', [id]);
|
|
302
|
+
res.send({ status: 'ok' });
|
|
303
|
+
});
|
|
263
304
|
const getPreferredLanguageForChat = ({ text, idCliente, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
264
305
|
const [{ preferredLanguage }] = yield (0, index_1.query)('SELECT [PREFERRED LANGUAGE] FROM [CLIENTE] WHERE [ID] = ?', [idCliente]);
|
|
265
306
|
if (preferredLanguage === common_1.LANGUAGES.ES)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAyBpD,CAAC;AAgfF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|