next/server/api/all-users.get.ts

14 lines
311 B
TypeScript
Raw Normal View History

import { User } from "~/models/user";
export default eventHandler(async (ev) => {
const q = getQuery(ev);
const regex = new RegExp(`.*${q.name}.*`, "i");
const users = await User.find({
username: regex,
banned: false,
})
.select("username _id")
.exec();
return users.map((a) => a.toObject());
});