-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to get all alerts of a customer to check if customer is subsc…
…ribed (#3)
- Loading branch information
Showing
8 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
yarn.lock | ||
/node_modules | ||
/vendor | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"@babel/runtime": "^7.14.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
document.addEventListener('turbolinks:load', () => { | ||
window.app.$on('logged-in', getAlerts); | ||
window.app.$on('alerts-updated', getAlerts); | ||
window.app.$on('logout', () => localStorage.removeItem('alerts')); | ||
|
||
async function getAlerts() { | ||
if (!localStorage.token) { | ||
return; | ||
} | ||
|
||
window.axios.defaults.headers.common['Authorization'] = `Bearer ${localStorage.token}`; | ||
await window.axios.post('/api/product-alerts').then((res) => localStorage.alerts = res.data) | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
use Rapidez\ProductAlert\Http\Controllers\AlertController; | ||
|
||
Route::prefix('api')->group(function() { | ||
Route::post('product-alerts', AlertController::class); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Rapidez\ProductAlert\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Routing\Controller; | ||
|
||
class AlertController extends Controller | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
abort_if(!$request->header('authorization'), 401); | ||
$customer = DB::table('oauth_token')->select('customer_id')->where('token', str_replace('Bearer ', '', $request->header('authorization')))->first(); | ||
abort_if(!$customer->customer_id, 401); | ||
$alerts = DB::table('product_alert_stock')->select('product_id')->where('customer_id', $customer->customer_id)->get(); | ||
|
||
return $alerts->pluck('product_id')->toJson() ?? []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters