Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+43
-18
@@ -20,7 +20,9 @@
|
||||
// global User lookup (resolveUserLabels): User is not tenant-scoped (a user can
|
||||
// belong to several tenants), so it stays on the db singleton.
|
||||
|
||||
import { CatalogError, foundationErrors } from "@toolctrl/foundation";
|
||||
import { CatalogError, foundationErrors } from "@hivegrid/foundation";
|
||||
import { tasksIndex } from "@hivegrid/search";
|
||||
import { publishSearchProjectionDelete, publishTaskSearchUpsert } from "~/services/search/searchIndexProjection.server";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { withTenantRLS, type TenantRlsClient } from "~/utils/db/.server/tenantRls.server";
|
||||
|
||||
@@ -146,8 +148,8 @@ export async function createTask(input: CreateTaskInput): Promise<TaskRow> {
|
||||
if ((linkedEntityType && !linkedEntityId) || (!linkedEntityType && linkedEntityId)) {
|
||||
throw new TaskServiceError("tasks.error.invalidEntityLink");
|
||||
}
|
||||
const task = await withTenantRLS(input.tenantId, (tx) =>
|
||||
tx.task.create({
|
||||
const task = await withTenantRLS(input.tenantId, async (tx) => {
|
||||
const created = await tx.task.create({
|
||||
data: {
|
||||
tenantId: input.tenantId,
|
||||
createdByUserId: input.userId,
|
||||
@@ -163,8 +165,10 @@ export async function createTask(input: CreateTaskInput): Promise<TaskRow> {
|
||||
sourceRef: input.sourceRef ?? null,
|
||||
isDemoData: input.isDemoData ?? false,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
await publishTaskSearchUpsert(tx, created);
|
||||
return created;
|
||||
});
|
||||
return task as TaskRow;
|
||||
}
|
||||
|
||||
@@ -197,8 +201,8 @@ export async function updateTask(input: UpdateTaskInput): Promise<void> {
|
||||
if (!existing) {
|
||||
throw new CatalogError(foundationErrors.notFound, { taskId: input.taskId });
|
||||
}
|
||||
await tx.task.updateMany({
|
||||
where: { id: input.taskId, tenantId: input.tenantId },
|
||||
const updated = await tx.task.update({
|
||||
where: { id: existing.id },
|
||||
data: {
|
||||
...(input.title !== undefined ? { title: input.title.trim().slice(0, MAX_TITLE_LENGTH) } : {}),
|
||||
...(input.description !== undefined ? { description: input.description } : {}),
|
||||
@@ -210,6 +214,7 @@ export async function updateTask(input: UpdateTaskInput): Promise<void> {
|
||||
...(completedAt !== undefined ? { completedAt } : {}),
|
||||
},
|
||||
});
|
||||
await publishTaskSearchUpsert(tx, updated);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -223,7 +228,7 @@ export async function reassignTask(input: {
|
||||
await withTenantRLS(input.tenantId, async (tx) => {
|
||||
const existing = await tx.task.findFirst({
|
||||
where: { id: input.taskId, tenantId: input.tenantId },
|
||||
select: { createdByUserId: true },
|
||||
select: { id: true, createdByUserId: true },
|
||||
});
|
||||
if (!existing) {
|
||||
throw new CatalogError(foundationErrors.notFound, { taskId: input.taskId });
|
||||
@@ -233,28 +238,45 @@ export async function reassignTask(input: {
|
||||
assignedToUserId: input.assignedToUserId,
|
||||
assignedToGroupId: input.assignedToGroupId,
|
||||
});
|
||||
await tx.task.updateMany({
|
||||
where: { id: input.taskId, tenantId: input.tenantId },
|
||||
const updated = await tx.task.update({
|
||||
where: { id: existing.id },
|
||||
data: { assignedToUserId: assignment.assignedToUserId, assignedToGroupId: assignment.assignedToGroupId },
|
||||
});
|
||||
await publishTaskSearchUpsert(tx, updated);
|
||||
});
|
||||
}
|
||||
|
||||
export async function completeTask(input: { tenantId: string; taskId: string }): Promise<void> {
|
||||
await withTenantRLS(input.tenantId, (tx) =>
|
||||
tx.task.updateMany({
|
||||
where: { id: input.taskId, tenantId: input.tenantId },
|
||||
data: { status: "done", completedAt: new Date() },
|
||||
}),
|
||||
);
|
||||
await withTenantRLS(input.tenantId, async (tx) => {
|
||||
const existing = await tx.task.findFirst({ where: { id: input.taskId, tenantId: input.tenantId }, select: { id: true } });
|
||||
if (!existing) {
|
||||
throw new CatalogError(foundationErrors.notFound, { taskId: input.taskId });
|
||||
}
|
||||
const updated = await tx.task.update({ where: { id: existing.id }, data: { status: "done", completedAt: new Date() } });
|
||||
await publishTaskSearchUpsert(tx, updated);
|
||||
});
|
||||
}
|
||||
|
||||
export async function archiveTask(input: { tenantId: string; taskId: string }): Promise<void> {
|
||||
await withTenantRLS(input.tenantId, (tx) => tx.task.updateMany({ where: { id: input.taskId, tenantId: input.tenantId }, data: { archivedAt: new Date() } }));
|
||||
await withTenantRLS(input.tenantId, async (tx) => {
|
||||
const existing = await tx.task.findFirst({ where: { id: input.taskId, tenantId: input.tenantId }, select: { id: true } });
|
||||
if (!existing) {
|
||||
throw new CatalogError(foundationErrors.notFound, { taskId: input.taskId });
|
||||
}
|
||||
await tx.task.update({ where: { id: existing.id }, data: { archivedAt: new Date() } });
|
||||
await publishSearchProjectionDelete(tx, { schema: tasksIndex, tenantId: input.tenantId, entityType: "task", entityId: existing.id });
|
||||
});
|
||||
}
|
||||
|
||||
export async function reactivateTask(input: { tenantId: string; taskId: string }): Promise<void> {
|
||||
await withTenantRLS(input.tenantId, (tx) => tx.task.updateMany({ where: { id: input.taskId, tenantId: input.tenantId }, data: { archivedAt: null } }));
|
||||
await withTenantRLS(input.tenantId, async (tx) => {
|
||||
const existing = await tx.task.findFirst({ where: { id: input.taskId, tenantId: input.tenantId }, select: { id: true } });
|
||||
if (!existing) {
|
||||
throw new CatalogError(foundationErrors.notFound, { taskId: input.taskId });
|
||||
}
|
||||
const updated = await tx.task.update({ where: { id: existing.id }, data: { archivedAt: null } });
|
||||
await publishTaskSearchUpsert(tx, updated);
|
||||
});
|
||||
}
|
||||
|
||||
export async function hardDeleteTask(input: { tenantId: string; taskId: string }): Promise<void> {
|
||||
@@ -265,6 +287,7 @@ export async function hardDeleteTask(input: { tenantId: string; taskId: string }
|
||||
}
|
||||
// TaskWatcher rows cascade on Task delete (schema onDelete: Cascade).
|
||||
await tx.task.delete({ where: { id: task.id } });
|
||||
await publishSearchProjectionDelete(tx, { schema: tasksIndex, tenantId: input.tenantId, entityType: "task", entityId: task.id });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -386,6 +409,7 @@ export type ListTasksFilter = {
|
||||
linkedEntityId?: string | null;
|
||||
source?: TaskSource | null;
|
||||
includeArchived?: boolean;
|
||||
includeDemoData?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -431,6 +455,7 @@ export async function listTasksForBrowser(input: {
|
||||
const where = {
|
||||
tenantId: input.tenantId,
|
||||
...(filter.includeArchived ? {} : { archivedAt: null }),
|
||||
...(filter.includeDemoData ? {} : { isDemoData: false }),
|
||||
...(filter.status ? { status: filter.status } : {}),
|
||||
...(filter.priority ? { priority: filter.priority } : {}),
|
||||
...(filter.assignedToUserId ? { assignedToUserId: filter.assignedToUserId } : {}),
|
||||
|
||||
Reference in new issue
Block a user