-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
update edit page 1396 #1401
update edit page 1396 #1401
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,37 +20,31 @@ describe('CREATE', () => { | |
}; | ||
|
||
// Submit a project | ||
const res = await request | ||
.post('/api/projects/') | ||
.set(headers) | ||
.send(submittedData); | ||
const res = await request.post('/api/projects/').set(headers).send(submittedData); | ||
expect(res.status).toBe(201); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe('READ', () => { | ||
test('Get all projects with GET to /api/projects/', async (done) => { | ||
// Test Data | ||
const submittedData = { | ||
name: 'projectName', | ||
}; | ||
|
||
// Submit a project | ||
const res = await request | ||
.post('/api/projects/') | ||
.set(headers) | ||
.send(submittedData); | ||
expect(res.status).toBe(201); | ||
|
||
// Get all projects | ||
const res2 = await request.get('/api/projects/').set(headers); | ||
expect(res2.status).toBe(200); | ||
|
||
const APIData = res2.body[0]; | ||
expect(APIData.name).toBe(submittedData.name); | ||
done(); | ||
});; | ||
// Test Data | ||
const submittedData = { | ||
name: 'projectName', | ||
}; | ||
|
||
// Submit a project | ||
const res = await request.post('/api/projects/').set(headers).send(submittedData); | ||
expect(res.status).toBe(201); | ||
|
||
// Get all projects | ||
const res2 = await request.get('/api/projects/').set(headers); | ||
expect(res2.status).toBe(200); | ||
|
||
const APIData = res2.body[0]; | ||
expect(APIData.name).toBe(submittedData.name); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe('UPDATE', () => { | ||
|
@@ -61,10 +55,7 @@ describe('UPDATE', () => { | |
}; | ||
|
||
// Submit a project | ||
const res = await request | ||
.post('/api/projects/') | ||
.set(headers) | ||
.send(submittedData); | ||
const res = await request.post('/api/projects/').set(headers).send(submittedData); | ||
expect(res.status).toBe(201); | ||
|
||
const updatedDataPayload = { | ||
|
@@ -73,7 +64,7 @@ describe('UPDATE', () => { | |
|
||
// Update project | ||
const res2 = await request | ||
.patch(`/api/projects/${res.body._id}`) | ||
.put(`/api/projects/${res.body._id}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you've only materially edited one line in this file. It's hard to pick out what's being worked on and what isn't if we get lots of changes from your linter. Can you please go and pick out the specific part of the code you're changing? These steps shoud do the trick: Rebase recent changes
Locate commit with your code
Change
Save and close file Git now brings you to that specific commit state. Reset your changes to the previous HEAD. This unstages the changes you've made in this specific commit.
Now use
This will bring up an interactive selection in your terminal (complete with colors that won't show in markdown)
What do these mean? [y,n,q,a,d,j,J,g,/,e,?]
Sift through the changes by hunt to get the right one (
Commit these changes with amend
Finish out the rebase and force push up, overwriting your old commit with the linter changes.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll go ahead and fix the linting but I am leaning on scrapping most of this PR since we need to fix the Project Form. We currently need to separate the ProjectFrom component, AddProjectForm, and EditProjectForm component so we can reuse the form component for both the add and edit. It would be much cleaner and remove some unnecessary lines. |
||
.set(headers) | ||
.send(updatedDataPayload); | ||
expect(res2.status).toBe(200); | ||
|
@@ -96,15 +87,12 @@ describe('DELETE', () => { | |
}; | ||
|
||
// Submit a project | ||
const res = await request | ||
.post('/api/projects/') | ||
.set(headers) | ||
.send(submittedData); | ||
const res = await request.post('/api/projects/').set(headers).send(submittedData); | ||
expect(res.status).toBe(201); | ||
|
||
// Delete project | ||
const res2 = await request.patch(`/api/projects/${res.body._id}`).set(headers); | ||
expect(res2.status).toBe(200); | ||
done(); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,42 +52,28 @@ class ProjectApiService { | |
console.log('THIS BASEPROJECT URL', this.baseProjectUrl); | ||
|
||
try { | ||
const proj = await fetch(this.baseProjectUrl, requestOptions); | ||
const projectDetails = await proj.json() | ||
return projectDetails._id | ||
const proj = await fetch(this.baseProjectUrl, requestOptions); | ||
const projectDetails = await proj.json(); | ||
return projectDetails._id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hate to be a stickler about this stuff, but can you drop these changes? It makes it a lot harder to follow what is being changed the PR with a lot of other linting changes. I know it's a hassle and we don't have a linter up and running for the repo yet, but adding the specifc section you're wanting to edit wth There's a writeup in another comment on this PR review that has a walkthrough |
||
} catch (error) { | ||
console.error(`Add project error: `, error); | ||
alert('Server not responding. Please try again.'); | ||
return undefined; | ||
} | ||
} | ||
|
||
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 }), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm understand this correclty, this change is because we're now submitting a whole JSON object to update the database entry intead of one specific field value. Nice work! |
||
}; | ||
|
||
try { | ||
const response = await fetch(url, requestOptions); | ||
const resJson = await response.json(); | ||
|
||
return resJson; | ||
} catch (error) { | ||
console.log(`update project error: `, error); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please drop this change as per other comments in this PR review re: linting