Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reusable form #1471

Merged
merged 13 commits into from
Aug 26, 2023
2 changes: 2 additions & 0 deletions backend/routers/projects.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ router.post('/', ProjectController.create);

router.get('/:ProjectId', ProjectController.project_by_id);

router.put('/:ProjectId', ProjectController.update);

router.patch('/:ProjectId', ProjectController.update);


Expand Down
2 changes: 1 addition & 1 deletion backend/routers/projects.router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('UPDATE', () => {

// Update project
const res2 = await request
.patch(`/api/projects/${res.body._id}`)
.put(`/api/projects/${res.body._id}`)
.set(headers)
.send(updatedDataPayload);
expect(res2.status).toBe(200);
Expand Down
3 changes: 2 additions & 1 deletion client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import ProjectLeaderDashboard from './pages/ProjectLeaderDashboard';
import UserAdmin from './pages/UserAdmin';
import ProjectList from './pages/ProjectList';
import ManageProjects from './pages/ManageProjects';
import addProject from './components/manageProjects/addProject';
import HealthCheck from './pages/HealthCheck';
import SecretPassword from './pages/SecretPassword';
import UserWelcome from './pages/UserWelcome';
Expand Down Expand Up @@ -49,7 +50,7 @@ const routes = [
{ path: '/events', name: 'events', Component: Events },
{ path: '/useradmin', name: 'useradmin', Component: UserAdmin },
{ path: '/projects', name: 'projects', Component: ProjectList },
{ path: '/projects/create', name: 'projectform', Component: ProjectForm },
{ path: '/projects/create', name: 'projectform', Component: addProject},
{
path: '/projects/:projectId',
name: 'project',
Expand Down
20 changes: 4 additions & 16 deletions client/src/api/ProjectApiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ProjectApiService {
}
}

// Handles the POST request and returns the projects ID.
async create(projectData) {
const {
name,
Expand Down Expand Up @@ -58,26 +59,13 @@ class ProjectApiService {
}
}

async updateProject(projectId, fieldName, fieldValue) {
let updateValue = fieldValue;
// These field are arrays, but the form makes them comma separated strings,
// so this adds it back to db as an arrray.
if (
fieldValue &&
(fieldName === 'partners' || fieldName === 'recruitingCategories')
) {
updateValue = fieldValue
.split(',')
.filter((x) => x !== '')
.map((y) => y.trim());
}

async updateProject(projectId, projectData) {
// Update database
const url = `${this.baseProjectUrl}${projectId}`;
const requestOptions = {
method: 'PATCH',
method: 'PUT',
headers: this.headers,
body: JSON.stringify({ [fieldName]: updateValue }),
body: JSON.stringify({ ...projectData }),
};

try {
Expand Down
Loading
Loading