mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim.git
synced 2026-08-19 04:24:00 +00:00
large commit
This commit is contained in:
@@ -27,7 +27,7 @@ class CreateOrderLogic
|
||||
/**
|
||||
* @param int $companyId
|
||||
* @param Request $request
|
||||
* @return \App\Models\Order|null
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function execute(int $companyId, Request $request) {
|
||||
|
||||
@@ -6,8 +6,10 @@ namespace App\Classes\Modules\Orders\Services;
|
||||
use App\Classes\Constants;
|
||||
use App\Classes\Modules\Accounts\Exceptions\CannotCreateOrderException;
|
||||
use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
use App\Models\AddressBook;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class CreatesOrder
|
||||
{
|
||||
@@ -26,15 +28,19 @@ class CreatesOrder
|
||||
|
||||
/**
|
||||
* @param OrderObject $order
|
||||
* @return Order
|
||||
* @return JsonResponse
|
||||
* @throws CannotCreateOrderException
|
||||
*/
|
||||
public function execute(OrderObject $order): ?Order {
|
||||
public function execute(OrderObject $order) {
|
||||
|
||||
try {
|
||||
|
||||
$address = AddressBook::where('company_id', $order->getCompanyId())
|
||||
->where('default', true)->firstOrFail();
|
||||
->where('default', true)->first();
|
||||
|
||||
if(!$address){
|
||||
return new JsonResponse(['message' => 'Failed to create order because import\'s delivery address wasn\'t found'], HttpStatus::RESOURCE_NOT_FOUND);
|
||||
}
|
||||
|
||||
$this->repository->company_id = $order->getCompanyId();
|
||||
$this->repository->marking = $order->getOrderId();
|
||||
@@ -43,7 +49,7 @@ class CreatesOrder
|
||||
|
||||
$this->repository->save();
|
||||
|
||||
return $this->repository;
|
||||
return new JsonResponse(null, HttpStatus::RESOURCE_CREATED);
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new CannotCreateOrderException($exception->getMessage());
|
||||
|
||||
@@ -25,7 +25,7 @@ class AddressBook extends JsonResource
|
||||
'state' => $this->state,
|
||||
'post_code' => $this->post_code,
|
||||
'country' => $this->country,
|
||||
'default' => $this->default
|
||||
'default' => (int)$this->default
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ class CreatePackages extends Migration
|
||||
$table->integer('list_id')->unsigned()->index();
|
||||
$table->integer('type')->default(0);
|
||||
$table->string('description')->nullable();
|
||||
$table->decimal('width', 5, 3);
|
||||
$table->decimal('length', 5, 3);
|
||||
$table->decimal('height', 5, 3);
|
||||
$table->decimal('width', 7, 2);
|
||||
$table->decimal('length', 7, 2);
|
||||
$table->decimal('height', 7, 2);
|
||||
$table->integer('weight')->default(0);
|
||||
$table->integer('quantity');
|
||||
$table->timestamps();
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form method="post" @submit.prevent="addOrder">
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col no-padding">
|
||||
<div class="form-group form-group-default input-group">
|
||||
@@ -36,7 +36,7 @@
|
||||
<div class="row">
|
||||
<div class="col no-padding">
|
||||
<button class="btn b-rad-none btn-default" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" class="btn b-rad-none btn-primary">Create Order</button>
|
||||
<button type="button" class="btn b-rad-none btn-primary" @click="addOrder()" data-dismiss="modal">Create Order</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -93,30 +93,36 @@
|
||||
methods: {
|
||||
addOrder() {
|
||||
if($(this.$el).find('form').valid()) {
|
||||
|
||||
let notification = this.$refs.notification;
|
||||
//turn on loading animation
|
||||
this.isLoading = true;
|
||||
fetch(route('api.order.create', {companyId: this.data}), {
|
||||
method: 'post',
|
||||
responseType: 'json',
|
||||
body: JSON.stringify(this.order),
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
}
|
||||
}).then(() => {
|
||||
}).then(response => {
|
||||
this.clearForm();
|
||||
//turn off loading animation
|
||||
this.isLoading = false;
|
||||
if(!response.ok){ throw response }
|
||||
|
||||
let notification = this.$refs.notification;
|
||||
}).then( () => {
|
||||
notification.title = notificationConstant.ORDER.CREATED.TITLE;
|
||||
notification.message = notificationConstant.ORDER.CREATED.MESSAGE;
|
||||
|
||||
notification.execute();
|
||||
|
||||
$(this.$el).parents('.modal').modal('hide')
|
||||
|
||||
Event.$emit('updateOrdersList');
|
||||
|
||||
}).catch(error => {
|
||||
error.json().then( error => {
|
||||
notification.type = 'error';
|
||||
notification.title = notificationConstant.ORDER.CREATED.TITLE;
|
||||
notification.message = error.message;
|
||||
notification.execute();
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user