pub(super) async fn publish_draft_to_live(
    db: Data<PgPool>,
    claims: TokenUser,
    jig_id: Path<JigId>,
) -> Result<Json<<jig::Publish as ApiEndpoint>::Res>, error::JigCloneDraft> {
    let jig_id = jig_id.into_inner();

    db::jig::authz(&*db, claims.0.user_id, Some(jig_id)).await?;

    let mut txn = db.begin().await?;

    let (draft_id, live_id) = db::jig::get_draft_and_live_ids(&mut *txn, jig_id)
        .await
        .ok_or(error::JigCloneDraft::ResourceNotFound)?;

    let new_live_id = db::jig::clone_data(&mut txn, &draft_id).await?;

    sqlx::query!(
        //language=SQL
        "update jig set live_id = $1, published_at = now() where id = $2",
        new_live_id,
        jig_id.0
    )
    .execute(&mut *txn)
    .await?;

    // should drop all the entries in the metadata tables that FK to the live jig_data row
    sqlx::query!(
        //language=SQL
        r#"
delete from jig_data where id = $1
    "#,
        live_id,
    )
    .execute(&mut *txn)
    .await?;

    log::info!("AOSIJDOAIJSD");

    txn.commit().await?;

    Ok(Json(()))
}
/// Copies the contents of the draft jig data to live
Copies the contents of the draft jig data to live
Copies the contents of the draft jig data to live
pub(super) async fn publish_draft_to_live(
    db: Data<PgPool>,
    claims: TokenUser,
    jig_id: Path<JigId>,
) -> Result<Json<<jig::Publish as ApiEndpoint>::Res>, error::JigCloneDraft> {
    let jig_id = jig_id.into_inner();
    db::jig::authz(&*db, claims.0.user_id, Some(jig_id)).await?;
    let mut txn = db.begin().await?;
    let (draft_id, live_id) = db::jig::get_draft_and_live_ids(&mut *txn, jig_id)
        .await
        .ok_or(error::JigCloneDraft::ResourceNotFound)?;
    let new_live_id = db::jig::clone_data(&mut txn, &draft_id).await?;
    sqlx::query!(
        //language=SQL
        "update jig set live_id = $1, published_at = now() where id = $2",
        new_live_id,
        jig_id.0
    )
    .execute(&mut *txn)
    .await?;
    // should drop all the entries in the metadata tables that FK to the live jig_data row
    sqlx::query!(
        //language=SQL
        r#"
delete from jig_data where id = $1
    "#,
        live_id,
    )
    .execute(&mut *txn)
    .await?;
    log::info!("AOSIJDOAIJSD");
    txn.commit().await?;
    Ok(Json(()))
}
pub ( super ) async fn publish_draft_to_live ( db : Data < PgPool > , claims : TokenUser , jig_id : Path < JigId > , ) -> Result < Json < < jig :: Publish as ApiEndpoint > :: Res > , error :: JigCloneDraft > { let jig_id = jig_id . into_inner ( ) ; db :: jig :: authz ( & * db , claims . 0 . user_id , Some ( jig_id ) ) . await ? ; let mut txn = db . begin ( ) . await ? ; let ( draft_id , live_id ) = db :: jig :: get_draft_and_live_ids ( & mut * txn , jig_id ) . await . ok_or ( error :: JigCloneDraft :: ResourceNotFound ) ? ; let new_live_id = db :: jig :: clone_data ( & mut txn , & draft_id ) . await ? ; sqlx :: query ! ( //language=SQL " " new_live_id jig_id 0 ) . execute ( & mut * txn ) . await ? ; // should drop all the entries in the metadata tables that FK to the live jig_data row sqlx :: query ! ( //language=SQL r#"
delete from jig_data where id = $1
    "# live_id ) . execute ( & mut * txn ) . await ? ; log :: info ! ( " " ) ; txn . commit ( ) . await ? ; Ok ( Json ( ( ) ) ) }
Copies the contents of the draft jig data to live
Copies the contents of the draft jig data to live
db
Data<PgPool>
claims
TokenUser
jig_id
Path<JigId>
db
Data<PgPool>
claims
TokenUser
jig_id
Path<JigId>