add: don't allow free ProfileStyle products

This commit is contained in:
trisua 2025-08-10 16:04:21 -04:00
parent 7f0cb1f2a1
commit 59378a4447

View file

@ -213,7 +213,14 @@ pub async fn update_price_request(
None => return Json(Error::NotAllowed.into()), 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( return Json(
Error::MiscError( Error::MiscError(
"Price is too low, please use a price of 25 coins or more".to_string(), "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()); 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 { match data.update_product_method(id, &user, req.method).await {
Ok(_) => Json(ApiReturn { Ok(_) => Json(ApiReturn {
ok: true, ok: true,