| | 1 | == Clone an existing build == |
| | 2 | |
| | 3 | === Actors === |
| | 4 | User, Admin |
| | 5 | |
| | 6 | === Scenario === |
| | 7 | 1. The user opens the completed builds page, opens the details popup for a build |
| | 8 | 2. The user clicks on the "CLONE & EDIT" button and is redirected to the forge page |
| | 9 | 3. The forge is populated with identical data as the build that was cloned |
| | 10 | |
| | 11 | {{{ |
| | 12 | BEGIN; |
| | 13 | |
| | 14 | SELECT * |
| | 15 | FROM build |
| | 16 | WHERE id = $buildId |
| | 17 | LIMIT 1; |
| | 18 | |
| | 19 | INSERT INTO build (user_id, name, created_at, description, total_price, is_approved) |
| | 20 | SELECT |
| | 21 | $userId, |
| | 22 | (b.name || ' (copy)'), |
| | 23 | CURRENT_DATE, |
| | 24 | b.description, |
| | 25 | b.total_price, |
| | 26 | false |
| | 27 | FROM build AS b |
| | 28 | WHERE b.id = $buildId |
| | 29 | RETURNING id; |
| | 30 | |
| | 31 | SELECT component_id |
| | 32 | FROM build_component |
| | 33 | WHERE build_id = $buildId; |
| | 34 | |
| | 35 | INSERT INTO build_component (build_id, component_id) |
| | 36 | SELECT |
| | 37 | $newBuildId, |
| | 38 | bc.component_id |
| | 39 | FROM build_component AS bc |
| | 40 | WHERE bc.build_id = $buildId; |
| | 41 | |
| | 42 | COMMIT; |
| | 43 | }}} |