next/server/api/bands/all.get.ts

19 lines
503 B
TypeScript

import { Band } from "~/models/band";
import { IUser } from "~/models/user";
export default eventHandler(async (ev) => {
let bands = await Band.find({
_id: {
// $not: {name: ""},
$nin: (ev.context.currentUser as IUser)?.hiddenBands || [],
},
}).exec();
return bands
.filter((a) => a.name != "")
.sort((a, b) => {
if (a.name.toLocaleLowerCase() > b.name.toLocaleLowerCase()) return 1;
if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) return -1;
return 0;
});
});