Update api endpoints for new association

This commit is contained in:
Owen 2025-03-31 16:21:01 -04:00
parent 1baa02de89
commit 56e1684e2e
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD
7 changed files with 172 additions and 133 deletions

View file

@ -1,7 +1,7 @@
import { Request, Response, NextFunction } from "express";
import { z } from "zod";
import { db } from "@server/db";
import { clients, sites } from "@server/db/schema";
import { clients, clientSites } from "@server/db/schema";
import { eq } from "drizzle-orm";
import response from "@server/lib/response";
import HttpCode from "@server/types/HttpCode";
@ -48,7 +48,17 @@ export async function deleteClient(
);
}
await db.delete(clients).where(eq(clients.clientId, clientId));
await db.transaction(async (trx) => {
// Delete the client-site associations first
await trx
.delete(clientSites)
.where(eq(clientSites.clientId, clientId));
// Then delete the client itself
await trx
.delete(clients)
.where(eq(clients.clientId, clientId));
});
return response(res, {
data: null,
@ -63,4 +73,4 @@ export async function deleteClient(
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
);
}
}
}