Skip to content

Commit df43cee

Browse files
committed
All router Are functional and tested
1 parent f962bf2 commit df43cee

3 files changed

Lines changed: 238 additions & 180 deletions

File tree

src/controllers/project.controller.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,48 @@ export const createProject = async ( req : Request , res : Response ) => {
3636
const file = req.file;
3737
if(!file) throw new ApiError('Image file is not find' , 400);
3838

39-
const imageUrl = await uploadImage( supabase , file , 'projects');
39+
const imageUrl = await uploadImage(supabase, file, 'projects');
4040

4141
if(!imageUrl) throw new ApiError("Image url is missing" , 400);
4242

43+
if(!req.body.projectData.name || !req.body.projectData.githubUrl) throw new ApiError(" fiels is missing " , 400);
44+
4345
const projectContent = {
44-
name: req.body.projectData.project,
46+
name: req.body.projectData.name,
4547
imageUrl: imageUrl,
4648
githubUrl: req.body.projectData.githubUrl,
47-
deployUrl: req.body.projectData.deployUrl,
48-
AdminId: req.body.projectData.AdminId,
49+
deployUrl: req.body.deployUrl,
50+
AdminId: req.body.projectData.adminId,
4951
};
5052

5153
const project = await projectService.createProject( projectContent );
5254
res.status(200).json(project);
5355

5456
} catch (error) {
55-
console.log(error);
5657
throw new ApiError( error as string , 404);
5758
}
5859
};
5960

