diff --git a/app/components/equipment/AddEquipmentForm.vue b/app/components/equipment/AddEquipmentForm.vue index beaa519..2cf10c2 100644 --- a/app/components/equipment/AddEquipmentForm.vue +++ b/app/components/equipment/AddEquipmentForm.vue @@ -22,7 +22,6 @@ diff --git a/server/api/equipment/items/[itemId]/index.delete.ts b/server/api/equipment/items/[itemId]/index.delete.ts new file mode 100644 index 0000000..4fb3e9b --- /dev/null +++ b/server/api/equipment/items/[itemId]/index.delete.ts @@ -0,0 +1,34 @@ +import { eq } from 'drizzle-orm' +import * as v from 'valibot' + +const paramsSchema = v.object({ + itemId: stringToIntegerValidator +}) + +function validateParams(params: unknown) { + return v.parse(paramsSchema, params) +} + +export default defineEventHandler(async (event) => { + await validateAdmin(event) + + const { itemId } = await getValidatedRouterParams(event, validateParams) + + const deleted = await event.context.db + .delete(tables.equipment) + .where( + eq(tables.equipment.id, itemId) + ) + .returning({ + id: tables.equipment.id + }) + + if (deleted.length === 0) { + throw createError({ + statusCode: 404, + message: `Item with ID ${itemId} not found` + }) + } + + setResponseStatus(event, 204) +}) diff --git a/server/api/equipment/items/[itemId].get.ts b/server/api/equipment/items/[itemId]/index.get.ts similarity index 100% rename from server/api/equipment/items/[itemId].get.ts rename to server/api/equipment/items/[itemId]/index.get.ts diff --git a/server/api/equipment/items/[itemId].patch.ts b/server/api/equipment/items/[itemId]/index.patch.ts similarity index 100% rename from server/api/equipment/items/[itemId].patch.ts rename to server/api/equipment/items/[itemId]/index.patch.ts