== Clone an existing build == === Actors === User, Admin === Scenario === 1. The user opens the completed builds page, opens the details popup for a build [[Image(clickClone.png, width=800, height=420)]] 2. The user clicks on the "CLONE & EDIT" button and is redirected to the forge page [[Image(clone.png, width=800, height=420)]] 3. The forge is populated with identical data as the build that was cloned {{{ BEGIN; WITH build_to_clone AS ( SELECT name, description, total_price FROM build WHERE id = $buildId LIMIT 1 ), new_build AS ( INSERT INTO build (user_id, name, created_at, description, total_price, is_approved) SELECT $userId, build_to_clone.name || ' (copy)', CURRENT_DATE, build_to_clone.description, build_to_clone.total_price, false FROM build_to_clone RETURNING id ), copied_components AS ( INSERT INTO build_component (build_id, component_id) SELECT new_build.id, bc.component_id FROM new_build JOIN build_component AS bc ON bc.build_id = $buildId RETURNING 1 ) COMMIT; }}} {{{ BEGIN; SELECT b.id, b.user_id, b.is_approved, b.name, b.description, b.total_price, FROM builds b WHERE b.id = $1 AND b.user_id = $2 LIMIT 1; SELECT bc.component_id FROM build_components bc WHERE bc.build_id = $1; COMMIT; }}} [[Image(clonedBuild.png, width=800, height=420)]]