Skip to content

Commit

Permalink
feat: get service by id
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCassiere committed Jun 23, 2024
1 parent a281350 commit 04ee497
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/v2/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import {
createServiceInputSchema,
createServiceOutputSchema,
getServiceFiltersSchema,
getServiceOutputSchema,
getServicesOutputSchema,
} from "./schemas";
import { ENDPOINT_MESSAGES } from "@/utils/messages";

const app = new Hono<ServerContext>();

Expand Down Expand Up @@ -77,4 +79,23 @@ app.post("/", adminServiceValidation, async (c) => {
return c.json(createServiceOutputSchema.parse(service[0]));
});

/**
* @private
* Get a service by its ID, only accessible by admins
*/
app.get("/:service_id", adminServiceValidation, async (c) => {
const serviceId = c.req.param("service_id");

const service = await db.query.services.findFirst({
where: (fields, { and, eq }) => and(eq(fields.id, serviceId), eq(fields.isActive, true)),
});

if (!service) {
c.status(404);
return c.json({ success: false, message: ENDPOINT_MESSAGES.ServiceNotFound });
}

return c.json(getServiceOutputSchema.parse(service));
});

export default app;

0 comments on commit 04ee497

Please sign in to comment.