feat(msg): announcements 公告模块 + sendBatch 批量优化 + 权限扩展 + nextstep 文档

This commit is contained in:
SpecialX
2026-07-14 15:57:41 +08:00
parent 7dd5c44406
commit fb23c5234e
28 changed files with 3644 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
import { and, count, desc, eq, inArray, lte } from "drizzle-orm";
import { and, count, desc, eq, inArray, lte, sql } from "drizzle-orm";
import { getDb } from "../config/database.js";
import {
notifications,
@@ -51,6 +51,31 @@ export async function findByEventId(
return row;
}
/**
* 批量查询已存在的 eventId用于 sendBatch 幂等过滤)。
* 返回已存在的 eventId 集合。
*/
export async function findExistingEventIds(
eventIds: string[],
): Promise<Set<string>> {
if (eventIds.length === 0) return new Set();
const db = getDb();
const rows = await db
.select({ eventId: notifications.eventId })
.from(notifications)
.where(
and(
inArray(notifications.eventId, eventIds),
sql`${notifications.eventId} IS NOT NULL`,
),
);
return new Set(
rows
.map((r) => r.eventId)
.filter((id): id is string => id !== null && id !== undefined),
);
}
export async function listByUser(
userId: string,
options: {