Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

bug: removed dependency for solution.id from client (#1045)

Ayush Kumar Yadav4f5605dedf88
diff --git a/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/_actions.ts b/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/_actions.ts
index e3f16ba6..052bbe43 100644
--- a/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/_actions.ts
+++ b/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/_actions.ts
@@ -24,10 +24,17 @@ interface SolutionUpdateArgs {
export const createCacheKeyForSolutions = (slug: string) => `challenge-${slug}-solutions`;
export const createCacheKeyForSharedSolutionsTab = (userId: string) => `${userId}-shared-solutions`;
-export async function updateSolution({ id, description, slug, title, userId }: SolutionUpdateArgs) {
+export async function updateSolution({ id, description, slug, title }: SolutionUpdateArgs) {
const session = await getServerAuthSession();
- if (!isAuthor(session, userId)) {
- throw new Error('Only author can delete their solution.');
+
+ const solution = await prisma.sharedSolution.findFirstOrThrow({
+ where: {
+ id,
+ },
+ });
+
+ if (!isAuthor(session, solution.userId) && !isAdminOrModerator(session)) {
+ throw new Error('Not authorized to edit this solution.');
}
await prisma.sharedSolution.update({
@@ -59,7 +66,13 @@ export async function postSolution({ challengeId, description, slug, title, user
export async function deleteSolution(solutionToDelete: ChallengeSolution) {
const session = await getServerAuthSession();
- if (!isAuthor(session, solutionToDelete?.userId) && !isAdminOrModerator(session)) {
+ const solution = await prisma.sharedSolution.findFirstOrThrow({
+ where: {
+ id: solutionToDelete.id,
+ },
+ });
+
+ if (!isAuthor(session, solution.userId) && !isAdminOrModerator(session)) {
throw new Error('Not authorized to delete this solution.');
}
diff --git a/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/solution-detail.tsx b/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/solution-detail.tsx
index 3f6f8550..62a57786 100644
--- a/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/solution-detail.tsx
+++ b/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/solution-detail.tsx
@@ -136,7 +136,6 @@ export function SolutionDetails({ solution }: Props) {
</Button>
) : null}
- {/* Only author can see edit / delete button */}
{isAuthor(session, solution.userId) || isAdminOrModerator(session) ? (
<>
<Tooltip>