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 @@ -87,3 +87,4 @@ base url: `http://localhost:3000`
- Create a new project: `POST /api/organization/:organizationId/team/:teamId/project`
- 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`
135 changes: 135 additions & 0 deletions src/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,138 @@ export const updateProjectStatus = async (req, res, next) => {
next(error);
}
};

/**
* @desc Update project priority
* @route /api/organization/:organizationId/team/:teamId/project/:projectId/priority
* @method PATCH
* @access private
*/
export const updateProjectPriority = async (req, res, next) => {
try {
const { organizationId, teamId, projectId } = req.params;
const { priority } = req.body;

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

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

// Validate priority
if (!priority) {
return res.status(400).json({
success: false,
message: 'Priority is required',
});
}

// Validate priority value
const validPriorities = ['LOW', 'MEDIUM', 'HIGH', 'URGENT'];
if (!validPriorities.includes(priority)) {
return res.status(400).json({
success: false,
message: `Priority must be one of: ${validPriorities.join(', ')}`,
});
}

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

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

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

if (!existingProject) {
return res.status(404).json({
success: false,
message: 'Project not found',
});
}

// Check permissions
const permissionCheck = checkTeamPermissions(
req.user,
existingOrg,
team,
'update priority of',
);

// Check if user is a project member with appropriate rights
const projectMembership = await prisma.projectMember.findFirst({
where: {
projectId: projectId,
userId: req.user.id,
isActive: true,
role: {
in: ['PROJECT_OWNER', 'PROJECT_MANAGER'],
},
},
});

const hasPermission = permissionCheck.success || projectMembership !== null;

if (!hasPermission) {
return res.status(403).json({
success: false,
message: "You do not have permission to update this project's priority",
});
}

// If priority is the same, no need to update
if (existingProject.priority === priority) {
return res.status(200).json({
success: true,
message: 'Project priority remains unchanged',
data: existingProject,
});
}

// Update the project priority
const updatedProject = await prisma.project.update({
where: { id: projectId },
data: {
priority,
lastModifiedBy: req.user.id,
},
});

res.status(200).json({
success: true,
message: 'Project priority updated successfully',
data: updatedProject,
});
} catch (error) {
next(error);
}
};
146 changes: 145 additions & 1 deletion src/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3397,7 +3397,7 @@
},
"/api/organization/{organizationId}/team/{teamId}/project/{projectId}/status": {
"patch": {
"tags": ["project"],
"tags": ["Project"],
"summary": "Update project status",
"description": "Updates the status of an existing project. Requires appropriate permissions (admin, organization owner, team manager, or project owner/manager).",
"parameters": [
Expand Down Expand Up @@ -3545,6 +3545,150 @@
}
]
}
},
"/api/organization/{organizationId}/team/{teamId}/project/{projectId}/priority": {
"patch": {
"tags": ["Project"],
"summary": "Update project priority",
"description": "Updates the priority of an existing project. Requires appropriate permissions (admin, organization owner, team manager, or project owner/manager).",
"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"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": ["priority"],
"properties": {
"priority": {
"type": "string",
"description": "New project priority",
"enum": ["LOW", "MEDIUM", "HIGH", "URGENT"],
"example": "HIGH"
}
}
}
}
}
},
"responses": {
"200": {
"description": "Project priority updated successfully",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": true
},
"message": {
"type": "string",
"example": "Project priority updated successfully"
},
"data": {
"$ref": "#/components/schemas/ProjectBasic"
}
}
}
}
}
},
"400": {
"description": "Bad request - Invalid priority or missing priority field",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": false
},
"message": {
"type": "string"
}
}
}
}
}
},
"403": {
"description": "Forbidden - Insufficient permissions",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": false
},
"message": {
"type": "string",
"example": "You do not have permission to update this project's priority"
}
}
}
}
}
},
"404": {
"description": "Not found - Organization, team or project not found",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"success": {
"type": "boolean",
"example": false
},
"message": {
"type": "string",
"example": "Project not found"
}
}
}
}
}
}
},
"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 @@ -3,6 +3,7 @@ import { verifyAccessToken } from '../middlewares/auth.middleware.js';
import {
createProject,
updateProject,
updateProjectPriority,
updateProjectStatus,
} from '../controllers/project.controller.js';

Expand All @@ -26,4 +27,10 @@ router.patch(
updateProjectStatus,
);

router.patch(
'/api/organization/:organizationId/team/:teamId/project/:projectId/priority',
verifyAccessToken,
updateProjectPriority,
);

export default router;