Index: database/drizzle/queries/components.ts
===================================================================
--- database/drizzle/queries/components.ts	(revision 3216215c5b96d6664d987b0830db38f47f7db770)
+++ database/drizzle/queries/components.ts	(revision 1ac9ee4c292344780bd23707d9be69481891c46a)
@@ -896,132 +896,118 @@
 }
 
-export async function addComponentToBuild(db: Database, buildId: number, componentId: number) {
-    const [build] = await db
-        .select()
-        .from(buildsTable)
-        .where(
-            eq(buildsTable.id, buildId)
-        )
-        .limit(1);
-
-    if(!build) return null;
-
-    const [component] = await db
-        .select()
-        .from(componentsTable)
-        .where(
-            eq(componentsTable.id, componentId)
-        )
-        .limit(1);
-
-    if(!component) return null;
-
-    const existing = await db
-        .select()
-        .from(buildComponentsTable)
-        .where(
-            and(
-                eq(buildComponentsTable.buildId, buildId),
-                eq(buildComponentsTable.componentId, componentId)
-            )
-        )
-        .limit(1);
-
-    if(existing.length > 0) return null;
-
-    const [result] = await db
-        .insert(buildComponentsTable)
-        .values({
-            buildId,
-            componentId
-        })
-        .returning({
-            id: buildComponentsTable.buildId
-        });
-
-    const buildComponents = await db
-        .select({
-            price:  componentsTable.price,
-        })
-        .from(buildComponentsTable)
-        .innerJoin(
-            componentsTable,
-            eq(buildComponentsTable.componentId, componentsTable.id)
-        )
-        .where(
-            eq(buildComponentsTable.buildId, buildId)
-        );
-
-    const totalPrice = buildComponents.reduce((sum, c) => sum + Number(c.price), 0);
-
-     await db
-        .update(buildsTable)
-        .set({
-            totalPrice: totalPrice.toFixed(2)
-        })
-        .where(
-            eq(buildsTable.id, buildId)
-        );
-
-    return result?.id ?? null;
-}
-
-export async function removeComponentFromBuild(db: Database, buildId: number, componentId: number) {
-    const [build] = await db
-        .select()
-        .from(buildsTable)
-        .where(
-            eq(buildsTable.id, buildId)
-        )
-        .limit(1);
-
-    if(!build) return null;
-
-    const [component] = await db
-        .select()
-        .from(componentsTable)
-        .where(
-            eq(componentsTable.id, componentId)
-        )
-        .limit(1);
-
-    if(!component) return null;
-
-    const result = await db
-        .delete(buildComponentsTable)
-        .where(
-            and(
-                eq(buildComponentsTable.buildId, buildId),
-                eq(buildComponentsTable.componentId, componentId)
-            )
-        );
-
-    if(result.rowCount === 0) return null;
-
-    const buildComponents = await db
-        .select({
-            price:  componentsTable.price,
-        })
-        .from(buildComponentsTable)
-        .innerJoin(
-            componentsTable,
-            eq(buildComponentsTable.componentId, componentsTable.id)
-        )
-        .where(
-            eq(buildComponentsTable.buildId, buildId)
-        );
-
-    const totalPrice = buildComponents.reduce((sum, c) => sum + Number(c.price), 0);
-
-    await db
-        .update(buildsTable)
-        .set({
-            totalPrice: totalPrice.toFixed(2)
-        })
-        .where(
-            eq(buildsTable.id, buildId)
-        );
-
-    return result;
-}
-
+export async function addComponentToBuild(db: Database, userId: number, buildId: number, componentId: number) {
+    return db.transaction(async (tx) => {
+        const [build] = await tx
+            .select()
+            .from(buildsTable)
+            .where(
+                and(
+                    eq(buildsTable.id, buildId),
+                    eq(buildsTable.userId, userId)
+                )
+            )
+            .limit(1);
+
+        if(!build || build.isApproved) return null;
+
+        const existing = await tx
+            .select()
+            .from(buildComponentsTable)
+            .where(
+                and(
+                    eq(buildComponentsTable.buildId, buildId),
+                    eq(buildComponentsTable.componentId, componentId)
+                )
+            )
+            .limit(1);
+
+        if (existing.length) return null;
+
+        await tx
+            .insert(buildComponentsTable)
+            .values({
+                buildId,
+                componentId
+            });
+
+        const buildComponents = await tx
+            .select({
+                price:  componentsTable.price,
+            })
+            .from(buildComponentsTable)
+            .innerJoin(
+                componentsTable,
+                eq(buildComponentsTable.componentId, componentsTable.id)
+            )
+            .where(
+                eq(buildComponentsTable.buildId, buildId)
+            );
+
+        const totalPrice = buildComponents.reduce((sum, c) => sum + Number(c.price), 0);
+
+        await tx
+            .update(buildsTable)
+            .set({
+                totalPrice: totalPrice.toFixed(2)
+            })
+            .where(
+                eq(buildsTable.id, buildId)
+            );
+
+        return buildId;
+    })
+}
+
+export async function removeComponentFromBuild(db: Database, userId: number, buildId: number, componentId: number) {
+    return db.transaction(async (tx) => {
+        const [build] = await tx
+            .select()
+            .from(buildsTable)
+            .where(
+                and(
+                    eq(buildsTable.id, buildId),
+                    eq(buildsTable.userId, userId)
+                )
+            )
+            .limit(1);
+
+        if(!build || build.isApproved) return null;
+
+        const result = await tx
+            .delete(buildComponentsTable)
+            .where(
+                and(
+                    eq(buildComponentsTable.buildId, buildId),
+                    eq(buildComponentsTable.componentId, componentId)
+                )
+            );
+
+        if(result.rowCount === 0) return null;
+
+        const buildComponents = await tx
+            .select({
+                price:  componentsTable.price,
+            })
+            .from(buildComponentsTable)
+            .innerJoin(
+                componentsTable,
+                eq(buildComponentsTable.componentId, componentsTable.id)
+            )
+            .where(
+                eq(buildComponentsTable.buildId, buildId)
+            );
+
+        const totalPrice = buildComponents.reduce((sum, c) => sum + Number(c.price), 0);
+
+        await tx
+            .update(buildsTable)
+            .set({
+                totalPrice: totalPrice.toFixed(2)
+            })
+            .where(
+                eq(buildsTable.id, buildId)
+            );
+
+        return result;
+    })
+}
