@adatechnology/meta-whatsapp-module 0.2.0-rc.6 → 0.2.0-rc.8

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.
package/dist/index.cjs CHANGED
@@ -226,6 +226,27 @@ var settings = metaWhatsAppSchema.table("settings", {
226
226
 
227
227
  // src/repositories/SessionRepository.ts
228
228
  var DEFAULT_LIMIT = 20;
229
+ var conversationSummaryProjection = {
230
+ lastContent: import_drizzle_orm2.sql`(
231
+ select m.content from ${messages} m
232
+ where m.company_id = ${sessions}.company_id and m.session_id = ${sessions}.id
233
+ order by m.created_at desc limit 1
234
+ )`,
235
+ lastDirection: import_drizzle_orm2.sql`(
236
+ select m.direction from ${messages} m
237
+ where m.company_id = ${sessions}.company_id and m.session_id = ${sessions}.id
238
+ order by m.created_at desc limit 1
239
+ )`,
240
+ // Entradas do cliente depois da última leitura do atendente. Sessão nunca lida conta
241
+ // tudo — é o comportamento esperado de uma conversa que ninguém abriu ainda.
242
+ unread: import_drizzle_orm2.sql`(
243
+ select count(*)::int from ${messages} m
244
+ where m.company_id = ${sessions}.company_id
245
+ and m.session_id = ${sessions}.id
246
+ and m.direction = 'inbound'
247
+ and (${sessions}.last_agent_read_at is null or m.created_at > ${sessions}.last_agent_read_at)
248
+ )`
249
+ };
229
250
  var SessionRepository = class {
230
251
  static {
231
252
  __name(this, "SessionRepository");
@@ -346,25 +367,7 @@ var SessionRepository = class {
346
367
  // lista dezenas de conversas por página, e uma query por linha é o gargalo clássico
347
368
  // dessa tela. Ambos os campos são dados do próprio módulo — deixá-los para o host
348
369
  // obrigaria todo consumidor a reescrever o mesmo join contra tabelas que não são dele.
349
- lastContent: import_drizzle_orm2.sql`(
350
- select m.content from ${messages} m
351
- where m.company_id = ${sessions.companyId} and m.session_id = ${sessions.id}
352
- order by m.created_at desc limit 1
353
- )`,
354
- lastDirection: import_drizzle_orm2.sql`(
355
- select m.direction from ${messages} m
356
- where m.company_id = ${sessions.companyId} and m.session_id = ${sessions.id}
357
- order by m.created_at desc limit 1
358
- )`,
359
- // Entradas do cliente depois da última leitura do atendente. Sessão nunca lida conta
360
- // tudo — é o comportamento esperado de uma conversa que ninguém abriu ainda.
361
- unread: import_drizzle_orm2.sql`(
362
- select count(*)::int from ${messages} m
363
- where m.company_id = ${sessions.companyId}
364
- and m.session_id = ${sessions.id}
365
- and m.direction = 'inbound'
366
- and (${sessions.lastAgentReadAt} is null or m.created_at > ${sessions.lastAgentReadAt})
367
- )`
370
+ ...conversationSummaryProjection
368
371
  }).from(sessions).where((0, import_drizzle_orm2.and)(...conditions)).orderBy((0, import_drizzle_orm2.desc)(sessions.lastActivity)).limit(limit).offset(offset);
369
372
  return rows.map((row) => ({
370
373
  id: row.id,
@@ -1203,6 +1206,8 @@ function toSessionContract(row) {
1203
1206
  companyId: row.companyId,
1204
1207
  whatsappNumber: row.whatsappNumber,
1205
1208
  currentState: row.currentState,
1209
+ flowKey: row.flowKey,
1210
+ currentNodeId: row.currentNodeId,
1206
1211
  context: row.context,
1207
1212
  mode: row.mode,
1208
1213
  assignedUserId: row.assignedUserId,