@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.js CHANGED
@@ -170,6 +170,27 @@ var settings = metaWhatsAppSchema.table("settings", {
170
170
 
171
171
  // src/repositories/SessionRepository.ts
172
172
  var DEFAULT_LIMIT = 20;
173
+ var conversationSummaryProjection = {
174
+ lastContent: sql2`(
175
+ select m.content from ${messages} m
176
+ where m.company_id = ${sessions}.company_id and m.session_id = ${sessions}.id
177
+ order by m.created_at desc limit 1
178
+ )`,
179
+ lastDirection: sql2`(
180
+ select m.direction from ${messages} m
181
+ where m.company_id = ${sessions}.company_id and m.session_id = ${sessions}.id
182
+ order by m.created_at desc limit 1
183
+ )`,
184
+ // Entradas do cliente depois da última leitura do atendente. Sessão nunca lida conta
185
+ // tudo — é o comportamento esperado de uma conversa que ninguém abriu ainda.
186
+ unread: sql2`(
187
+ select count(*)::int from ${messages} m
188
+ where m.company_id = ${sessions}.company_id
189
+ and m.session_id = ${sessions}.id
190
+ and m.direction = 'inbound'
191
+ and (${sessions}.last_agent_read_at is null or m.created_at > ${sessions}.last_agent_read_at)
192
+ )`
193
+ };
173
194
  var SessionRepository = class {
174
195
  static {
175
196
  __name(this, "SessionRepository");
@@ -290,25 +311,7 @@ var SessionRepository = class {
290
311
  // lista dezenas de conversas por página, e uma query por linha é o gargalo clássico
291
312
  // dessa tela. Ambos os campos são dados do próprio módulo — deixá-los para o host
292
313
  // obrigaria todo consumidor a reescrever o mesmo join contra tabelas que não são dele.
293
- lastContent: sql2`(
294
- select m.content from ${messages} m
295
- where m.company_id = ${sessions.companyId} and m.session_id = ${sessions.id}
296
- order by m.created_at desc limit 1
297
- )`,
298
- lastDirection: sql2`(
299
- select m.direction from ${messages} m
300
- where m.company_id = ${sessions.companyId} and m.session_id = ${sessions.id}
301
- order by m.created_at desc limit 1
302
- )`,
303
- // Entradas do cliente depois da última leitura do atendente. Sessão nunca lida conta
304
- // tudo — é o comportamento esperado de uma conversa que ninguém abriu ainda.
305
- unread: sql2`(
306
- select count(*)::int from ${messages} m
307
- where m.company_id = ${sessions.companyId}
308
- and m.session_id = ${sessions.id}
309
- and m.direction = 'inbound'
310
- and (${sessions.lastAgentReadAt} is null or m.created_at > ${sessions.lastAgentReadAt})
311
- )`
314
+ ...conversationSummaryProjection
312
315
  }).from(sessions).where(and(...conditions)).orderBy(desc(sessions.lastActivity)).limit(limit).offset(offset);
313
316
  return rows.map((row) => ({
314
317
  id: row.id,
@@ -1147,6 +1150,8 @@ function toSessionContract(row) {
1147
1150
  companyId: row.companyId,
1148
1151
  whatsappNumber: row.whatsappNumber,
1149
1152
  currentState: row.currentState,
1153
+ flowKey: row.flowKey,
1154
+ currentNodeId: row.currentNodeId,
1150
1155
  context: row.context,
1151
1156
  mode: row.mode,
1152
1157
  assignedUserId: row.assignedUserId,