Revert "undo commit"

This reverts commit 9103f67db5.
This commit is contained in:
daniel31x13
2024-11-03 03:27:52 -05:00
parent e37702aa14
commit dbd096ab76
176 changed files with 2362 additions and 9401 deletions
@@ -1,5 +1,5 @@
import { prisma } from "@/lib/api/db";
import { LinkRequestQuery, Order, Sort } from "@/types/global";
import { LinkRequestQuery, Sort } from "@/types/global";
type Response<D> =
| {
@@ -17,7 +17,7 @@ export default async function getDashboardData(
userId: number,
query: LinkRequestQuery
): Promise<Response<any>> {
let order: Order = { id: "desc" };
let order: any;
if (query.sort === Sort.DateNewestFirst) order = { id: "desc" };
else if (query.sort === Sort.DateOldestFirst) order = { id: "asc" };
else if (query.sort === Sort.NameAZ) order = { name: "asc" };
@@ -48,7 +48,7 @@ export default async function getDashboardData(
});
const pinnedLinks = await prisma.link.findMany({
take: 16,
take: 10,
where: {
AND: [
{
@@ -80,7 +80,7 @@ export default async function getDashboardData(
});
const recentlyAddedLinks = await prisma.link.findMany({
take: 16,
take: 10,
where: {
collection: {
OR: [
@@ -105,17 +105,12 @@ export default async function getDashboardData(
});
const links = [...recentlyAddedLinks, ...pinnedLinks].sort(
(a, b) => new Date(b.id).getTime() - new Date(a.id).getTime()
);
// Make sure links are unique
const uniqueLinks = links.filter(
(link, index, self) => index === self.findIndex((t) => t.id === link.id)
(a, b) => (new Date(b.id) as any) - (new Date(a.id) as any)
);
return {
data: {
links: uniqueLinks,
links,
numberOfPinnedLinks,
},
message: "Dashboard data fetched successfully.",