mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-15 10:30:37 +09:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { and, desc, eq } from "drizzle-orm";
|
|
import type { Db } from "@paperclipai/db";
|
|
import { inboxDismissals } from "@paperclipai/db";
|
|
|
|
export function inboxDismissalService(db: Db) {
|
|
return {
|
|
list: async (companyId: string, userId: string) =>
|
|
db
|
|
.select()
|
|
.from(inboxDismissals)
|
|
.where(and(eq(inboxDismissals.companyId, companyId), eq(inboxDismissals.userId, userId)))
|
|
.orderBy(desc(inboxDismissals.updatedAt)),
|
|
|
|
dismiss: async (
|
|
companyId: string,
|
|
userId: string,
|
|
itemKey: string,
|
|
dismissedAt: Date = new Date(),
|
|
) => {
|
|
const now = new Date();
|
|
const [row] = await db
|
|
.insert(inboxDismissals)
|
|
.values({
|
|
companyId,
|
|
userId,
|
|
itemKey,
|
|
dismissedAt,
|
|
updatedAt: now,
|
|
})
|
|
.onConflictDoUpdate({
|
|
target: [inboxDismissals.companyId, inboxDismissals.userId, inboxDismissals.itemKey],
|
|
set: {
|
|
dismissedAt,
|
|
updatedAt: now,
|
|
},
|
|
})
|
|
.returning();
|
|
return row;
|
|
},
|
|
};
|
|
}
|