@runnerpro/backend 1.17.2 → 1.17.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.
|
@@ -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.sendMessage = exports.updateSenderView = exports.conversationRoute = void 0;
|
|
26
|
+
exports.editConversationMessage = exports.sendMessage = 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");
|
|
@@ -129,25 +129,67 @@ const deleteConversationMessage = (req, res, { isClient }) => __awaiter(void 0,
|
|
|
129
129
|
// - Se elimina la sugerencia
|
|
130
130
|
// - Se elimina el mensaje programado
|
|
131
131
|
// TODO: Comprobar que el cliente/entrenador puede editar/eliminar el mensaje (no se haya contestado ya y que no haya pasado el tiempo de cortesía)
|
|
132
|
+
/**
|
|
133
|
+
* Edita un mensaje de chat existente
|
|
134
|
+
*
|
|
135
|
+
* @param req - Request con params y body
|
|
136
|
+
* @param req.params.id - ID del mensaje a editar
|
|
137
|
+
* @param req.body.text - Nuevo texto del mensaje
|
|
138
|
+
* @param req.body.idWorkout - ID del workout a linkear (opcional, solo entrenadores). Si se envía null, se quita el workout linkeado
|
|
139
|
+
* @param res - Response
|
|
140
|
+
* @param params.isClient - Si el sender es cliente (true) o entrenador (false)
|
|
141
|
+
* @returns Promise<void> - Envía { status: 'ok' } en la respuesta
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // Editar solo el texto
|
|
146
|
+
* PUT /chat/conversation/123
|
|
147
|
+
* { "text": "Texto corregido" }
|
|
148
|
+
*
|
|
149
|
+
* // Editar texto y agregar workout
|
|
150
|
+
* PUT /chat/conversation/123
|
|
151
|
+
* { "text": "Texto corregido", "idWorkout": "workout456" }
|
|
152
|
+
*
|
|
153
|
+
* // Quitar workout linkeado
|
|
154
|
+
* PUT /chat/conversation/123
|
|
155
|
+
* { "text": "Texto corregido", "idWorkout": null }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
132
158
|
const editConversationMessage = (req, res, { isClient }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
159
|
const { id } = req.params;
|
|
134
|
-
const { text } = req.body;
|
|
160
|
+
const { text, idWorkout: idWorkoutBody } = req.body;
|
|
135
161
|
if (!(yield canEditOrDeleteMessage({ idMessage: id, isClient, userid: req.session.userid })))
|
|
136
162
|
return res.send({ status: 'ok' });
|
|
137
|
-
const [message] = yield (0, index_1.query)('SELECT [ID CLIENTE] FROM [CHAT MESSAGE] WHERE [ID] = ?', [id]);
|
|
163
|
+
const [message] = yield (0, index_1.query)('SELECT [ID CLIENTE], [ID WORKOUT] FROM [CHAT MESSAGE] WHERE [ID] = ?', [id]);
|
|
138
164
|
// Devuelve el texto en el otro idioma si el cliente no habla español y el idioma del cliente
|
|
139
165
|
const { textSpanish, textPreferredLanguage } = yield getPreferredLanguageForChat({
|
|
140
166
|
text,
|
|
141
167
|
idCliente: message.idCliente,
|
|
142
168
|
isClient,
|
|
143
169
|
});
|
|
144
|
-
|
|
170
|
+
// ✅ Linkeo de workout desde la edición (solo para entrenadores)
|
|
171
|
+
let idWorkout = message.idWorkout; // Mantener el workout existente por defecto
|
|
172
|
+
if (idWorkoutBody && !isClient) {
|
|
173
|
+
// Validar que el workout existe y pertenece al cliente
|
|
174
|
+
const [workout] = yield (0, index_1.query)('SELECT [ID] FROM [WORKOUT] WHERE [ID] = ? AND [ID CLIENTE] = ?', [idWorkoutBody, message.idCliente]);
|
|
175
|
+
if (workout) {
|
|
176
|
+
idWorkout = idWorkoutBody;
|
|
177
|
+
}
|
|
178
|
+
// Si el workout no existe o no pertenece al cliente, se mantiene el idWorkout actual (o null)
|
|
179
|
+
}
|
|
180
|
+
else if (idWorkoutBody === null && !isClient) {
|
|
181
|
+
// Permitir quitar el workout si se envía explícitamente null
|
|
182
|
+
idWorkout = null;
|
|
183
|
+
}
|
|
184
|
+
yield (0, index_1.query)('UPDATE [CHAT MESSAGE] SET [TEXT] = ?, [TEXT PREFERRED LANGUAGE] = ?, [ID WORKOUT] = ?, [EDITADO] = TRUE WHERE [ID] = ?', [
|
|
145
185
|
textSpanish,
|
|
146
186
|
textPreferredLanguage,
|
|
187
|
+
idWorkout,
|
|
147
188
|
id,
|
|
148
189
|
]);
|
|
149
190
|
res.send({ status: 'ok' });
|
|
150
191
|
});
|
|
192
|
+
exports.editConversationMessage = editConversationMessage;
|
|
151
193
|
const canEditOrDeleteMessage = ({ idMessage, isClient, userid }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
152
194
|
const [message] = yield (0, index_1.query)('SELECT [ID], "ID CLIENTE", "ID SENDER" FROM [CHAT MESSAGE] WHERE [ID] = ? AND (? = FALSE OR [ID CLIENTE] = ?)', [
|
|
153
195
|
idMessage,
|
|
@@ -1,4 +1,31 @@
|
|
|
1
1
|
declare const conversationRoute: ({ router, ...params }: any) => void;
|
|
2
|
+
/**
|
|
3
|
+
* Edita un mensaje de chat existente
|
|
4
|
+
*
|
|
5
|
+
* @param req - Request con params y body
|
|
6
|
+
* @param req.params.id - ID del mensaje a editar
|
|
7
|
+
* @param req.body.text - Nuevo texto del mensaje
|
|
8
|
+
* @param req.body.idWorkout - ID del workout a linkear (opcional, solo entrenadores). Si se envía null, se quita el workout linkeado
|
|
9
|
+
* @param res - Response
|
|
10
|
+
* @param params.isClient - Si el sender es cliente (true) o entrenador (false)
|
|
11
|
+
* @returns Promise<void> - Envía { status: 'ok' } en la respuesta
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Editar solo el texto
|
|
16
|
+
* PUT /chat/conversation/123
|
|
17
|
+
* { "text": "Texto corregido" }
|
|
18
|
+
*
|
|
19
|
+
* // Editar texto y agregar workout
|
|
20
|
+
* PUT /chat/conversation/123
|
|
21
|
+
* { "text": "Texto corregido", "idWorkout": "workout456" }
|
|
22
|
+
*
|
|
23
|
+
* // Quitar workout linkeado
|
|
24
|
+
* PUT /chat/conversation/123
|
|
25
|
+
* { "text": "Texto corregido", "idWorkout": null }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare const editConversationMessage: (req: any, res: any, { isClient }: any) => Promise<any>;
|
|
2
29
|
/**
|
|
3
30
|
* Envía un mensaje de chat entre entrenador y cliente
|
|
4
31
|
*
|
|
@@ -31,5 +58,5 @@ declare const updateSenderView: ({ userid, idCliente, idMessage }: {
|
|
|
31
58
|
idCliente: any;
|
|
32
59
|
idMessage: any;
|
|
33
60
|
}) => Promise<void>;
|
|
34
|
-
export { conversationRoute, updateSenderView, sendMessage };
|
|
61
|
+
export { conversationRoute, updateSenderView, sendMessage, editConversationMessage };
|
|
35
62
|
//# sourceMappingURL=conversation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAmBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SA0BpD,CAAC;
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAmBA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SA0BpD,CAAC;AA0EF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,QAAA,MAAM,uBAAuB,qCAAkC,GAAG,iBAqCjE,CAAC;AAmGF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,QAAA,MAAM,WAAW,0EAAuE,GAAG,kBAkE1F,CAAC;AAEF,QAAA,MAAM,gBAAgB;;;;mBAqBrB,CAAC;AA8RF,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,WAAW,EAAE,uBAAuB,EAAE,CAAC"}
|