forked from bai/curriculum-project-hub
fix: move folder creation into project move flow
This commit is contained in:
@@ -52,6 +52,65 @@ export async function browseFolderDestinations(
|
||||
};
|
||||
}
|
||||
|
||||
export async function createFolderAndMoveProject(
|
||||
prisma: PrismaClient,
|
||||
input: {
|
||||
readonly organizationId: string;
|
||||
readonly projectId: string;
|
||||
readonly parentFolderId: string | null;
|
||||
readonly name: string;
|
||||
readonly actorUserId?: string | undefined;
|
||||
},
|
||||
): Promise<{ readonly folderId: string; readonly folderName: string }> {
|
||||
const name = input.name.trim();
|
||||
if (name === "") throw new Error("folder name is required");
|
||||
if (name.length > 100) throw new Error("folder name must not exceed 100 characters");
|
||||
return prisma.$transaction(async (tx) => {
|
||||
await lockActiveProjectOrganization(tx, input.projectId);
|
||||
const project = await tx.project.findFirst({
|
||||
where: { id: input.projectId, organizationId: input.organizationId, archivedAt: null },
|
||||
select: { id: true, folderId: true },
|
||||
});
|
||||
if (project === null) throw new Error("active project not found in Organization");
|
||||
if (input.parentFolderId !== null) {
|
||||
const parent = await tx.folder.findFirst({
|
||||
where: {
|
||||
id: input.parentFolderId,
|
||||
organizationId: input.organizationId,
|
||||
archivedAt: null,
|
||||
kind: { not: "SYSTEM_INBOX" },
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
if (parent === null) throw new Error("active destination folder not found in Organization");
|
||||
}
|
||||
const folder = await tx.folder.create({
|
||||
data: {
|
||||
organizationId: input.organizationId,
|
||||
parentId: input.parentFolderId,
|
||||
name,
|
||||
},
|
||||
select: { id: true, name: true },
|
||||
});
|
||||
await tx.project.update({ where: { id: project.id }, data: { folderId: folder.id } });
|
||||
await tx.auditEntry.create({
|
||||
data: {
|
||||
organizationId: input.organizationId,
|
||||
projectId: project.id,
|
||||
...(input.actorUserId !== undefined ? { actorUserId: input.actorUserId } : {}),
|
||||
action: "folder.created_and_project_moved_from_feishu",
|
||||
metadata: {
|
||||
folderId: folder.id,
|
||||
parentFolderId: input.parentFolderId,
|
||||
previousFolderId: project.folderId,
|
||||
name: folder.name,
|
||||
},
|
||||
},
|
||||
});
|
||||
return { folderId: folder.id, folderName: folder.name };
|
||||
});
|
||||
}
|
||||
|
||||
export async function loadProjectConsole(
|
||||
prisma: PrismaClient,
|
||||
input: { readonly projectId: string; readonly chatId: string },
|
||||
|
||||
Reference in New Issue
Block a user