funcion/pedido-ollas #47
3 changed files with 18 additions and 8 deletions
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api;
|
|||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Producto;
|
||||
use App\TipoPedido;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Filtros\FiltroDeSubpedido;
|
||||
use App\Subpedido;
|
||||
|
@ -28,12 +29,19 @@ class SubpedidoController extends Controller
|
|||
public function store(Request $request)
|
||||
{
|
||||
$validado = $this->validateSubpedido();
|
||||
if (Subpedido::where("nombre",$validado["nombre"])->where("grupo_de_compra_id",$validado["grupo_de_compra_id"])->get()->count()) {
|
||||
|
||||
if (Subpedido::where("nombre", $validado["nombre"])
|
||||
->where("grupo_de_compra_id", $validado["grupo_de_compra_id"])
|
||||
->get()
|
||||
->count()
|
||||
) {
|
||||
throw new HttpException(400, "Ya existe un subpedido con este nombre");
|
||||
}
|
||||
|
||||
$s = new Subpedido();
|
||||
$s->nombre = $validado["nombre"];
|
||||
$s->grupo_de_compra_id = $validado["grupo_de_compra_id"];
|
||||
$s->tipo_pedido_id = $validado["tipo_id"];
|
||||
$s->save();
|
||||
return $this->show($s);
|
||||
}
|
||||
|
@ -45,7 +53,11 @@ class SubpedidoController extends Controller
|
|||
'grupo_de_compra_id' => [
|
||||
'required',
|
||||
Rule::in(GrupoDeCompra::all()->pluck('id')),
|
||||
]
|
||||
],
|
||||
'tipo_id' => [
|
||||
'required',
|
||||
Rule::in(TipoPedido::all()->pluck('id')),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,8 @@ export default {
|
|||
else
|
||||
await this.crearPedido({
|
||||
nombre: this.searchString,
|
||||
grupo_de_compra_id: this.grupo_de_compra.id
|
||||
grupo_de_compra_id: this.grupo_de_compra.id,
|
||||
tipo_id: 1,
|
||||
});
|
||||
},
|
||||
}
|
||||
|
|
7
resources/js/store/modules/pedido.js
vendored
7
resources/js/store/modules/pedido.js
vendored
|
@ -55,11 +55,8 @@ const actions = {
|
|||
async guardarSesion(_, { pedido_id }) {
|
||||
await axios.post("/pedido/sesion", { id: pedido_id });
|
||||
},
|
||||
async crearPedido({ commit, dispatch }, { nombre, grupo_de_compra_id }) {
|
||||
const response = await axios.post("/api/subpedidos", {
|
||||
nombre: nombre,
|
||||
grupo_de_compra_id: grupo_de_compra_id
|
||||
});
|
||||
async crearPedido({ commit, dispatch }, req) {
|
||||
const response = await axios.post("/api/subpedidos", req);
|
||||
dispatch("guardarSesion", { pedido_id: response.data.data.id});
|
||||
commit('setPedido', response.data.data);
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue