@runnerpro/backend 1.10.14 → 1.10.15

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.
@@ -91,7 +91,6 @@ const getConversation = (req, res, { query, isClient }) => __awaiter(void 0, voi
91
91
  if (isClient)
92
92
  yield markReadMessage({ isClient, query, idCliente });
93
93
  });
94
- // TODO: Tener en cuenta para el flujo de sugerir mensaje
95
94
  const deleteConversationMessage = (req, res, { query, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
96
95
  const { id } = req.params;
97
96
  const [message] = yield query('SELECT [ID] FROM [CHAT MESSAGE] WHERE [ID] = ? AND (? = FALSE OR [ID CLIENTE] = ?)', [
@@ -101,28 +100,47 @@ const deleteConversationMessage = (req, res, { query, isClient }) => __awaiter(v
101
100
  ]);
102
101
  if (!message)
103
102
  return res.status(404).send('Not found');
104
- if (isClient) {
103
+ if (yield canEditOrDeleteMessage({ idMessage: id, isClient }))
104
+ return res.send({ status: 'ok' });
105
+ if (isClient)
105
106
  yield query('UPDATE [CHAT MESSAGE] SET [ELIMINADO] = TRUE WHERE [ID] = ?', [id]);
106
- }
107
- else {
107
+ else
108
108
  yield query('DELETE FROM [CHAT MESSAGE] WHERE [ID] = ?', [id]);
109
- }
110
109
  res.send({ status: 'ok' });
111
110
  });
112
- // TODO: Sugerencias de texto
111
+ // TODO: Si el cliente elimina o edita y ya se ha sugerido el mensaje
112
+ // - Se elimina la sugerencia
113
+ // - Se elimina el mensaje programado
114
+ // 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)
113
115
  const editConversationMessage = (req, res, { query, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
114
116
  const { id } = req.params;
115
117
  const { text } = req.body;
116
- const [message] = yield query('SELECT [ID] FROM [CHAT MESSAGE] WHERE [ID] = ? AND (? = FALSE OR [ID CLIENTE] = ?)', [
118
+ const [message] = yield query('SELECT [ID], [ID CLIENTE] FROM [CHAT MESSAGE] WHERE [ID] = ? AND (? = FALSE OR [ID CLIENTE] = ?)', [
117
119
  id,
118
120
  isClient,
119
121
  req.session.userid,
120
122
  ]);
121
123
  if (!message)
122
124
  return res.status(404).send('Not found');
123
- yield query('UPDATE [CHAT MESSAGE] SET [TEXT] = ?, [EDITADO] = TRUE WHERE [ID] = ?', [text, id]);
125
+ if (yield canEditOrDeleteMessage({ idMessage: id, isClient }))
126
+ return res.send({ status: 'ok' });
127
+ // Devuelve el texto en el otro idioma si el cliente no habla español y el idioma del cliente
128
+ const { textSpanish, textPreferredLanguage } = yield getPreferredLanguageForChat({
129
+ text,
130
+ idCliente: message.idCliente,
131
+ isClient,
132
+ query,
133
+ });
134
+ yield query('UPDATE [CHAT MESSAGE] SET [TEXT] = ?, [TEXT PREFERRED LANGUAGE] = ?, [EDITADO] = TRUE WHERE [ID] = ?', [
135
+ textSpanish,
136
+ textPreferredLanguage,
137
+ id,
138
+ ]);
124
139
  res.send({ status: 'ok' });
125
140
  });
141
+ const canEditOrDeleteMessage = ({ idMessage, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
142
+ return false;
143
+ });
126
144
  const getConversationImage = (req, res, { query, bucket, isClient }) => __awaiter(void 0, void 0, void 0, function* () {
127
145
  const result = yield getChatFile({
128
146
  query,
@@ -1 +1 @@
1
- {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAYA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAoBpD,CAAC;AAgRF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAYA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAoBpD,CAAC;AAwSF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.10.14",
3
+ "version": "1.10.15",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"