From 59378a44476c072a267a751f788c6a1b87480ba1 Mon Sep 17 00:00:00 2001 From: trisua Date: Sun, 10 Aug 2025 16:04:21 -0400 Subject: [PATCH] add: don't allow free ProfileStyle products --- crates/app/src/routes/api/v1/products.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/app/src/routes/api/v1/products.rs b/crates/app/src/routes/api/v1/products.rs index 03e319c..c9eef1a 100644 --- a/crates/app/src/routes/api/v1/products.rs +++ b/crates/app/src/routes/api/v1/products.rs @@ -213,7 +213,14 @@ pub async fn update_price_request( None => return Json(Error::NotAllowed.into()), }; - if req.price < 25 && req.price != 0 { + let product = match data.get_product_by_id(id).await { + Ok(x) => x, + Err(e) => return Json(e.into()), + }; + + let can_be_free = product.method != ProductFulfillmentMethod::ProfileStyle; + + if req.price < 25 && (!can_be_free || req.price != 0) { return Json( Error::MiscError( "Price is too low, please use a price of 25 coins or more".to_string(), @@ -250,6 +257,18 @@ pub async fn update_method_request( return Json(Error::RequiresSupporter.into()); } + let product = match data.get_product_by_id(id).await { + Ok(x) => x, + Err(e) => return Json(e.into()), + }; + + if req.method == ProductFulfillmentMethod::ProfileStyle && product.price == 0 { + // no free profile styles + if let Err(e) = data.update_product_price(id, &user, 25).await { + return Json(e.into()); + } + } + match data.update_product_method(id, &user, req.method).await { Ok(_) => Json(ApiReturn { ok: true,