diff --git a/src/utils/messages.ts b/src/utils/messages.ts index 029ed1d..04f48c9 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -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.", }; diff --git a/src/v2/services/index.ts b/src/v2/services/index.ts index 017470f..5472ce5 100644 --- a/src/v2/services/index.ts +++ b/src/v2/services/index.ts @@ -14,6 +14,7 @@ import { getServicesOutputSchema, } from "./schemas"; import { ENDPOINT_MESSAGES } from "@/utils/messages"; +import { eq } from "drizzle-orm"; const app = new Hono(); @@ -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;