-
Notifications
You must be signed in to change notification settings - Fork 2
Introduce MVP-level coaching session Note creation/updating #25
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
efdf079
Creates a new note when a coaching session page first loads and an as…
jhodapp af6eaf9
Fetch Note instance by id and update note when user makes changes.
jhodapp b098e13
Clear the coaching notes sync status on key down event
jhodapp d160686
Make sure the handleKeyDown event handler has the correct definition
jhodapp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,173 @@ | ||
// Interacts with the note endpoints | ||
|
||
import { Id } from "@/types/general"; | ||
import { defaultNote, isNote, isNoteArray, Note, noteToString, parseNote } from "@/types/note"; | ||
import { AxiosError, AxiosResponse } from "axios"; | ||
|
||
export const fetchNotesByCoachingSessionId = async ( | ||
coachingSessionId: Id | ||
): Promise<Note[]> => { | ||
const axios = require("axios"); | ||
|
||
var notes: Note[] = []; | ||
var err: string = ""; | ||
|
||
const data = await axios | ||
.get(`http://localhost:4000/notes`, { | ||
params: { | ||
coaching_session_id: coachingSessionId, | ||
}, | ||
withCredentials: true, | ||
setTimeout: 5000, // 5 seconds before timing out trying to log in with the backend | ||
headers: { | ||
"X-Version": "0.0.1", | ||
}, | ||
}) | ||
.then(function (response: AxiosResponse) { | ||
// handle success | ||
if (response?.status == 204) { | ||
console.error("Retrieval of Note failed: no content."); | ||
err = "Retrieval of Note failed: no content."; | ||
} else { | ||
var notes_data = response.data.data; | ||
if (isNoteArray(notes_data)) { | ||
notes_data.forEach((note_data: any) => { | ||
notes.push(parseNote(note_data)) | ||
}); | ||
} | ||
} | ||
}) | ||
.catch(function (error: AxiosError) { | ||
// handle error | ||
console.error(error.response?.status); | ||
if (error.response?.status == 401) { | ||
console.error("Retrieval of Note failed: unauthorized."); | ||
err = "Retrieval of Note failed: unauthorized."; | ||
} else { | ||
console.log(error); | ||
console.error( | ||
`Retrieval of Note by coaching session Id (` + coachingSessionId + `) failed.` | ||
); | ||
err = | ||
`Retrieval of Note by coaching session Id (` + coachingSessionId + `) failed.`; | ||
} | ||
}); | ||
|
||
if (err) | ||
throw err; | ||
|
||
return notes; | ||
}; | ||
|
||
export const createNote = async ( | ||
coaching_session_id: Id, | ||
user_id: Id, | ||
body: string | ||
): Promise<Note> => { | ||
const axios = require("axios"); | ||
|
||
const newNoteJson = { | ||
coaching_session_id: coaching_session_id, | ||
user_id: user_id, | ||
body: body | ||
}; | ||
console.debug("newNoteJson: " + JSON.stringify(newNoteJson)); | ||
// A full real note to be returned from the backend with the same body | ||
var createdNote: Note = defaultNote(); | ||
var err: string = ""; | ||
|
||
//var strNote: string = noteToString(note); | ||
const data = await axios | ||
.post(`http://localhost:4000/notes`, newNoteJson, { | ||
withCredentials: true, | ||
setTimeout: 5000, // 5 seconds before timing out trying to log in with the backend | ||
headers: { | ||
"X-Version": "0.0.1", | ||
"Content-Type": "application/json", | ||
}, | ||
}) | ||
.then(function (response: AxiosResponse) { | ||
// handle success | ||
const noteStr = response.data.data; | ||
if (isNote(noteStr)) { | ||
createdNote = parseNote(noteStr); | ||
} | ||
}) | ||
.catch(function (error: AxiosError) { | ||
// handle error | ||
console.error(error.response?.status); | ||
if (error.response?.status == 401) { | ||
console.error("Creation of Note failed: unauthorized."); | ||
err = "Creation of Note failed: unauthorized."; | ||
} else if (error.response?.status == 500) { | ||
console.error( | ||
"Creation of Note failed: internal server error." | ||
); | ||
err = "Creation of Note failed: internal server error."; | ||
} else { | ||
console.log(error); | ||
console.error(`Creation of new Note failed.`); | ||
err = `Creation of new Note failed.`; | ||
} | ||
} | ||
); | ||
|
||
if (err) | ||
throw err; | ||
|
||
return createdNote; | ||
}; | ||
|
||
export const updateNote = async ( | ||
id: Id, | ||
user_id: Id, | ||
coaching_session_id: Id, | ||
body: string, | ||
): Promise<Note> => { | ||
const axios = require("axios"); | ||
|
||
var updatedNote: Note = defaultNote(); | ||
var err: string = ""; | ||
|
||
const newNoteJson = { | ||
coaching_session_id: coaching_session_id, | ||
user_id: user_id, | ||
body: body | ||
}; | ||
|
||
const data = await axios | ||
.put(`http://localhost:4000/notes/${id}`, newNoteJson, { | ||
withCredentials: true, | ||
setTimeout: 5000, // 5 seconds before timing out trying to log in with the backend | ||
headers: { | ||
"X-Version": "0.0.1", | ||
"Content-Type": "application/json", | ||
}, | ||
}) | ||
.then(function (response: AxiosResponse) { | ||
// handle success | ||
if (isNote(response.data.data)) { | ||
updatedNote = response.data.data; | ||
} | ||
}) | ||
.catch(function (error: AxiosError) { | ||
// handle error | ||
console.error(error.response?.status); | ||
if (error.response?.status == 401) { | ||
console.error("Update of Note failed: unauthorized."); | ||
err = "Update of Organization failed: unauthorized."; | ||
} else if (error.response?.status == 500) { | ||
console.error("Update of Organization failed: internal server error."); | ||
err = "Update of Organization failed: internal server error."; | ||
} else { | ||
console.log(error); | ||
console.error(`Update of new Organization failed.`); | ||
err = `Update of new Organization failed.`; | ||
} | ||
}); | ||
|
||
if (err) | ||
throw err; | ||
|
||
return updatedNote; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
interesting