Fix review response typing and usage date rendering
This commit is contained in:
parent
a7c7c08f44
commit
474e7f9cda
2 changed files with 30 additions and 26 deletions
|
|
@ -267,20 +267,20 @@ export async function POST(
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
let review: {
|
const review = await prisma.$transaction(async (tx) => {
|
||||||
id: string;
|
let updatedReview: {
|
||||||
title: string | null;
|
id: string;
|
||||||
content: string;
|
title: string | null;
|
||||||
rating: number;
|
content: string;
|
||||||
helpfulCount: number;
|
rating: number;
|
||||||
createdAt: Date;
|
helpfulCount: number;
|
||||||
updatedAt: Date;
|
createdAt: Date;
|
||||||
user: { id: string; name: string | null; image: string | null; username: string | null };
|
updatedAt: Date;
|
||||||
} | null = null;
|
user: { id: string; name: string | null; image: string | null; username: string | null };
|
||||||
await prisma.$transaction(async (tx) => {
|
};
|
||||||
if (existingReview) {
|
if (existingReview) {
|
||||||
// Update existing review
|
// Update existing review
|
||||||
review = await tx.toolReview.update({
|
updatedReview = await tx.toolReview.update({
|
||||||
where: { id: existingReview.id },
|
where: { id: existingReview.id },
|
||||||
data: {
|
data: {
|
||||||
title: title?.trim() || null,
|
title: title?.trim() || null,
|
||||||
|
|
@ -300,7 +300,7 @@ export async function POST(
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Create new review
|
// Create new review
|
||||||
review = await tx.toolReview.create({
|
updatedReview = await tx.toolReview.create({
|
||||||
data: {
|
data: {
|
||||||
userId: session.user.id,
|
userId: session.user.id,
|
||||||
toolId: id,
|
toolId: id,
|
||||||
|
|
@ -359,23 +359,25 @@ export async function POST(
|
||||||
ratingCount: aggregates._count.rating,
|
ratingCount: aggregates._count.rating,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return updatedReview;
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
data: {
|
data: {
|
||||||
id: review?.id,
|
id: review.id,
|
||||||
title: review?.title,
|
title: review.title,
|
||||||
content: review?.content,
|
content: review.content,
|
||||||
rating: review?.rating,
|
rating: review.rating,
|
||||||
helpfulCount: review?.helpfulCount,
|
helpfulCount: review.helpfulCount,
|
||||||
createdAt: review?.createdAt.toISOString(),
|
createdAt: review.createdAt.toISOString(),
|
||||||
updatedAt: review?.updatedAt.toISOString(),
|
updatedAt: review.updatedAt.toISOString(),
|
||||||
user: {
|
user: {
|
||||||
id: review?.user.id,
|
id: review.user.id,
|
||||||
name: review?.user.name,
|
name: review.user.name,
|
||||||
image: review?.user.image,
|
image: review.user.image,
|
||||||
username: review?.user.username,
|
username: review.user.username,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
meta: { version: API_VERSION, timestamp: new Date().toISOString(), requestId },
|
meta: { version: API_VERSION, timestamp: new Date().toISOString(), requestId },
|
||||||
|
|
|
||||||
|
|
@ -244,8 +244,10 @@ export default function UsagePage(): React.ReactElement {
|
||||||
new Date(data.timeSeries[0].periodStart).toLocaleDateString()}
|
new Date(data.timeSeries[0].periodStart).toLocaleDateString()}
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
{data.timeSeries.at(-1)?.periodStart &&
|
{(() => {
|
||||||
new Date(data.timeSeries.at(-1)?.periodStart).toLocaleDateString()}
|
const lastPeriodStart = data.timeSeries.at(-1)?.periodStart;
|
||||||
|
return lastPeriodStart ? new Date(lastPeriodStart).toLocaleDateString() : null;
|
||||||
|
})()}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue