wiki:CloneBuild

Version 2 (modified by 233051, 5 hours ago) ( diff )

--

Clone an existing build

Actors

User, Admin

Scenario

  1. The user opens the completed builds page, opens the details popup for a build
  2. The user clicks on the "CLONE & EDIT" button and is redirected to the forge page
  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
)
SELECT id
FROM new_build;

COMMIT;

Attachments (3)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.