additional info about request

This commit is contained in:
saparatayev 2022-01-25 17:14:57 +05:00
parent 142f1dddb5
commit 81fb6aa533
4 changed files with 88 additions and 9 deletions

View File

@ -42,6 +42,10 @@ class RequestController extends Controller
'phone' => ['required'],
'password' => ['required'],
'dial_code' => ['required'],
'first_name' => ['required'],
'last_name' => ['required'],
'email' => ['required', 'email'],
'org_type' => ['required'],
'items' => ['required', 'array'],
'items.*.id' => ['required'],
'totalPrice' => ['required', 'numeric'],
@ -73,16 +77,26 @@ class RequestController extends Controller
break;
case 200:
// try to withdraw from the balance
// check user balance
$fee = $input['totalPrice'];
if($input['currency'] == 'USD') {
$fee = $fee * settings('local_price') / settings('int_price');
}
if($loginResponse['user']['user_balance'] - $fee < 0) {
return response()->json([
'status' => 300, // 300
'message' => 'Fill up your balance 2',
'response' => $loginResponse
], 300);
}
// try to withdraw fee from the balance for creating a request
$balanceResponse = Http::post('http://127.0.0.1:8000/api/v1/withdraw-from-balance?token=' . $loginResponse['token'] . '&total_price=' . $input['totalPrice'] . '&currency=' . $input['currency']);
$balanceResponseStatus = $balanceResponse->status();
if($balanceResponseStatus == 201) {
RequestModel::create(array_merge($input, [
'name' => $loginResponse['user']['name'] . $loginResponse['user']['surname'],
'email' => $loginResponse['user']['email']
]));
RequestModel::create($input);
}
if($balanceResponseStatus == 500) {
@ -95,7 +109,7 @@ class RequestController extends Controller
}
return response()->json([
'status' => $balanceResponseStatus, // 201 (ok) or 300 (fill up balance)
'status' => $balanceResponseStatus, // 201 (ok)
'message' => $balanceResponse['message'],
'response' => $balanceResponse
], $balanceResponseStatus);

View File

@ -14,6 +14,16 @@ class RequestResource extends JsonResource
*/
public function toArray($request)
{
return parent::toArray($request);
// return parent::toArray($request);
return [
'id' => $this->id,
'name' => $this->first_name . ' ' . $this->last_name,
'email' => $this->email,
'phone' => $this->phone,
'org_type' => $this->org_type,
'items' => $this->items,
'created_at' => $this->created_at->format('d.m.Y (h:i)'),
'updated_at' => $this->updated_at,
];
}
}

View File

@ -15,9 +15,11 @@ class CreateRequestsTable extends Migration
{
Schema::create('requests', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('first_name');
$table->string('last_name');
$table->string('email');
$table->string('phone');
$table->string('org_type');
$table->json('items');
$table->timestamps();
});

View File

@ -45,8 +45,54 @@
</template>
</a-form-item>
</div>
<div class="w-2/12"></div>
<!-- Warning text -->
<div class="w-4/12">
<p>You have to be resgistered and have enough money no your balance to make a request</p>
<p>Not Registered? <a href="#" class="font-bold text-primary">Click here</a></p>
</div>
<!-- Warning text end -->
</div>
<!-- Additional info for creating a request -->
<div class="flex space-x-3 border-t pt-4 border-gray-300">
<div class="w-8/12">
<a-form-item
:label="'First name'"
>
<a-input v-model="form.first_name" :placeholder="'First name'" />
<template v-if="validationErrorsObj.first_name">
<span class="validation-error" v-for="item in validationErrorsObj.first_name" :key="item">{{ item }}</span>
</template>
</a-form-item>
<a-form-item
:label="'Last name'"
>
<a-input v-model="form.last_name" :placeholder="'Last name'" />
<template v-if="validationErrorsObj.last_name">
<span class="validation-error" v-for="item in validationErrorsObj.last_name" :key="item">{{ item }}</span>
</template>
</a-form-item>
<a-form-item
:label="trans('Email')"
>
<a-input v-model="form.email" :placeholder="trans('Email')" />
<template v-if="validationErrorsObj.email">
<span class="validation-error" v-for="item in validationErrorsObj.email" :key="item">{{ item }}</span>
</template>
</a-form-item>
<a-form-item
:label="'Organization type'"
>
<a-input v-model="form.org_type" :placeholder="'Organization type'" />
<template v-if="validationErrorsObj.org_type">
<span class="validation-error" v-for="item in validationErrorsObj.org_type" :key="item">{{ item }}</span>
</template>
</a-form-item>
</div>
</div>
<!-- Additional info for creating a request -->
<div
class="flex relative space-x-3"
v-for="(item, index) in form.items"
@ -122,6 +168,10 @@ export default {
form: this.$inertia.form({
phone: undefined,
password: undefined,
first_name: undefined,
last_name: undefined,
email: undefined,
org_type: undefined,
// captcha: undefined,
items: [
{
@ -269,4 +319,7 @@ export default {
.vue-country-select .dropdown-item.last-preferred {
border-bottom: 1px solid #004691 !important;
}
.ant-form-item label {
white-space: pre-wrap;
}
</style>