-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
const router = require('express').Router(); | ||
|
||
const { getAlumni } = require('./student'); | ||
const { getProjectData, getProjectsData } = require('./project'); | ||
const { getCohortsData, getSpecificCohort } = require('./cohort'); | ||
const { getProjectData } = require('./project'); | ||
|
||
router.get('/alumni', getAlumni); | ||
router.get('/cohorts/:cohortId', getSpecificCohort); | ||
router.get('/projects', getProjectsData); | ||
router.get('/cohorts', getCohortsData); | ||
router.get('/cohorts/:cohortId', getSpecificCohort); | ||
router.get('/projects/:projectId', getProjectData); | ||
|
||
module.exports = router; |
33 changes: 33 additions & 0 deletions
33
server/controllers/routes/user/project/getProjectsByType.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { getProjects } = require('../../../../database/queries'); | ||
|
||
const getProjectsData = async (req, res, next) => { | ||
try { | ||
const { type } = req.query; | ||
if ( | ||
type.toLowerCase() === 'internal' || | ||
type.toLowerCase() === 'remotely' | ||
) { | ||
const { rows } = await getProjects(type); | ||
if (rows.length > 0) { | ||
res.json({ | ||
statusCode: 200, | ||
data: rows, | ||
}); | ||
} else { | ||
res.json({ | ||
statusCode: 200, | ||
message: `There is no ${type} projects`, | ||
}); | ||
} | ||
} else { | ||
res.status(404).json({ | ||
statusCode: 404, | ||
message: 'Please enter valid type', | ||
}); | ||
} | ||
} catch (err) { | ||
next(err); | ||
} | ||
}; | ||
|
||
module.exports = getProjectsData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
const getProjectsData = require('./getProjectsByType'); | ||
const getProjectData = require('./getProjectById'); | ||
|
||
module.exports = { | ||
getProjectsData, | ||
getProjectData, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const connection = require('../../config/connection'); | ||
|
||
const getProjects = (ProjectType) => | ||
connection.query( | ||
'SELECT * FROM project WHERE project_type ilike $1 ORDER BY name', | ||
[ProjectType], | ||
); | ||
|
||
module.exports = getProjects; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters