Skip to content

Commit

Permalink
fix: More systems routes cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 committed Jan 30, 2025
1 parent 5191abd commit 955d855
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion apps/webservice/src/app/api/v1/systems/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const POST = request()
.returning()
.then(takeFirst)
.then((system) =>
NextResponse.json({ system }, { status: httpStatus.CREATED }),
NextResponse.json(system, { status: httpStatus.CREATED }),
)
.catch((error) => {
if (error instanceof z.ZodError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,30 @@ export const GET = request()
),
),
)
.handle<{ params: { workspaceSlug: string } }>(async (ctx) => {
try {
const workspace = await ctx.db
.select()
.from(SCHEMA.workspace)
.where(eq(SCHEMA.workspace.slug, ctx.params.workspaceSlug))
.then(takeFirstOrNull);
.handle<unknown, { params: { workspaceSlug: string } }>(
async ({ db }, { params: { workspaceSlug } }) => {
try {
const workspace = await db
.select()
.from(SCHEMA.workspace)
.where(eq(SCHEMA.workspace.slug, workspaceSlug))
.then(takeFirstOrNull);

if (workspace == null)
if (workspace == null)
return NextResponse.json(
{ error: "Workspace not found" },
{ status: httpStatus.NOT_FOUND },
);

return NextResponse.json(workspace, { status: httpStatus.OK });
} catch {
return NextResponse.json(
{ error: "Workspace not found" },
{ status: httpStatus.NOT_FOUND },
{
error:
"An error occurred while fetching the workspace, please contact support",
},
{ status: httpStatus.INTERNAL_SERVER_ERROR },
);

return NextResponse.json(workspace, { status: httpStatus.OK });
} catch {
return NextResponse.json(
{
error:
"An error occurred while fetching the workspace, please contact support",
},
{ status: httpStatus.INTERNAL_SERVER_ERROR },
);
}
});
}
},
);

0 comments on commit 955d855

Please sign in to comment.