@runnerpro/backend 1.3.11 → 1.4.0

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.
@@ -240,6 +240,7 @@ const readMessage = (req, res, { query, isClient }) => __awaiter(void 0, void 0,
240
240
  const markReadMessage = ({ isClient, query, idCliente }) => __awaiter(void 0, void 0, void 0, function* () {
241
241
  const conditionSender = isClient ? ' AND [ID SENDER] != ?' : ' AND [ID SENDER] = ?';
242
242
  yield query('UPDATE [CHAT MESSAGE] SET [READ] = TRUE WHERE [ID CLIENTE] = ? AND [READ] = FALSE ' + conditionSender, [idCliente, idCliente]);
243
+ yield saveResponseTime({ query, isClient, idCliente });
243
244
  });
244
245
  const resizeImage = (data, filePath, mimetype) => __awaiter(void 0, void 0, void 0, function* () {
245
246
  if (mimetype.includes('webp'))
@@ -280,3 +281,29 @@ const readFeelings = (req, res, { query, isClient }) => __awaiter(void 0, void 0
280
281
  }
281
282
  res.send({ status: 'ok' });
282
283
  });
284
+ const saveResponseTime = ({ query, isClient, idCliente }) => __awaiter(void 0, void 0, void 0, function* () {
285
+ if (isClient)
286
+ return;
287
+ let lastNotReadMessage;
288
+ let firstNotReadMessage;
289
+ // eslint-disable-next-line no-constant-condition
290
+ while (true) {
291
+ const [lastMessage] = yield query(`
292
+ SELECT * FROM [CHAT MESSAGE]
293
+ WHERE [ID CLIENTE] = ? AND [ID] < ?
294
+ ORDER BY [DATE] DESC
295
+ LIMIT 1
296
+ `, [idCliente, (lastNotReadMessage === null || lastNotReadMessage === void 0 ? void 0 : lastNotReadMessage.id) || 2147483646]);
297
+ // Si no hay más mensajes || el mensaje no es del cliente || ya tiene tiempo de respuesta => salimos del bucle
298
+ if (!lastMessage || (lastMessage.idSender && lastMessage.idCliente !== lastMessage.idSender) || lastMessage.tiempoRespuesta)
299
+ break;
300
+ lastNotReadMessage = lastMessage; // Se va actualizando el último mensaje no leído hasta que se encuentra el primero
301
+ if (!firstNotReadMessage)
302
+ firstNotReadMessage = lastMessage; // Se guarda el primer mensaje no leído para añadir en este el tiempo de respuesta
303
+ }
304
+ if (!lastNotReadMessage)
305
+ return;
306
+ // @ts-ignore
307
+ const responseTime = Math.floor((new Date() - new Date(lastNotReadMessage.date)) / 1000);
308
+ yield query('UPDATE [CHAT MESSAGE] SET [TIEMPO RESPUESTA] = ? WHERE [ID] = ?', [responseTime, firstNotReadMessage.id]);
309
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAWA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAmBpD,CAAC;AAmQF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAWA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAmBpD,CAAC;AAkSF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.3.11",
3
+ "version": "1.4.0",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"
@@ -52,15 +52,15 @@
52
52
  "typescript-eslint": "^7.15.0"
53
53
  },
54
54
  "peerDependencies": {
55
+ "@napi-rs/canvas": "^0.1.53",
55
56
  "@parse/node-apn": "6.0.1",
56
- "@runnerpro/common": "^1.4.1",
57
+ "@runnerpro/common": "^1.5.1",
57
58
  "axios": "^1.6.7",
59
+ "image-size": "^1.0.2",
58
60
  "jimp": "^0.22.10",
59
61
  "nodemailer": "6.9.9",
60
62
  "pg": "8.11.3",
61
- "uuidv4": "^6.2.13",
62
- "image-size": "^1.0.2",
63
- "@napi-rs/canvas": "^0.1.53"
63
+ "uuidv4": "^6.2.13"
64
64
  },
65
65
  "dependencies": {
66
66
  "@google-cloud/translate": "^8.3.0",