Skip to content

Commit

Permalink
feat: disable service
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCassiere committed Jun 23, 2024
1 parent 04ee497 commit 2bd4321
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/utils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export const ENDPOINT_MESSAGES = {
ServiceIdHeaderNotProvided: "X-APP-SERVICE-ID header was not passed.",
ServiceDoesNotExistOrDoesNotHaveNecessaryRights: "Service does not exist or does not have necessary rights.",
DBWritesFrozen: "Database writes are currently frozen.",
ServiceCannotDisableSelf: "You cannot disable the service you are using.",
};
16 changes: 16 additions & 0 deletions src/v2/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getServicesOutputSchema,
} from "./schemas";
import { ENDPOINT_MESSAGES } from "@/utils/messages";
import { eq } from "drizzle-orm";

const app = new Hono<ServerContext>();

Expand Down Expand Up @@ -98,4 +99,19 @@ app.get("/:service_id", adminServiceValidation, async (c) => {
return c.json(getServiceOutputSchema.parse(service));
});

app.delete("/:service_id", adminServiceValidation, async (c) => {
const reqServiceId = c.var.service!.id;
const serviceId = c.req.param("service_id");

if (reqServiceId.trim() === serviceId.trim()) {
c.status(400);
return c.json({ success: false, message: ENDPOINT_MESSAGES.ServiceCannotDisableSelf });
}

await db.update(servicesTable).set({ isActive: false }).where(eq(servicesTable.id, serviceId)).execute();

c.status(200);
return c.json({ success: true, message: ENDPOINT_MESSAGES.ServiceDisabled });
});

export default app;

0 comments on commit 2bd4321

Please sign in to comment.