6061
export const updateProjects = async ( req : Request , res : Response ) => {
6162

6263
try {
63-
const projectInfo = req.body;
64+
const projectInfo = req.body.projectData;
6465
const projectId = parseInt(req.params.projectId);
65-
const updatedById = req.body.updatedById;
66+
const updatedById = projectInfo.updatedById;
67+
68+
let imageUrl = null;
69+
const file = req.file;
70+
71+
if(file){
72+
imageUrl = await uploadImage(supabase , file , 'projects');
73+
}
74+
75+
if( imageUrl ) {
76+
projectInfo.imageUrl = imageUrl;
77+
}
78+
6679

67-
if( !projectId || projectInfo.length === 0 || !updatedById) throw new ApiError( " Send The project id " , 400);
80+
if( !projectId || projectInfo.length === 0 || !updatedById) throw new ApiError( " Something is Mising " , 400);
6881

6982
const project = await projectService.updateProjects( projectInfo , projectId );
7083
res.status(200).json(project)
@@ -133,7 +146,7 @@ export const removeMembers = async ( req : Request , res : Response ) => {
133146
try {
134147
const data = {
135148
projectId : parseInt ( req.params.projectId ),
136-
memberId : req.body.memberId
149+
memberId : req.params.memberId
137150
}
138151

139152
if( !data.projectId || !data.memberId) throw new ApiError(' Field is missing !!!' , 400);

src/routes/projects.ts

Lines changed: 137 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import {
1414

1515

1616
function parseCreateProjectData(req : Request, res : Response , next : NextFunction) {
17-
17+
1818
if(req.body.projectData){
1919
try{
2020
const parse = JSON.parse(req.body.projectData);
21-
req.body = parse;
21+
req.body.projectData = parse;
2222
}catch(e){
23+
console.log(e);
2324
return res.status(400).json({ message: 'Invalid JSON in projectData field' });
2425
}
2526
}
@@ -33,132 +34,162 @@ export default function projectsRouter(
3334
const router = Router()
3435

3536
// Get all User
36-
/**
37-
* @api {get} /api/v1/projects Get all projects
38-
* @apiName getProjects
39-
* @apiGroup Project
40-
*
41-
* @apiSuccess {Object{}} An array of all projects
42-
*/
37+
/**
38+
* @api {get} /api/v1/projects Get all projects
39+
* @apiName getProjects
40+
* @apiGroup Project
41+
*
42+
* @apiSuccess {Object[]} projects List of all projects
43+
*
44+
* @apiSuccessExample {json} Success-Response:
45+
* HTTP/1.1 200 OK
46+
* [
47+
* {
48+
* "id": 1,
49+
* "name": "Project Alpha",
50+
* "imageUrl": "https://example.com/image.png",
51+
* "githubUrl": "https://github.com/org/project-alpha",
52+
* "deployUrl": "https://project-alpha.example.com",
53+
* "AdminId": "uuid-string",
54+
* "createdAt": "2025-07-18T10:00:00Z",
55+
* "updatedAt": "2025-07-18T10:00:00Z"
56+
* },
57+
* {
58+
* "id": 2,
59+
* "name": "Project Beta",
60+
* ...
61+
* }
62+
* ]
63+
*
64+
* @apiError (500) InternalServerError Failed to fetch projects from the database
65+
*/
66+
4367
router.get('/', getProjects)
4468

4569
// get Project by Id
46-
/**
47-
* @api {get} /api/v1/projects/:projectId Get specific project by its ID
48-
* @apiName getProjectById
49-
* @apiGroup Project
50-
*
51-
* @apiParam {UUID} projectId ID of the project
52-
* @apiSuccess {object{}} Get single project whoes ID -> projectID
53-
*
54-
* @apiError {object{}} No projects with such ID
55-
*/
70+
/**
71+
* @api {get} /api/v1/projects/:projectId Get specific project by ID
72+
* @apiName getProjectById
73+
* @apiGroup Project
74+
*
75+
* @apiParam (Path) {UUID} projectId ID of the project
76+
*
77+
* @apiSuccess {Object} project The project object with the given ID
78+
*
79+
* @apiError (404) NotFound No project found with the specified ID
80+
* @apiError (500) InternalServerError Database error or internal issue
81+
*/
82+
5683
router.get('/:projectId', getProjectById)
5784

5885
// Create project
59-
/**
60-
* @api {post} /api/v1/projects/create Create the new Project
61-
* @apiName createProject
62-
* @apiGroup Project
63-
*
64-
* @apiParam {Request body} {string} Name of the project
65-
* @apiParam {Request body} {string} Image usrl of project Photo
66-
* @apiParam {Request body} {string} githubUrl of project
67-
* @apiParam {Request body} {string} deploy link of project
68-
* @apiParam { UUID } {string} AdminID ID of the admin who create the project
69-
*
70-
* @apiSuccess {object{}} created project by the admin
71-
*
72-
* @apiError { error 400} some fields are missing
73-
* @apiError { error 500} error related to the db interaction
74-
*/
86+
/**
87+
* @api {post} /api/v1/projects/create Create a new project
88+
* @apiName createProject
89+
* @apiGroup Project
90+
*
91+
* @apiParam (FormData) {String} name Name of the project
92+
* @apiParam (FormData) {File} image Image file for the project
93+
* @apiParam (FormData) {String} githubUrl GitHub URL of the project
94+
* @apiParam (FormData) {String} deployUrl Deployment link of the project
95+
* @apiParam (FormData) {UUID} AdminId ID of the admin creating the project
96+
*
97+
* @apiSuccess {Object} project The created project object
98+
*
99+
* @apiError (400) BadRequest Some fields are missing
100+
* @apiError (500) InternalServerError Database error or internal issue
101+
*/
102+
75103
router.post('/create', upload.single('image') , parseCreateProjectData , createProject )
76104

77105
// Update Project
78-
/**
79-
* @api {patch} /api/v1/projects/:projectId/update Update the projects with given project id
80-
* @apiName updateProjects
81-
* @apiGroup Project
82-
*
83-
* @apiParam {Request body} ? {string} Name of the project
84-
* @apiParam {Request body} ? {string} Image usrl of project Photo
85-
* @apiParam {Request body} ? {string} githubUrl of project
86-
* @apiParam {Request body} ? {string} deploy link of project
87-
* @apiParam { UUID } {string} AdminID ID of the admin who update the project
88-
* @apiParam { projectID } {number} projectID ID of the project
89-
*
90-
* @apiSuccess {object{}} updated project by the admin
91-
*
92-
* @apiError { error 400} some fields are missing
93-
* @apiError { error 500} error related to the db interaction
94-
*/
95-
router.patch('/:projectId/update', updateProjects )
106+
/**
107+
* @api {patch} /api/v1/projects/:projectId/update Update a project
108+
* @apiName updateProjects
109+
* @apiGroup Project
110+
*
111+
* @apiParam (Path Params) {Number} projectId ID of the project to update
112+
* @apiParam (Body) {String} [name] Name of the project (optional)
113+
* @apiParam (Body) {String} [githubUrl] GitHub URL of the project (optional)
114+
* @apiParam (Body) {String} [deployUrl] Deployment link of the project (optional)
115+
* @apiParam (Body) {UUID} adminId ID of the admin updating the project (required)
116+
* @apiParam (Form Data) {File} [image] Image file (optional)
117+
*
118+
* @apiSuccess {Object} project Updated project data
119+
*
120+
* @apiError (400) BadRequest Some required fields are missing or invalid
121+
* @apiError (500) InternalServerError Database error or unexpected issue
122+
*/
123+
124+
router.patch('/:projectId/update', upload.single('image') , parseCreateProjectData , updateProjects )
96125

97126
// delete projects
98127

99-
/**
100-
* @api {delete} /api/v1/projects/:projectId/delete Delete the project
101-
* @apiName deleteProjects
102-
* @apiGroup Project
103-
*
104-
* @apiParam { projectId } { number } projectID ID of the project to be delete
105-
* @apiParam { UUID } {string} AdminID ID of the admin who delete the project
106-
*
107-
* @apiSuccess {Object{}} A deleted project
108-
*
109-
* @apiError {error 400} Some fields are missing
110-
* @apiError {error 500} Internal server error
111-
*/
128+
/**
129+
* @api {delete} /api/v1/projects/:projectId/delete Delete a project
130+
* @apiName deleteProjects
131+
* @apiGroup Project
132+
*
133+
* @apiParam (Path Params) {Number} projectId ID of the project to be deleted
134+
*
135+
* @apiSuccess {Object} deletedProject Details of the deleted project
136+
*
137+
* @apiError (400) BadRequest Some required fields are missing or invalid
138+
* @apiError (500) InternalServerError Internal server error
139+
*/
140+
141+
142+
112143
router.delete('/:projectId/delete', deleteProjects )
113144

114-
// getMember by ProjectId
115-
/**
116-
* @api {get} /api/v1/projects/:projectId/members Get members enroll in projects
117-
* @apiName getMembersBYProjectId
118-
* @apiGroup MemberProject
119-
*
120-
* @apiParam { projectId } { number } projectID ID of the project
121-
*
122-
* @apiSuccess {Object{}} array of member associated with projects
123-
*
124-
* @apiError {error 400} Some fields are missing
125-
* @apiError {error 500} Internal server error
126-
*/
145+
/**
146+
* @api {get} /api/v1/projects/:projectId/members Get members enrolled in a project
147+
* @apiName getMembersByProjectId
148+
* @apiGroup MemberProject
149+
*
150+
* @apiParam (Path Params) {Number} projectId ID of the project
151+
*
152+
* @apiSuccess {Object[]} members Array of members associated with the project
153+
*
154+
* @apiError (400) BadRequest Some required fields are missing
155+
* @apiError (500) InternalServerError Internal server error
156+
*/
157+
127158

128159
router.get('/:projectId/members', getMembersByProjectId )
129160

130-
// add member to project
131-
/**
132-
* @api {post} /api/v1/projects/:projectId/members add members into projects
133-
* @apiName addmembers
134-
* @apiGroup MemberProject
135-
*
136-
* @apiParam { projectId } { number } projectID ID of the project
137-
* @apiParam { Request body} { array } constains the array of memberId
138-
*
139-
* @apiSuccess {Object{}} array of member added into projects
140-
*
141-
* @apiError {error 400} Some fields are missing
142-
* @apiError {error 500} Internal server error
143-
*/
161+
/**
162+
* @api {post} /api/v1/projects/:projectId/members Add members to a project
163+
* @apiName addMembers
164+
* @apiGroup MemberProject
165+
*
166+
* @apiParam (Path Params) {Number} projectId ID of the project
167+
* @apiParam (Request Body) {UUID[]} memberIds Array of member IDs to add to the project
168+
*
169+
* @apiSuccess {Number} count Number of members successfully added
170+
*
171+
* @apiError (400) BadRequest Some required fields are missing
172+
* @apiError (500) InternalServerError Internal server error
173+
*/
144174

145175

146176
router.post('/:projectId/members' , addMembers )
147177

148178
// Remover the memnber
149-
/**
150-
* @api {delete} /api/v1/projects/:projectId/members/:memberId add members into projects
151-
* @apiName removeMembers
152-
* @apiGroup MemberProject
153-
*
154-
* @apiParam { projectId } { number } projectID ID of the project
155-
* @apiParam { memberId} { string } memberID ID of the member
156-
*
157-
* @apiSuccess {Object{}} member which are deleted
158-
*
159-
* @apiError {error 400} Some fields are missing
160-
* @apiError {error 500} Internal server error
161-
*/
179+
/**
180+
* @api {delete} /api/v1/projects/:projectId/members/:memberId Remove a member from a project
181+
* @apiName removeMember
182+
* @apiGroup MemberProject
183+
*
184+
* @apiParam (Path Params) {Number} projectId ID of the project
185+
* @apiParam (Path Params) {UUID} memberId ID of the member to be removed
186+
*
187+
* @apiSuccess {Object} member The member that was removed
188+
*
189+
* @apiError (400) BadRequest Some required fields are missing
190+
* @apiError (500) InternalServerError Internal server error
191+
*/
192+
162193

163194
router.delete( '/:projectId/members/:memberId', removeMembers)
164195

0 commit comments

Comments
 (0)