@@ -1,11 +1,11 @@
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import { LinkRequestQuery, Order, Sort } from "@/types/global";
|
||||
import { LinkRequestQuery, Sort } from "@/types/global";
|
||||
|
||||
export default async function getDashboardData(
|
||||
userId: number,
|
||||
query: LinkRequestQuery
|
||||
) {
|
||||
let order: Order = { id: "desc" };
|
||||
let order: any = { id: "desc" };
|
||||
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" };
|
||||
|
||||
@@ -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.",
|
||||
|
||||
Reference in New Issue
Block a user