Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ base url: `http://localhost:3000`
- Update a project: `PUT /api/organization/:organizationId/team/:teamId/project/:projectId`
- Update the project status: `PATCH /api/organization/:organizationId/team/:teamId/project/:projectId/status`
- Update the project priority: `PATCH /api/organization/:organizationId/team/:teamId/project/:projectId/priority`
- Delete a project: `DELETE /api/organization/:organizationId/team/:teamId/project/:projectId`
77 changes: 77 additions & 0 deletions src/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,3 +778,80 @@ export const updateProjectPriority = async (req, res, next) => {
next(error);
}
};

/**
* @desc Delete a project
* @route /api/organization/:organizationId/team/:teamId/project/:projectId
* @method DELETE
* @access private
*/
export const deleteProject = async (req, res, next) => {
try {
const { organizationId, teamId, projectId } = req.params;
const user = req.user;

// Validate required parameters
const validationResult = validateParams(
{ organizationId, teamId, projectId },
['organizationId', 'teamId', 'projectId'],
);

if (!validationResult.success) {
return res.status(400).json({ message: validationResult.message });
}

// Check if organization exists
const orgResult = await checkOrganization(organizationId);
if (!orgResult.success) {
return res.status(404).json({ message: orgResult.message });
}

// Check if team exists
const teamResult = await checkTeam(teamId, organizationId);
if (!teamResult.success) {
return res.status(404).json({ message: teamResult.message });
}

// Check if project exists
const project = await prisma.project.findFirst({
where: {
id: projectId,
teamId,
deletedAt: null,
},
});

if (!project) {
return res.status(404).json({ message: 'Project not found' });
}

// Check user permissions
const permissionResult = checkTeamPermissions(
user,
orgResult.organization,
teamResult.team,
'delete projects from',
);
if (!permissionResult.success) {
return res.status(403).json({ message: permissionResult.message });
}

// Soft delete the project
await prisma.project.update({
where: {
id: projectId,
},
data: {
deletedAt: new Date(),
updatedBy: user.id,
},
});

res.status(200).json({
success: true,
message: 'Project deleted successfully',
});
} catch (error) {
next(error);
}
};
110 changes: 110 additions & 0 deletions src/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3689,6 +3689,116 @@
}
]
}
},
"/api/organization/{organizationId}/team/{teamId}/project/{projectId}/": {
"delete": {
"tags": ["Project"],
"summary": "Delete a project",
"description": "Soft deletes a project. Requires admin, organization owner, or team manager permissions.",
"parameters": [
{
"name": "organizationId",
"in": "path",
"description": "Organization ID",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "teamId",
"in": "path",
"description": "Team ID",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "projectId",
"in": "path",
"description": "Project ID",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "Project deleted successfully",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": true
},
"message": {
"type": "string",
"example": "Project deleted successfully"
}
}
}
}
}
},
"400": {
"description": "Bad request - Missing or invalid parameters",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"message": {
"type": "string",
"example": "Organization ID is required"
}
}
}
}
}
},
"403": {
"description": "Forbidden - Insufficient permissions",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"message": {
"type": "string",
"example": "You don't have permission to delete projects from this team"
}
}
}
}
}
},
"404": {
"description": "Not found - Organization, team or project not found",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
}
}
}
}
},
"security": [
{
"bearerAuth": []
}
]
}
}
},

Expand Down
7 changes: 7 additions & 0 deletions src/routes/project.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Router } from 'express';
import { verifyAccessToken } from '../middlewares/auth.middleware.js';
import {
createProject,
deleteProject,
updateProject,
updateProjectPriority,
updateProjectStatus,
Expand Down Expand Up @@ -33,4 +34,10 @@ router.patch(
updateProjectPriority,
);

router.delete(
'/api/organization/:organizationId/team/:teamId/project/:projectId',
verifyAccessToken,
deleteProject,
);

export default router;