fix image attachment bug (#1405)
This commit is contained in:
committed by
GitHub
parent
18637ab3e1
commit
edc532c028
@@ -177,36 +177,6 @@ impl Image {
|
||||
}
|
||||
|
||||
impl TaskImage {
|
||||
pub async fn create(pool: &SqlitePool, data: &CreateTaskImage) -> Result<Self, sqlx::Error> {
|
||||
let id = Uuid::new_v4();
|
||||
sqlx::query_as!(
|
||||
TaskImage,
|
||||
r#"INSERT INTO task_images (id, task_id, image_id)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id as "id!: Uuid",
|
||||
task_id as "task_id!: Uuid",
|
||||
image_id as "image_id!: Uuid",
|
||||
created_at as "created_at!: DateTime<Utc>""#,
|
||||
id,
|
||||
data.task_id,
|
||||
data.image_id,
|
||||
)
|
||||
.fetch_one(pool)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn associate_many(
|
||||
pool: &SqlitePool,
|
||||
task_id: Uuid,
|
||||
image_ids: &[Uuid],
|
||||
) -> Result<(), sqlx::Error> {
|
||||
for &image_id in image_ids {
|
||||
let task_image = CreateTaskImage { task_id, image_id };
|
||||
TaskImage::create(pool, &task_image).await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Associate multiple images with a task, skipping duplicates.
|
||||
pub async fn associate_many_dedup(
|
||||
pool: &SqlitePool,
|
||||
|
||||
@@ -151,7 +151,7 @@ pub async fn create_task_and_start(
|
||||
let task = Task::create(&deployment.db().pool, &payload.task, task_id).await?;
|
||||
|
||||
if let Some(image_ids) = &payload.task.image_ids {
|
||||
TaskImage::associate_many(&deployment.db().pool, task.id, image_ids).await?;
|
||||
TaskImage::associate_many_dedup(&deployment.db().pool, task.id, image_ids).await?;
|
||||
}
|
||||
|
||||
deployment
|
||||
|
||||
Reference in New Issue
Block a user