You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: backend/src/db/mod.rs
+19Lines changed: 19 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -95,6 +95,7 @@ impl Database {
95
95
/// - Sets the `filelink` to:
96
96
/// - For library papers, remains unchanged
97
97
/// - For uploaded papers, approved papers are moved to the approved directory and renamed `id_coursecode_coursename_year_semester_exam.pdf` and unapproved papers are moved to the unapproved directory and named `id.pdf`
98
+
/// - Deletes `replace` papers from the database.
98
99
///
99
100
/// Returns the database transaction, the old filelink and the new paper details ([`crate::qp::AdminDashboardQP`])
100
101
pubasyncfnedit_paper<'c>(
@@ -113,6 +114,7 @@ impl Database {
113
114
exam,
114
115
approve_status,
115
116
note,
117
+
replace,
116
118
} = edit_req;
117
119
118
120
let current_details = self.get_paper_by_id(id).await?;
@@ -177,6 +179,23 @@ impl Database {
177
179
let new_qp:DBAdminDashboardQP = query.fetch_one(&mut*tx).await?;
178
180
let new_qp = AdminDashboardQP::from(new_qp);
179
181
182
+
// Delete the replaced papers
183
+
for replace_id in replace {
184
+
let rows_affected = sqlx::query(queries::SOFT_DELETE_ANY_BY_ID)
185
+
.bind(replace_id)
186
+
.execute(&mut*tx)
187
+
.await?
188
+
.rows_affected();
189
+
190
+
if rows_affected > 1{
191
+
tx.rollback().await?;
192
+
returnErr(eyre!(
193
+
"Error: {} (> 1) papers were deleted. Rolling back.",
0 commit comments