0.4.0 convex及界面修改
This commit is contained in:
@@ -142,6 +142,9 @@ export const listByWorkspaceForSearch = query({
|
||||
document_id: t.document_id,
|
||||
title: t.title,
|
||||
is_archived: t.is_archived,
|
||||
deleted_at: t.deleted_at ?? null,
|
||||
deleted_by: t.deleted_by ?? null,
|
||||
purged_at: t.purged_at ?? null,
|
||||
created_at: t.created_at,
|
||||
updated_at: t.updated_at,
|
||||
}));
|
||||
@@ -173,6 +176,9 @@ export const create = mutation({
|
||||
view_preferences: {},
|
||||
snapshot: args.snapshot ?? null,
|
||||
is_archived: false,
|
||||
deleted_at: null,
|
||||
deleted_by: null,
|
||||
purged_at: null,
|
||||
last_synced_at: now,
|
||||
created_by: args.userId,
|
||||
updated_by: args.userId,
|
||||
@@ -279,9 +285,39 @@ export const remove = mutation({
|
||||
throw new Error("Table not found");
|
||||
}
|
||||
|
||||
const now = nowIso();
|
||||
await ctx.db.patch(table._id, {
|
||||
is_archived: true,
|
||||
updated_at: nowIso(),
|
||||
deleted_at: now,
|
||||
deleted_by: args.userId,
|
||||
purged_at: null,
|
||||
updated_at: now,
|
||||
updated_by: args.userId,
|
||||
});
|
||||
|
||||
return { success: true };
|
||||
},
|
||||
});
|
||||
|
||||
// Mutation: 恢复表格(从垃圾桶恢复)
|
||||
export const restore = mutation({
|
||||
args: { userId: v.string(), tableId: v.string() },
|
||||
handler: async (ctx, args) => {
|
||||
const table = await ctx.db
|
||||
.query("document_tables")
|
||||
.withIndex("by_table_id", (q) => q.eq("id", args.tableId))
|
||||
.first();
|
||||
if (!table) {
|
||||
throw new Error("Table not found");
|
||||
}
|
||||
|
||||
const now = nowIso();
|
||||
await ctx.db.patch(table._id, {
|
||||
is_archived: false,
|
||||
deleted_at: null,
|
||||
deleted_by: null,
|
||||
purged_at: null,
|
||||
updated_at: now,
|
||||
updated_by: args.userId,
|
||||
});
|
||||
|
||||
@@ -318,6 +354,45 @@ export const purge = mutation({
|
||||
},
|
||||
});
|
||||
|
||||
export const emptyTrashByWorkspace = mutation({
|
||||
args: { userId: v.string(), workspaceId: v.string(), expiredDeletedAt: v.string() },
|
||||
handler: async (ctx, args) => {
|
||||
await assertWorkspaceMember(ctx, args.userId, args.workspaceId);
|
||||
|
||||
const rows = await ctx.db
|
||||
.query("document_tables")
|
||||
.withIndex("by_workspace", (q) => q.eq("workspace_id", args.workspaceId))
|
||||
.order("desc")
|
||||
.take(5000);
|
||||
|
||||
// 仅清理“已进入垃圾桶且超出宽限期”的表格
|
||||
const targets = rows.filter((t) => {
|
||||
if (!t.is_archived) return false;
|
||||
const deletedAt = (t as any).deleted_at ?? null;
|
||||
if (!deletedAt || typeof deletedAt !== "string") return false;
|
||||
return deletedAt <= args.expiredDeletedAt;
|
||||
});
|
||||
|
||||
if (targets.length === 0) {
|
||||
return { ok: true, deleted: 0 };
|
||||
}
|
||||
|
||||
for (const table of targets) {
|
||||
const tableId = table.id;
|
||||
const tableRows = await ctx.db
|
||||
.query("document_table_rows")
|
||||
.withIndex("by_table", (q) => q.eq("table_id", tableId))
|
||||
.collect();
|
||||
for (const r of tableRows) {
|
||||
await ctx.db.delete(r._id);
|
||||
}
|
||||
await ctx.db.delete(table._id);
|
||||
}
|
||||
|
||||
return { ok: true, deleted: targets.length };
|
||||
},
|
||||
});
|
||||
|
||||
// Query: 获取表格行数据
|
||||
export const getRows = query({
|
||||
args: { tableId: v.string() },
|
||||
|
||||
Reference in New Issue
Block a user