I have this get Request
router.get('/', async (req, res) => {
//I connect to the DB and i return the collection with Posts
const posts = await loadPostsCollection();
res.send(await posts.find({ "tmima": { "$eq": 'andriko' } }).toArray());
});
Everything works Fine as it is.. the problem is that i want to find the posts dynamicaly and not having this 'andriko' there..
I tried this { "tmima": { "$eq": req.body.params } } but its now working... the weird thing is that with req.body.params it shows all the other posts except those that have tmima: 'andriko'
This 'tmima' value comes from the dynamic route so thats why i need this req.body.params or something similar, to show the posts based on the routing.
Thx in advance!
EDIT!! FronteEnd section included!!
router.js
const routes = [
{
path: "/",
name: "Home",
component: Home,
},
{
path: "/katigories/:tmima",
name: "katigories",
props: true,
component: () => import("../views/katigories.vue"),
children: [
{ path: 'anakoinoseis', name: 'anakoinoseis', props: true, component: () => import("../views/Ypokatigories/Anakoinoseis.vue")},
{ path: 'roster', name: 'roster', props: true, component: () => import("../views/Ypokatigories/RosterView.vue")},
{ path: 'vathmologia', name: 'vathmologia', props: true, component: () => import("../views/Ypokatigories/Vathmologia.vue")}
]
}
axios.js
import axios from 'axios'
const url = 'http://localhost:5000/api/posts/';
class AnnouncementsService {
//GET Annaouncements
static getPosts() {
return new Promise ((resolve,reject) => {
axios.get(url).then((res) => {
const data = res.data;
resolve(
data.map(post => ({
...post,
createdAt: new Date(post.createdAt)
}))
);
})
.catch((err)=> {
reject(err);
})
});
}
Anakoinoseis.vue
<script>
import AnnouncementsService from '../../store/axios'
export default {
name: 'Announcements',
props: ['tmima'],
data() {
return {
posts: [],
text: '',
title: ''
}
},
async created() {
try {
this.posts = await AnnouncementsService.getPosts();
await console.log(this.tmima)
}catch(err){
this.error = err.message;
}
},
</script>