fix migration and api changes

This commit is contained in:
yogesh-gohil
2023-03-14 17:45:58 +05:30
parent aede1f76d0
commit 2bea727d19
4 changed files with 46 additions and 61 deletions

View File

@ -25,11 +25,6 @@ class MailSender extends Model
return $this->belongsTo(Company::class);
}
public function setSettingsAttribute($value)
{
$this->attributes['settings'] = json_encode($value);
}
public function scopeWhereOrder($query, $orderByField, $orderBy)
{
$query->orderBy($orderByField, $orderBy);

View File

@ -32,17 +32,10 @@ class CreateMailSendersTable extends Migration
$table->timestamps();
});
$user = User::where('role', 'super admin')->first();
if ($user) {
$users = User::where('role', 'super admin')->get();
foreach ($users as $user) {
$user->allow('view-mail-sender');
$user->allow('create-mail-sender');
$user->allow('edit-mail-sender');
$user->allow('delete-mail-sender');
BouncerFacade::allow($user)->toOwn(MailSender::class);
BouncerFacade::allow($user)->toManage(MailSender::class);
}
$companies = Company::all();
@ -56,11 +49,11 @@ class CreateMailSendersTable extends Migration
'MAIL_PASSWORD' => env('MAIL_PASSWORD'),
'MAIL_ENCRYPTION' => env('MAIL_ENCRYPTION')
];
$this->insertData($settings, $company->id);
$this->createSender($settings, $company->id);
}
if (env('MAIL_DRIVER') == 'mail' || env('MAIL_DRIVER') == 'sendmail') {
$this->insertData(null, $company->id);
$this->createSender(null, $company->id);
}
if (env('MAIL_DRIVER') == 'mailgun') {
@ -69,7 +62,7 @@ class CreateMailSendersTable extends Migration
'MAILGUN_SECRET' => env('MAILGUN_SECRET'),
'MAILGUN_ENDPOINT' => env('MAILGUN_ENDPOINT'),
];
$this->insertData($settings, $company->id);
$this->createSender($settings, $company->id);
}
if (env('MAIL_DRIVER') == 'ses') {
@ -81,13 +74,12 @@ class CreateMailSendersTable extends Migration
'SES_KEY' => env('SES_KEY'),
'SES_SECRET' => env('SES_SECRET'),
];
$this->insertData($settings, $company->id);
$this->createSender($settings, $company->id);
}
});
}
}
public function insertData($settings, $company_id)
public function createSender($settings, $company_id)
{
$data = [
'name' => env('MAIL_DRIVER'),

View File

@ -68,7 +68,7 @@ export const useMailSenderStore = (useWindow = false) => {
fetchMailSenders(params) {
return new Promise((resolve, reject) => {
axios
.get(`/api/v1/mail-sender`, { params })
.get(`/api/v1/mail-senders`, { params })
.then((response) => {
this.mailSenders = response.data.data
resolve(response)
@ -83,7 +83,7 @@ export const useMailSenderStore = (useWindow = false) => {
fetchMailSender(id) {
return new Promise((resolve, reject) => {
axios
.get(`/api/v1/mail-sender/${id}`)
.get(`/api/v1/mail-senders/${id}`)
.then((response) => {
this.currentMailSender = response.data.data
if (response.data.data.settings) {
@ -116,7 +116,7 @@ export const useMailSenderStore = (useWindow = false) => {
const notificationStore = useNotificationStore()
return new Promise((resolve, reject) => {
axios
.post('/api/v1/mail-sender', data)
.post('/api/v1/mail-senders', data)
.then((response) => {
this.mailSenders.push(response.data.data)
notificationStore.showNotification({
@ -136,7 +136,7 @@ export const useMailSenderStore = (useWindow = false) => {
const notificationStore = useNotificationStore()
return new Promise((resolve, reject) => {
axios
.put(`/api/v1/mail-sender/${data.id}`, data)
.put(`/api/v1/mail-senders/${data.id}`, data)
.then((response) => {
if (response.data) {
let pos = this.mailSenders.findIndex(
@ -160,7 +160,7 @@ export const useMailSenderStore = (useWindow = false) => {
deleteMailSender(id) {
return new Promise((resolve, reject) => {
axios
.delete(`/api/v1/mail-sender/${id}`)
.delete(`/api/v1/mail-senders/${id}`)
.then((response) => {
if (response.data.success) {
let index = this.mailSenders.findIndex(

View File

@ -403,14 +403,12 @@ Route::prefix('/v1')->group(function () {
// Mails
//----------------------------------
Route::apiResource('mail-sender', MailSenderController::class);
Route::apiResource('mail-senders', MailSenderController::class);
Route::get('/mail-drivers', [MailConfigurationController::class, 'getMailDrivers']);
Route::post('/mail-test', [MailConfigurationController::class, 'TestMailDriver']);
Route::get('mail-senders', GetAllMailSendersController::class);
Route::get('/company/mail/config', GetCompanyMailConfigurationController::class);
Route::apiResource('notes', NotesController::class);