fix: 🚑️ Fixed credits check at server creation & formatted prices nicely

This commit is contained in:
IceToast 2022-07-27 23:26:03 +02:00 committed by IceToast
parent e254b2acfe
commit 87ec49008d
No known key found for this signature in database
GPG key ID: 1464353E063A5B97
4 changed files with 21 additions and 11 deletions

View file

@ -91,7 +91,7 @@ class ChargeServers extends Command
}
// check if the server is canceled or if user has enough credits to charge the server or
if ( $server->cancelled || $user->credits < $product->price) {
if ( $server->cancelled || $user->credits <= $product->price) {
try {
// suspend server
$this->line("<fg=yellow>{$server->name}</> from user: <fg=blue>{$user->name}</> has been <fg=red>suspended!</>");

View file

@ -131,7 +131,8 @@ class ServerController extends Controller
Auth::user()->credits <
($product->minimum_credits == -1
? config('SETTINGS::USER:MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER', 50)
: $product->minimum_credits)
: $product->minimum_credits) ||
Auth::user()->credits <= $product->price
) {
return redirect()->route('servers.index')->with('error', 'You do not have the required amount of '.CREDITS_DISPLAY_NAME.' to use this product!');
}

View file

@ -188,7 +188,7 @@
@endif
</div>
<span>
{{ $server->product->price }}
{{ number_format($server->product->price) }}
</span>
</div>
</div>

View file

@ -239,14 +239,14 @@
<input type="hidden" name="product" x-model="selectedProduct">
</div>
<div>
<button type="submit" x-model="selectedProduct" name="product"
:disabled="product.minimum_credits > user.credits || product.doesNotFit == true ||
submitClicked"
:class="product.minimum_credits > user.credits || product.doesNotFit == true ||
submitClicked ? 'disabled' : ''"
class="btn btn-primary btn-block mt-2" @click="setProduct(product.id);"
x-text=" product.doesNotFit == true ? '{{ __('Server cant fit on this Node') }}' : (product.minimum_credits > user.credits ? '{{ __('Not enough') }} {{ CREDITS_DISPLAY_NAME }}!' : '{{ __('Create server') }}')">
</button>
<button type="submit" x-model="selectedProduct" name="product"
:disabled="product.minimum_credits > user.credits || product.price > user.credits || product.doesNotFit == true ||
submitClicked"
:class="product.minimum_credits > user.credits || product.price > user.credits || product.doesNotFit == true ||
submitClicked ? 'disabled' : ''"
class="btn btn-primary btn-block mt-2" @click="setProduct(product.id);"
x-text="product.doesNotFit == true ? '{{ __('Server cant fit on this Node') }}' : (product.minimum_credits > user.credits || product.price > user.credits ? '{{ __('Not enough') }} {{ CREDITS_DISPLAY_NAME }}!' : '{{ __('Create server') }}')">
</button>
</div>
</div>
</div>
@ -376,6 +376,7 @@
.catch(console.error)
this.fetchedProducts = true;
// TODO: Sortable by user chosen property (cpu, ram, disk...)
this.products = response.data.sort((p1, p2) => parseInt(p1.price, 10) > parseInt(p2.price, 10) &&
1 || -1)
@ -385,11 +386,19 @@
product.cpu = product.cpu / 100;
})
//format price to have no decimals if it is a whole number
this.products.forEach(product => {
if (product.price % 1 === 0) {
product.price = Math.round(product.price);
}
})
this.loading = false;
this.updateSelectedObjects()
},
/**
* @description map selected id's to selected objects
* @note being used in the server info box