mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-05-09 11:01:45 +00:00
feat: adiciona ações em lote ao inbox
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use server";
|
||||
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { and, eq, inArray, ne } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
import { inboxItems } from "@/db/schema";
|
||||
import {
|
||||
@@ -35,6 +35,10 @@ const bulkDeleteInboxSchema = z.object({
|
||||
status: z.enum(["processed", "discarded"]),
|
||||
});
|
||||
|
||||
const bulkDeleteSelectedInboxSchema = z.object({
|
||||
inboxItemIds: z.array(z.string().uuid()).min(1, "Selecione ao menos um item"),
|
||||
});
|
||||
|
||||
function revalidateInbox() {
|
||||
revalidateForEntity("inbox");
|
||||
}
|
||||
@@ -264,6 +268,36 @@ export async function deleteInboxItemAction(
|
||||
}
|
||||
}
|
||||
|
||||
export async function bulkDeleteSelectedInboxItemsAction(
|
||||
input: z.infer<typeof bulkDeleteSelectedInboxSchema>,
|
||||
): Promise<ActionResult> {
|
||||
try {
|
||||
const user = await getUser();
|
||||
const data = bulkDeleteSelectedInboxSchema.parse(input);
|
||||
|
||||
const result = await db
|
||||
.delete(inboxItems)
|
||||
.where(
|
||||
and(
|
||||
inArray(inboxItems.id, data.inboxItemIds),
|
||||
eq(inboxItems.userId, user.id),
|
||||
ne(inboxItems.status, "pending"),
|
||||
),
|
||||
)
|
||||
.returning({ id: inboxItems.id });
|
||||
|
||||
revalidateInbox();
|
||||
|
||||
const count = result.length;
|
||||
return {
|
||||
success: true,
|
||||
message: `${count} item(s) excluído(s).`,
|
||||
};
|
||||
} catch (error) {
|
||||
return handleActionError(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function bulkDeleteInboxItemsAction(
|
||||
input: z.infer<typeof bulkDeleteInboxSchema>,
|
||||
): Promise<ActionResult> {
|
||||
|
||||
Reference in New Issue
Block a user