Skip to content

Commit

Permalink
feat(notices.ts): add getNoticeEnvs function to retrieve unique envs …
Browse files Browse the repository at this point in the history
…for a given project ID
  • Loading branch information
masterkain committed May 28, 2023
1 parent ff818ac commit 4535dfa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 2 additions & 4 deletions app/projects/[project_id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Search from '@/components/Search';
import SidebarDesktop from '@/components/SidebarDesktop';
import SidebarMobile from '@/components/SidebarMobile';
import ProjectActionsMenu from '@/components/project/ActionsMenu';
import { getNotices } from '@/lib/queries/notices';
import { getNoticeEnvs } from '@/lib/queries/notices';
import { getProjectById } from '@/lib/queries/projects';
import type { Route } from 'next';
import { Metadata } from 'next';
Expand All @@ -30,9 +30,7 @@ export default async function ProjectNotices({ params, searchParams }: Component
throw new Error('Project not found');
}

const notices = await getNotices(project.id, {});
const envArray = notices.map((notice) => notice.env);
const uniqueEnvArray = Array.from(new Set(envArray));
const uniqueEnvArray = await getNoticeEnvs(project.id);

const breadcrumbs = [
{
Expand Down
17 changes: 17 additions & 0 deletions lib/queries/notices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,20 @@ export const getNoticeIdsByProjectId = async (projectId: string): Promise<string
});
return notices.map((notice) => notice.id);
};

export async function getNoticeEnvs(projectId: string): Promise<string[]> {
const notices = await prisma.notice.findMany({
where: {
project_id: projectId,
},
select: {
env: true
},
orderBy: {
env: 'asc',
},
distinct: ['env']
});

return notices.map((notice) => notice.env);
}

0 comments on commit 4535dfa

Please sign in to comment.