mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-12 12:04:16 +00:00
added SearchController
This commit is contained in:
parent
318a62fe35
commit
1782db93c1
@ -0,0 +1,20 @@
|
|||||||
|
import getMutuals from "@services/getMutuals"
|
||||||
|
|
||||||
|
export default {
|
||||||
|
method: "GET",
|
||||||
|
route: "/quick",
|
||||||
|
middlewares: ["withAuthentication"],
|
||||||
|
fn: async (req, res) => {
|
||||||
|
let mutuals = await getMutuals({
|
||||||
|
from_user_id: req.user._id.toString(),
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error(error)
|
||||||
|
|
||||||
|
return []
|
||||||
|
})
|
||||||
|
|
||||||
|
return res.json({
|
||||||
|
friends: mutuals,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
import { User } from "@models"
|
||||||
|
|
||||||
|
export default {
|
||||||
|
method: "GET",
|
||||||
|
route: "/",
|
||||||
|
middlewares: ["withOptionalAuthentication"],
|
||||||
|
fn: async (req, res) => {
|
||||||
|
const { keywords = "" } = req.query
|
||||||
|
|
||||||
|
let suggestions = {}
|
||||||
|
|
||||||
|
// search users by username or name
|
||||||
|
const users = await User.find({
|
||||||
|
$or: [
|
||||||
|
{ username: { $regex: keywords, $options: "i" } },
|
||||||
|
{ fullName: { $regex: keywords, $options: "i" } },
|
||||||
|
],
|
||||||
|
})
|
||||||
|
.limit(5)
|
||||||
|
.select("username fullName avatar verified")
|
||||||
|
|
||||||
|
if (users.length > 0) {
|
||||||
|
suggestions["users"] = users
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.json(suggestions)
|
||||||
|
}
|
||||||
|
}
|
@ -1,37 +1,9 @@
|
|||||||
import { Controller } from "linebridge/dist/server"
|
import { Controller } from "linebridge/dist/server"
|
||||||
|
import generateEndpointsFromDir from "linebridge/dist/server/lib/generateEndpointsFromDir"
|
||||||
import { User, Post } from "@models"
|
|
||||||
|
|
||||||
export default class SearchController extends Controller {
|
export default class SearchController extends Controller {
|
||||||
static refName = "SearchController"
|
static refName = "SearchController"
|
||||||
static useRoute = "/search"
|
static useRoute = "/search"
|
||||||
|
|
||||||
httpEndpoints = {
|
httpEndpoints = generateEndpointsFromDir(__dirname + "/endpoints")
|
||||||
get: {
|
|
||||||
"/": {
|
|
||||||
middlewares: ["withOptionalAuthentication"],
|
|
||||||
fn: async (req, res) => {
|
|
||||||
const { keywords = "" } = req.query
|
|
||||||
|
|
||||||
let suggestions = {}
|
|
||||||
|
|
||||||
// search users by username or name
|
|
||||||
const users = await User.find({
|
|
||||||
$or: [
|
|
||||||
{ username: { $regex: keywords, $options: "i" } },
|
|
||||||
{ fullName: { $regex: keywords, $options: "i" } },
|
|
||||||
],
|
|
||||||
})
|
|
||||||
.limit(5)
|
|
||||||
.select("username fullName avatar verified")
|
|
||||||
|
|
||||||
if (users.length > 0) {
|
|
||||||
suggestions["users"] = users
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.json(suggestions)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user