Hi folks, having some issues with my ULR shortener.
At a high level I plan to implement:
submit url to be shortened
-> check if the url has already been shortened in database
-> if it has be shortened, return that record as json
-> else make a new shortened url to store in db
-----> need to check the number of records in db first before assigning a number for the shortened url
-> return new shortened url as json
-> implement the action of directing to the shortened url (still trying to figure out above before thinking too much about this piece)
I am slowly piecing it together, but am having issues looking up the records in the db.
I have a finder function that will look up the number of records and return the results. Within the finder function, I can log the data that returns from the database find, but when I try to return that data through the finder function, it returns undefined, even if it found records.
I think there is some asynchronous workings going on that I don’t quite understand, or I am not using the callback correctly. Hoping for some feedback! Feel free to share feedback on the general high level implementation as well.
The project so far is on glitch, below are links to specifics parts that I am trying to figure out.
If you view the page with logs open, and trigger the post action, you will see the statements getting logged.