URL Shortened Microservice (short link redirect)

Tell us what’s happening: So the problem is with third case. I checked all remaining sections and it worked but for third part it keeps telling me that my file doesn’t redirect. while if u try to do it manually it works. maybe proctoring algo needs some specific method. any help would be appreciated.

Your project link(s)

Project link:
https://repl.it/join/bhazqock-irtesamvirani

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36.

Challenge: URL Shortener Microservice

Link to the challenge:

Welcome, irtesam.

When I run the tests, I see these errors in the browser console:
image

This happens, because you app crashes with:

{
  original_url: 'https://boilerplate-project-urlshortener.irtesamvirani.repl.co/?v=1614965007550',
  short: 1
}
Error: Url validation failed: original: Path `original` is required.

I think a major issue is the logic here:

Url.findOne({})
        .sort({ short: 'desc' })
        .exec((error, result) => {
            console.log(error, result)
            if (!error && result != undefined) {
                console.log(error, result)
                inputShort = result.short + 1
            }
            if (!error) {
                Url.findOne({ original: inputUrl })

That is, having a nested Model.find does not seem like the best way to do what the user-stories are asking, and I think it is tripping up the workflow.


Also, this does not look like this issue, but keep in mind, programming, in general, requires very specific attention to detail:

If you pass an invalid URL that doesn’t follow the valid http://www.example.com format, the JSON response will contain { error: 'invalid url' }

Url.findOne({ short: input }, (error, result) => {
        if (!error && result != undefined) {
            response.redirect(result.original)
        } else {
            response.json({ error: 'Invalid URL' })
        }
    })

UPDATE: No issue with algorithm or anything else.
90% of the projects saw in quest of completing mine had one simple error:
Variable used in this section of code

Url.findOne({ short: input }, (error, result) => {
        if (!error && result != undefined) {
            response.redirect(result.original)
        } else {
            response.json({ error: 'Invalid URL' })
        }
    })

I Used this: { short: input }
But Url in my database was stored as short_url