Commit f2c8df1d by jaymehta

search bar custom api

1 parent cb90f3ef
......@@ -274,4 +274,45 @@ module.exports = createCoreController("api::experience.experience", () => ({
ctx.throw(500, error);
}
},
async getSearchResponse(ctx) {
const string = ctx.request.body.string;
console.log("str", ctx.request.body.string);
if (!string.length > 0) {
return ctx.notFound("Please pass a valid string");
}
const activities = await strapi.db
.query("api::experience.experience")
.findMany({
where: {
name: {
$contains: string,
},
},
});
const categories = await strapi.db
.query("api::categorie.categorie")
.findMany({
where: {
name: {
$contains: string,
},
},
});
console.log("activities", activities);
console.log("categories", categories);
let responseData = {};
responseData["categories"] = categories?.map((item) => {
return { id: item.id, name: item.name };
});
responseData["activities"] = activities?.map((item) => {
return { id: item.id, name: item.name };
});
return ctx.send({
success: true,
data: responseData,
});
},
}));
......@@ -7,6 +7,14 @@ const routes = {
config: {
//some Configuration
},
},
{
method: "POST",
path: "/experience/get-search-response",
handler: "api::experience.experience.getSearchResponse",
config: {
//some Configuration
},
}
],
};
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!