Ananto30 / golpo-express

Backend of the Social Network - Golpo
https://golpo.vercel.app
4 stars 15 forks source link

Update text to url and added validation #11

Closed alammoiz closed 2 years ago

Ananto30 commented 2 years ago

It's not working 😟 Am I missing something?

image

alammoiz commented 2 years ago

I have updated the schema, please try with url not text @Ananto30

ref: createPost now takes text in body, replace that with url

Ananto30 commented 2 years ago

Oh sorry, my mistake 🙏 After changing it to url -

image

I think just includes won't suffice const isAdultUrl = adultURLs.includes(value);

Ananto30 commented 2 years ago

Still not working 😟 I think we can check this inside the controller method createPost. And please test before pushing 🙏

You need to add not() and this works

body("url", "Adult contents are not allowed").not().isIn(adultURLs)

But only for the exact match, like if I put exactly "https://www.timeout.com"

So this is not the solution I think. If the express-validator cannot do this, we can always write a method to do that 😃

alammoiz commented 2 years ago

Still not working 😟 I think we can check this inside the controller method createPost. And please test before pushing 🙏

You need to add not() and this works

body("url", "Adult contents are not allowed").not().isIn(adultURLs)

But only for the exact match, like if I put exactly "https://www.timeout.com"

So this is not the solution I think. If the express-validator cannot do this, we can always write a method to do that 😃

You're Right. But I'm not an expert in express-validator. So, I have pushed the code with only this fix that you have mentioned. Can you please merge this PR or open another ticket of custom validation for url. I shall be very thankful if you could do this. 😃

Or can you please help me?

Ananto30 commented 2 years ago

Thanks @alammoiz Rest of the task transferred to https://github.com/Ananto30/golpo-express/issues/14