@adatechnology/meta-whatsapp-module 0.2.0-rc.6 → 0.2.0-rc.7
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 +22 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +22 -19
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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
|
-
|
|
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,
|