Skip to content

Commit

Permalink
Fix rating issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken-Miura committed Dec 1, 2023
1 parent 19ede46 commit 01b9eb0
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ impl AwaitingWithdrawalOperation for AwaitingWithdrawalOperationImpl {
}
})?;

insert_user_rating(&ap, txn).await?;
insert_consultant_rating(&ap, txn).await?;

let id =
find_identity_by_user_account_id_in_transaction(txn, ap.user_account_id)
.await?;
Expand Down Expand Up @@ -148,6 +151,54 @@ impl AwaitingWithdrawalOperation for AwaitingWithdrawalOperationImpl {
}
}

async fn insert_user_rating(
ap: &entity::awaiting_payment::Model,
txn: &DatabaseTransaction,
) -> Result<(), ErrRespStruct> {
let ur = entity::user_rating::ActiveModel {
consultation_id: Set(ap.consultation_id),
user_account_id: Set(ap.user_account_id),
consultant_id: Set(ap.consultant_id),
meeting_at: Set(ap.meeting_at),
rating: Set(None),
rated_at: Set(None),
};
let _ = ur.insert(txn).await.map_err(|e| {
error!(
"failed to insert user_rating (awaiting_payment: {:?}): {}",
ap, e
);
ErrRespStruct {
err_resp: unexpected_err_resp(),
}
})?;
Ok(())
}

async fn insert_consultant_rating(
ap: &entity::awaiting_payment::Model,
txn: &DatabaseTransaction,
) -> Result<(), ErrRespStruct> {
let cr = entity::consultant_rating::ActiveModel {
consultation_id: Set(ap.consultation_id),
user_account_id: Set(ap.user_account_id),
consultant_id: Set(ap.consultant_id),
meeting_at: Set(ap.meeting_at),
rating: Set(None),
rated_at: Set(None),
};
let _ = cr.insert(txn).await.map_err(|e| {
error!(
"failed to insert consultant_rating (awaiting_payment: {:?}): {}",
ap, e
);
ErrRespStruct {
err_resp: unexpected_err_resp(),
}
})?;
Ok(())
}

async fn insert_awaiting_withdrawal(
ap: entity::awaiting_payment::Model,
sender_name: String,
Expand Down

0 comments on commit 01b9eb0

Please sign in to comment.