Skip to content

Commit

Permalink
Fixed api changes
Browse files Browse the repository at this point in the history
Following the new way users are mapped to UserUI, changes were needed to some routes.
  • Loading branch information
wilzet committed Jan 4, 2024
1 parent 6687edd commit 2ce9cc9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/app/api/recipes/create/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ export async function POST(request: Request) {
},
});

const user = toUserUI(post.author);

return NextResponse.json({ user: user } as RecipePostResponse);
return NextResponse.json({ user: await toUserUI(post.author) } as RecipePostResponse);
} catch (err: any) {
console.error(err);
if (err.code === 'P2025') {
Expand Down
12 changes: 10 additions & 2 deletions src/app/api/recipes/update/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NextResponse } from 'next/server';
import { RecipePostRequest, RecipePostResponse } from '@/types/recipe-post';
import { toUserUI } from '@/lib/leaderboard';
import prisma from '@/lib/prisma';
import AppSettings from '@/lib/appsettings';

Expand All @@ -13,7 +14,7 @@ export async function POST(request: Request) {
}

try {
await prisma.post.update({
const post = await prisma.post.update({
where: {
id: data.id,
author: {
Expand All @@ -35,9 +36,16 @@ export async function POST(request: Request) {
date: data.date,
updated: new Date(),
},
include: {
author: {
include: {
posts: true,
},
},
},
});

return NextResponse.json({} as RecipePostResponse);
return NextResponse.json({ user: await toUserUI(post.author) } as RecipePostResponse);
} catch (err: any) {
console.error(err);
if (err.code === 'P2025') {
Expand Down

0 comments on commit 2ce9cc9

Please sign in to comment.