Partypack/Server/Source/Routes/Discovery.ts

26 lines
810 B
TypeScript
Raw Normal View History

2024-01-28 11:07:10 +01:00
import { Router } from "express";
import { ForcedCategory } from "../Schemas/ForcedCategory";
import { Song } from "../Schemas/Song";
const App = Router();
App.get("/", async (req, res) => {
const ForcedCategories = await ForcedCategory.find({ where: { Activated: true } });
const New = {
ID: "new",
Header: "Recently added",
2024-01-28 22:02:29 +01:00
Songs: (await Song.find({ where: { IsDraft: false }, take: 10, order: { CreationDate: "DESC" } })).map(x => x.Package()),
2024-01-28 11:07:10 +01:00
Priority: 100,
Custom: false
}
res.json([
...ForcedCategories.map(x => { return { ...x, Custom: true, Songs: x.Songs.map(y => y.Package()) }; }),
New
].sort((a, b) => a.Priority - b.Priority))
});
export default {
App,
DefaultAPI: "/api/discovery"
}