before u push the "poem" to the db && re-write the file, u should check that the poem object contains all the appropriate properties && that those properties have the correct types
poem.datetime // number
poem.location // an array w/two items in it (both numbers)
poem.text // a string
poem.author // a string,
poem.route // a number
if something is wrong, then the function should return an object w/an error message like return { error: 'datetime should be a number' }
remove the commented code && replace the last line with res.json(check) if u're function is properly returning an object with a success or error message, than this will pass it along to the front end.
hey @armiesingh
update the addPoem function
let's improve the
addPoem()
function so that it validates the data && returns an error (if/when there's an issue) https://github.com/net-art-uchicago/cta-file-sharing/blob/235b371bfe9986e425e9fa4f8b22c3a0e1abdcb6/backend/init_database.js#L12-L19before u push the "poem" to the db && re-write the file, u should check that the poem object contains all the appropriate properties && that those properties have the correct types
if something is wrong, then the function should return an object w/an error message like
return { error: 'datetime should be a number' }
if the
poem
object passes all the validation then we can push it to the database && update the file, but rather than using the asynchronous versionwriteFile
like the file is now, let's use the synchronous versionwriteFileSync
like we do here: https://github.com/net-art-uchicago/cta-file-sharing/blob/235b371bfe9986e425e9fa4f8b22c3a0e1abdcb6/backend/init_database.js#L8&& the
return { message: 'success' }
or something similarupdate the add-poem REST API endpoint
https://github.com/net-art-uchicago/cta-file-sharing/blob/235b371bfe9986e425e9fa4f8b22c3a0e1abdcb6/backend/REST-API.js#L13-L22
remove the commented code && replace the last line with
res.json(check)
if u're function is properly returning an object with a success or error message, than this will pass it along to the front end.clean up
let's delete the test scripts:
let's remove this comment https://github.com/net-art-uchicago/cta-file-sharing/blob/235b371bfe9986e425e9fa4f8b22c3a0e1abdcb6/backend/REST-API.js#L8