@runnerpro/backend 1.8.15 → 1.8.17

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.
@@ -34,6 +34,7 @@ const common_1 = require("@runnerpro/common");
34
34
  const index_2 = require("../../locale/index");
35
35
  const multer_1 = __importDefault(require("multer"));
36
36
  const axios_1 = __importDefault(require("axios"));
37
+ const saveResponseTime_1 = require("../saveResponseTime");
37
38
  const conversationRoute = (_a) => {
38
39
  var { router } = _a, params = __rest(_a, ["router"]);
39
40
  const uploadFile = (0, multer_1.default)({
@@ -233,7 +234,7 @@ const readMessage = (req, res, { query, isClient }) => __awaiter(void 0, void 0,
233
234
  const markReadMessage = ({ isClient, query, idCliente }) => __awaiter(void 0, void 0, void 0, function* () {
234
235
  const conditionSender = isClient ? ' AND [ID SENDER] != ?' : ' AND ([ID SENDER] = ? OR [ID SENDER] IS NULL)';
235
236
  yield query('UPDATE [CHAT MESSAGE] SET [READ] = TRUE WHERE [ID CLIENTE] = ? AND [READ] = FALSE ' + conditionSender, [idCliente, idCliente]);
236
- yield saveResponseTime({ query, isClient, idCliente });
237
+ yield (0, saveResponseTime_1.saveResponseTime)({ isClient, idCliente });
237
238
  });
238
239
  const resizeImage = (data, filePath, mimetype) => __awaiter(void 0, void 0, void 0, function* () {
239
240
  if (mimetype.includes('webp'))
@@ -266,29 +267,3 @@ const rotateOrientationImage = (data, filePath, image = null, mimetype) => __awa
266
267
  image = yield image.rotate(rotate);
267
268
  return image.getBufferAsync(jimp_1.default.MIME_JPEG);
268
269
  });
269
- const saveResponseTime = ({ query, isClient, idCliente }) => __awaiter(void 0, void 0, void 0, function* () {
270
- if (isClient)
271
- return;
272
- let lastNotReadMessage;
273
- let firstNotReadMessage;
274
- // eslint-disable-next-line no-constant-condition
275
- while (true) {
276
- const [lastMessage] = yield query(`
277
- SELECT * FROM [CHAT MESSAGE]
278
- WHERE [ID CLIENTE] = ? AND [ID] < ?
279
- ORDER BY [DATE] DESC
280
- LIMIT 1
281
- `, [idCliente, (lastNotReadMessage === null || lastNotReadMessage === void 0 ? void 0 : lastNotReadMessage.id) || 2147483646]);
282
- // Si no hay más mensajes || el mensaje no es del cliente || ya tiene tiempo de respuesta => salimos del bucle
283
- if (!lastMessage || (lastMessage.idSender && lastMessage.idCliente !== lastMessage.idSender) || lastMessage.tiempoRespuesta)
284
- break;
285
- lastNotReadMessage = lastMessage; // Se va actualizando el último mensaje no leído hasta que se encuentra el primero
286
- if (!firstNotReadMessage)
287
- firstNotReadMessage = lastMessage; // Se guarda el primer mensaje no leído para añadir en este el tiempo de respuesta
288
- }
289
- if (!lastNotReadMessage)
290
- return;
291
- // @ts-ignore
292
- const responseTime = Math.floor((new Date() - new Date(lastNotReadMessage.date)) / 1000);
293
- yield query('UPDATE [CHAT MESSAGE] SET [TIEMPO RESPUESTA] = ? WHERE [ID] = ?', [responseTime, firstNotReadMessage.id]);
294
- });
@@ -0,0 +1,40 @@
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.saveResponseTime = void 0;
13
+ const index_1 = require("../db/index");
14
+ const saveResponseTime = ({ isClient, idCliente }) => __awaiter(void 0, void 0, void 0, function* () {
15
+ if (isClient)
16
+ return;
17
+ let lastNotReadMessage;
18
+ let firstNotReadMessage;
19
+ // eslint-disable-next-line no-constant-condition
20
+ while (true) {
21
+ const [lastMessage] = yield (0, index_1.query)(`
22
+ SELECT * FROM [CHAT MESSAGE]
23
+ WHERE [ID CLIENTE] = ? AND [ID] < ?
24
+ ORDER BY [DATE] DESC
25
+ LIMIT 1
26
+ `, [idCliente, lastNotReadMessage === null || lastNotReadMessage === void 0 ? void 0 : lastNotReadMessage.id]);
27
+ // Si no hay más mensajes || el mensaje no es del cliente || ya tiene tiempo de respuesta => salimos del bucle
28
+ if (!lastMessage || (lastMessage.idSender && lastMessage.idCliente !== lastMessage.idSender) || lastMessage.tiempoRespuesta)
29
+ break;
30
+ lastNotReadMessage = lastMessage; // Se va actualizando el último mensaje no leído hasta que se encuentra el primero
31
+ if (!firstNotReadMessage)
32
+ firstNotReadMessage = lastMessage; // Se guarda el primer mensaje no leído para añadir en este el tiempo de respuesta
33
+ }
34
+ if (!lastNotReadMessage)
35
+ return;
36
+ // @ts-ignore
37
+ const responseTime = Math.floor((new Date() - new Date(lastNotReadMessage.date)) / 1000);
38
+ yield (0, index_1.query)('UPDATE [CHAT MESSAGE] SET [TIEMPO RESPUESTA] = ? WHERE [ID] = ?', [responseTime, firstNotReadMessage.id]);
39
+ });
40
+ exports.saveResponseTime = saveResponseTime;
@@ -26,10 +26,9 @@ const sendMessageChatToClient = (idCliente, text, textPreferredLanguage, preferr
26
26
  return;
27
27
  idEntrenador = entrenadorBBDD.idEntrenador;
28
28
  }
29
- let result;
30
29
  if (notification) {
31
30
  try {
32
- result = yield (0, index_2.sendNotification)({
31
+ yield (0, index_2.sendNotification)({
33
32
  firebaseMessaging: (0, messaging_1.getMessaging)(),
34
33
  idCliente,
35
34
  body: (0, common_1.removeAccent)((textPreferredLanguage || text).substring(0, 50)) + ((textPreferredLanguage || text).length > 50 ? '...' : ''),
@@ -37,20 +36,9 @@ const sendMessageChatToClient = (idCliente, text, textPreferredLanguage, preferr
37
36
  });
38
37
  }
39
38
  catch (e) {
40
- console.log('Error al enviar notificación', e);
41
39
  (0, index_1.err)(null, null, e, null);
42
- return e;
43
40
  }
44
41
  }
45
42
  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]);
46
- return {
47
- // status: 'success',
48
- // notification,
49
- // options,
50
- // firebaseMessaging: getMessaging(),
51
- // body: removeAccent((textPreferredLanguage || text).substring(0, 50)) + ((textPreferredLanguage || text).length > 50 ? '...' : ''),
52
- // screen: NOTIFICATION_SCREEN_TYPES.CHAT,
53
- result,
54
- };
55
43
  });
56
44
  exports.sendMessageChatToClient = sendMessageChatToClient;
@@ -24,19 +24,15 @@ const sendNotification = ({ firebaseMessaging, idCliente, title, body, screen =
24
24
  }),
25
25
  ]);
26
26
  const screenParamsString = JSON.stringify(screenParams);
27
- const resultsDevices = [];
28
27
  for (const device of devices) {
29
- const resultDevice = yield notificationWEB(firebaseMessaging, {
28
+ yield notificationWEB(firebaseMessaging, {
30
29
  title,
31
30
  body,
32
31
  idNotification: (idNotification || '0').toString(),
33
32
  screen,
34
33
  screenParams: screenParamsString,
35
34
  }, device.subscription);
36
- // @ts-ignore
37
- resultsDevices.push(resultDevice);
38
35
  }
39
- return { status: 'success', idNotification, devices, resultsDevices };
40
36
  });
41
37
  exports.sendNotification = sendNotification;
42
38
  function notificationWEB(firebaseMessaging, msg, token) {
@@ -44,7 +40,7 @@ function notificationWEB(firebaseMessaging, msg, token) {
44
40
  if (!msg.title)
45
41
  msg.title = '';
46
42
  try {
47
- const result = yield firebaseMessaging.send({
43
+ yield firebaseMessaging.send({
48
44
  token,
49
45
  notification: {
50
46
  title: msg.title,
@@ -52,11 +48,9 @@ function notificationWEB(firebaseMessaging, msg, token) {
52
48
  },
53
49
  data: msg,
54
50
  });
55
- return result;
56
51
  }
57
52
  catch (error) {
58
53
  console.log('Error al enviar notificación', error);
59
- return error;
60
54
  }
61
55
  });
62
56
  }
@@ -1 +1 @@
1
- {"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../../../../src/chat/api/conversation.ts"],"names":[],"mappings":"AAUA,QAAA,MAAM,iBAAiB,0BAA2B,GAAG,SAiBpD,CAAC;AA4QF,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,SAiBpD,CAAC;AA6OF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ declare const saveResponseTime: ({ isClient, idCliente }: {
2
+ isClient: any;
3
+ idCliente: any;
4
+ }) => Promise<void>;
5
+ export { saveResponseTime };
6
+ //# sourceMappingURL=saveResponseTime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saveResponseTime.d.ts","sourceRoot":"","sources":["../../../../src/chat/saveResponseTime.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,gBAAgB;;;mBA6BrB,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -1,3 +1,3 @@
1
- declare const sendMessageChatToClient: (idCliente: any, text: any, textPreferredLanguage: any, preferredLanguage: any, options: any) => Promise<any>;
1
+ declare const sendMessageChatToClient: (idCliente: any, text: any, textPreferredLanguage: any, preferredLanguage: any, options: any) => Promise<void>;
2
2
  export { sendMessageChatToClient };
3
3
  //# sourceMappingURL=sendMessageChatToClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sendMessageChatToClient.d.ts","sourceRoot":"","sources":["../../../../src/chat/sendMessageChatToClient.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,uBAAuB,+GAuC5B,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
1
+ {"version":3,"file":"sendMessageChatToClient.d.ts","sourceRoot":"","sources":["../../../../src/chat/sendMessageChatToClient.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,uBAAuB,gHA2B5B,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
@@ -7,11 +7,6 @@ interface Notification {
7
7
  screen?: string;
8
8
  screenParams?: any;
9
9
  }
10
- declare const sendNotification: ({ firebaseMessaging, idCliente, title, body, screen, screenParams, }: Notification) => Promise<{
11
- status: string;
12
- idNotification: any;
13
- devices: any;
14
- resultsDevices: any[];
15
- }>;
10
+ declare const sendNotification: ({ firebaseMessaging, idCliente, title, body, screen, screenParams, }: Notification) => Promise<void>;
16
11
  export { sendNotification };
17
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/sendNotification/index.ts"],"names":[],"mappings":"AAEA,UAAU,YAAY;IACpB,iBAAiB,EAAE,GAAG,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,GAAG,CAAC;CACpB;AAED,QAAA,MAAM,gBAAgB,yEAOnB,YAAY;;;;;EAmCd,CAAC;AAyBF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/sendNotification/index.ts"],"names":[],"mappings":"AAEA,UAAU,YAAY;IACpB,iBAAiB,EAAE,GAAG,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,GAAG,CAAC;CACpB;AAED,QAAA,MAAM,gBAAgB,yEAOnB,YAAY,kBA8Bd,CAAC;AAuBF,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runnerpro/backend",
3
- "version": "1.8.15",
3
+ "version": "1.8.17",
4
4
  "description": "A collection of common backend functions",
5
5
  "exports": {
6
6
  ".": "./lib/cjs/index.js"