feat(msg): announcements 公告模块 + sendBatch 批量优化 + 权限扩展 + nextstep 文档
This commit is contained in:
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user