next/server/api/band/all.get.ts
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ ee7ea24e4e
refactor(*): rename route
change "bands" to "band"

BREAKING CHANGE: breaks anything that tries to access `/api/bands/*`
2023-12-06 22:22:48 -05:00

19 lines
509 B
TypeScript

import { Band } from "~/models/band";
import { IUser } from "~/models/user";
export default cachedEventHandler(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;
});
});