Fixed it! Thanks to another one of your answers.
Added another route above terms to separate term/letter
from terms/letter/term_id
.
Router.map(function() {
this.route("home", { path: "/" });
this.route("term", function() {
this.route("letter", { path: "/:letter" })
});
this.route("terms", function() {
this.route("letter", { path: "/:letter" }, function() {
this.route("term_id", { path: "/:term_id" });
});
});
});
Then just added a new this.get
to the mirage config.
export default function() {
this.namespace = "api";
this.get("/term", function({ terms }, { queryParams }) {
let { letter } = queryParams;
let results = terms.all();
if (letter) {
const match = letter.toLowerCase();
results = results.filter(t => t.term.toLowerCase()[0] === match);
}
return results;
});
this.get("/terms", function({ terms }, { queryParams }) {
let { term, letter } = queryParams;
let results = terms.all();
if (letter) {
const match = letter.toLowerCase();
results = results.filter(t => t.term.toLowerCase()[0] === match);
}
if (term) {
const match = term.toLowerCase();
results = results.filter(t => t.term.toLowerCase().includes(match));
}
return results;
});
this.get("/terms/:id");
}
Works like a charm. POW!
Have a great weekend!!