improved email throttle

This commit is contained in:
Denis Duliçi
2022-09-14 11:53:22 +03:00
parent bf2f83981c
commit eb3b080ee8
7 changed files with 92 additions and 41 deletions

View File

@ -7,9 +7,13 @@ use App\Models\Document\Document;
use App\Notifications\Sale\Invoice as Notification;
use App\Jobs\Document\SendDocumentAsCustomMail;
use App\Http\Requests\Common\CustomMail as Request;
use Illuminate\Http\JsonResponse;
use App\Traits\Emails;
class InvoiceEmails extends Controller
{
use Emails;
/**
* Instantiate a new controller instance.
*/
@ -22,14 +26,7 @@ class InvoiceEmails extends Controller
$this->middleware('permission:delete-sales-invoices')->only('destroy');
}
/**
* Show the form for creating a new resource.
*
* @param Document $invoice
*
* @return Response
*/
public function create(Document $invoice)
public function create(Document $invoice): JsonResponse
{
$notification = new Notification($invoice, 'invoice_new_customer', true);
@ -58,16 +55,9 @@ class InvoiceEmails extends Controller
]);
}
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @return Response
*/
public function store(Request $request)
public function store(Request $request): JsonResponse
{
$response = $this->ajaxDispatch(new SendDocumentAsCustomMail($request, 'invoice_new_customer'));
$response = $this->sendEmail(new SendDocumentAsCustomMail($request, 'invoice_new_customer'));
if ($response['success']) {
$invoice = Document::find($request->get('document_id'));

View File

@ -8,9 +8,13 @@ use App\Notifications\Portal\PaymentReceived as PaymentReceivedNotification;
use App\Notifications\Banking\Transaction as TransactionNotification;
use App\Jobs\Banking\SendTransactionAsCustomMail;
use App\Http\Requests\Common\CustomMail as Request;
use Illuminate\Http\JsonResponse;
use App\Traits\Emails;
class TransactionEmails extends Controller
{
use Emails;
/**
* Instantiate a new controller instance.
*/
@ -23,17 +27,10 @@ class TransactionEmails extends Controller
$this->middleware('permission:delete-banking-transactions')->only('destroy');
}
/**
* Show the form for creating a new resource.
*
* @param Transaction $transaction
*
* @return Response
*/
public function create(Transaction $transaction)
{
public function create(Transaction $transaction): JsonResponse
{
$email_template = config('type.transaction.' . $transaction->type . '.email_template');
if (request()->get('email_template')) {
$email_template = request()->get('email_template');
}
@ -42,7 +39,7 @@ class TransactionEmails extends Controller
case 'invoice_payment_customer':
$notification = new PaymentReceivedNotification($transaction->document, $transaction, $email_template, true);
break;
default:
$notification = new TransactionNotification($transaction, $email_template, true);
break;
@ -73,20 +70,13 @@ class TransactionEmails extends Controller
]);
}
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @return Response
*/
public function store(Request $request)
public function store(Request $request): JsonResponse
{
$transaction = Transaction::find($request->get('transaction_id'));
$email_template = config('type.transaction.' . $transaction->type . '.email_template');
$response = $this->ajaxDispatch(new SendTransactionAsCustomMail($request, $email_template));
$response = $this->sendEmail(new SendTransactionAsCustomMail($request, $email_template));
if ($response['success']) {
$route = config('type.transaction.' . $transaction->type . '.route.prefix');