tak e off sale

This commit is contained in:
xander 2022-04-04 12:20:27 -12:00
parent ae22ea9d5f
commit a047f5701b
3 changed files with 57 additions and 1 deletions

View File

@ -84,6 +84,7 @@ class CatalogController extends Controller
foreach ($replies as &$reply) {
$creator = User::where('id', $reply['seller_id'])->first();
if ($creator->id == $user->id) {$reply['isMeta'] = true;}else{$reply['isMeta'] = false;}
$reply['created_at'] = explode('T', $reply['created_at'])[0];
$reply['seller_name'] = $creator->username;
}
@ -118,6 +119,7 @@ class CatalogController extends Controller
foreach ($replies as &$reply) {
$creator = User::where('id', $reply['seller_id'])->first();
if ($creator->id == $user->id) {$reply['isMeta'] = true;}else{$reply['isMeta'] = false;}
$reply['created_at'] = explode('T', $reply['created_at'])[0];
$reply['seller_name'] = $creator->username;
}
@ -178,6 +180,7 @@ class CatalogController extends Controller
foreach ($replies as &$reply) {
$creator = User::where('id', $reply['seller_id'])->first();
if ($creator->id == $user->id) {$reply['isMeta'] = true;}else{$reply['isMeta'] = false;}
$reply['created_at'] = explode('T', $reply['created_at'])[0];
$reply['seller_name'] = $creator->username;
}
@ -235,6 +238,42 @@ class CatalogController extends Controller
foreach ($replies as &$reply) {
$creator = User::where('id', $reply['seller_id'])->first();
if ($creator->id == $user->id) {$reply['isMeta'] = true;}else{$reply['isMeta'] = false;}
$reply['created_at'] = explode('T', $reply['created_at'])[0];
$reply['seller_name'] = $creator->username;
}
return Response()->json(['message'=>"Success!", 'badInputs'=>[], "item"=>$itemA, "sellingPrices"=>$replies]);
}
public function removeSale(Request $request, $id) {
$user = AuthHelper::GetCurrentUser($request);
if (!$user) return Response()->json(['message'=>'System Error', 'badInputs'=>['title']]);
$sellingId = $id;
$sellingItem = Selling::whereId($sellingId)->first();
if (!$sellingItem) return Response()->json(['message'=>"That selling item doesn't exist!", 'badInputs'=>['title']]);
if ($sellingItem->seller_id != $user->id) return Response()->json(['message'=>"Thats not you!", 'badInputs'=>['title']]);
$sellingItem->delete();
if (count($item->sellingPrices) <= 0) {$item->current_price = null;$item->save();}else{$item->current_price = $sellingItemNew->price;$item->save();}
$replies = $item->sellingPrices()->orderBy('price', 'asc')->paginate(10);
$itemA = $item->toArray();
$itemA['creator'] = User::where('id', $item->creator_id)->first();
foreach ($replies as &$reply) {
$creator = User::where('id', $reply['seller_id'])->first();
if ($creator->id == $user->id) {$reply['isMeta'] = true;}else{$reply['isMeta'] = false;}
$reply['created_at'] = explode('T', $reply['created_at'])[0];
$reply['seller_name'] = $creator->username;
}

View File

@ -39,6 +39,21 @@ const Item = (props) => {
}).catch(error=>{console.log(error);});
}
const removeSale = async (saleId) => {
setState({...state, loading: true});
const body = new FormData();
await axios.post(`${protocol}apis.${url}/api/catalog/remove/sale/${saleId}`, body, {headers: {"X-Requested-With":"XMLHttpRequest"}}).then(data=>{
setState({...state, loading: false});
const res = data.data;
if (res.badInputs.length >= 1) {
setValidity({error: true, message:res.message, inputs: res.badInputs});
setTimeout(()=>{setValidity({...validity, error: false, inputs: res.badInputs});}, 4000);
}else{
setPost({item: res.item, sellingPrices: {...item.sellingPrices, sellingPrices: res.sellingPrices.data, meta: res.sellingPrices}});
}
}).catch(error=>{console.log(error);});
}
const buyItem = async (decision, isSelling, sellingId) => {
setState({...state, loading: true});
const body = new FormData();
@ -177,7 +192,7 @@ const Item = (props) => {
<div className={`flex flex-column flex alc jcc`}>
<p>Price: ${reply.price}</p>
<p>Item UID: {reply.uid}</p>
<button className={`btn btn-success w-fit-content`} onClick={(e)=>{buyItem(`selling`, true, reply.id);}}>Buy</button>
{!reply.isMeta? <button className={`btn btn-success w-fit-content`} onClick={(e)=>{buyItem(`selling`, true, reply.id);}}>Buy</button> : <button className={`btn btn-danger w-fit-content`} onClick={(e)=>{removeSale(reply.id);}}>Take off Sale</button>}
</div>
</div>
</div>

View File

@ -70,6 +70,8 @@ Route::post('/api/catalog/buy/{id}', 'CatalogController@buy');
Route::post('/api/catalog/sell/{id}', 'CatalogController@sell');
Route::post('/api/catalog/remove/sale/{id}', 'CatalogController@removeSale');
Route::post('/api/change/user/about', 'SettingsController@settingsAbout');
Route::post('/api/change/user/password', 'SettingsController@settingsPassword');