This commit is contained in:
Daniel Hougaard
2024-02-23 01:34:15 +01:00
parent aaca3ac229
commit a9bba02f44
2 changed files with 39 additions and 0 deletions

View File

@ -33,7 +33,9 @@ import { assignWorkspaceKeysToMembers, createProjectKey } from "./project-fns";
import { TProjectQueueFactory } from "./project-queue";
import {
TCreateProjectDTO,
TDeleteProjectBySlugDTO,
TDeleteProjectDTO,
TGetProjectBySlugDTO,
TGetProjectDTO,
TToggleProjectAutoCapitalizationDTO,
TUpdateProjectDTO,
@ -358,6 +360,27 @@ export const projectServiceFactory = ({
return deletedProject;
};
const deleteProjectBySlug = async ({ actor, actorId, actorOrgId, slug }: TDeleteProjectBySlugDTO) => {
const project = await projectDAL.findOne({ slug });
const { permission } = await permissionService.getProjectPermission(actor, actorId, project.id, actorOrgId);
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Delete, ProjectPermissionSub.Project);
const deletedProject = await projectDAL.transaction(async (tx) => {
const delProject = await projectDAL.deleteById(project.id, tx);
const projectGhostUser = await projectMembershipDAL.findProjectGhostUser(project.id).catch(() => null);
// Delete the org membership for the ghost user if it's found.
if (projectGhostUser) {
await userDAL.deleteById(projectGhostUser.id, tx);
}
return delProject;
});
return deletedProject;
};
const getProjects = async (actorId: string) => {
const workspaces = await projectDAL.findAllProjects(actorId);
return workspaces;
@ -450,8 +473,10 @@ export const projectServiceFactory = ({
deleteProject,
getProjects,
updateProject,
deleteProjectBySlug,
getProjectUpgradeStatus,
getAProject,
getProjectBySlug,
toggleAutoCapitalization,
updateName,
upgradeProject

View File

@ -36,6 +36,13 @@ export type TDeleteProjectBySlugDTO = {
actorOrgId?: string;
};
export type TDeleteProjectBySlugDTO = {
slug: string;
actor: ActorType;
actorId: string;
actorOrgId?: string;
};
export type TGetProjectDTO = {
filter: Filter;
} & Omit<TProjectPermission, "projectId">;
@ -47,6 +54,13 @@ export type TUpdateProjectNameDTO = {
name: string;
} & TProjectPermission;
export type TGetProjectBySlugDTO = {
slug: string;
actor: ActorType;
actorId: string;
actorOrgId?: string;
};
export type TUpdateProjectDTO = {
filter: Filter;
update: {