Skip to content
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

Question: where to place additional code for model, with different route? #148

Open
ApayRus opened this issue May 5, 2020 · 2 comments
Open

Comments

@ApayRus
Copy link

ApayRus commented May 5, 2020

Thanks for boilerplate. It's very helpful.
It's my first real project with express and mongoose, and I'm sorry if my question is stupid.
I'm working on dictionary, and have an Article model:

const articleSchema = new Schema({
  wordTable: { type: String, required: true },
  wordForms: { type: [String] }
})

I need new route /search/:text
This route not related to /article route, but method still related to article model:
Article.find({ wordForms: text })
I'm a little confused, where to place this code.
Can you give me an advice please?

@ndelvalle
Copy link
Owner

Hi @Aparus by any chance your project is open sources so I can take a look?
I need a bit more context to help you out. If that route is not related to articles, what is related to? Maybe is related to another model? If it's related to another model and the route is there, it is totally ok to use the Article model reference from some other model.
I hope this helps and sorry if the answer is a bit vague.

@ApayRus
Copy link
Author

ApayRus commented May 6, 2020

For now my whole project is just your basic boilerplate, I swear there is nothing to share. :)
I just little changed Article model, as I wrote above, from { title, body } to { wordTable, wordForms }. I just meant, that desired route is not part of link domain.com/article/, but completely different link domain.com/search/:text. And I can't write this route into /model/article/router.js, and there is no other than Article model for write it. Where is better place to write this route?

But this route should run method on the Article model, and find text in array field, and there will be other methods in the future, related only to Article model. All existing by default methods are written in lib/controller.js and lib/facade.js. And now I need unique method only for Article model, not shared with other models. I guess I should write it in model/article/controller.js and model/article/facade.js. Should I?
Where to write not universal method, but especial method for one particular model? How to expand model?

Please, provide with couple examples, how to write unique method for only one model. And where to place strange routes :-)

I apologize for my ignorance, I worked last year with firebase and material-ui, and forget many of things I had learned before about express-mongoose stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants