Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@

"Terms of Service": "Terms of Service",
"Thank you for your support!": "Thank you for your support!",
"This company has registered users and cannot be deleted.": "This company has registered users and cannot be deleted.",
"This password reset link will expire in :count minutes.": "This password reset link will expire in :count minutes.",
"This verification link will expire in :count minutes.": "This verification link will expire in :count minutes.",
"Total": "Total",
Expand Down
1 change: 1 addition & 0 deletions lang/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@

"Terms of Service": "Hizmet Şartları",
"Thank you for your support!": "Desteğiniz için teşekkür ederiz!",
"This company has registered users and cannot be deleted.": "Bu şirkete kayıtlı kullanıcılar olduğu için bu şirket silinemez.",
"This password reset link will expire in :count minutes.": "Bu şifre oluşturma linki :count dakika içerisinde sonlanacak.",
"This verification link will expire in :count minutes.": "Bu doğrulama linki :count dakika içerisinde sonlanacak.",
"Total": "Toplam",
Expand Down
16 changes: 16 additions & 0 deletions modules/SystemUser/Http/Requests/CompanyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ public function rulesForUpdate()
];
}

public function rulesForDelete()
{
return [
'id' => [
'required',
function ($attribute, $value, $fail) {
$company = $this->model()->find($value);

if ($company && $company->users()->exists()) {
$fail(__('This company has registered users and cannot be deleted.'));
}
},
],
];
}

public function messages()
{
return [
Expand Down
2 changes: 2 additions & 0 deletions src/Http/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ public function update($id, $submoduleId = null)
*/
public function destroy($id, $submoduleId = null)
{
$this->getFormRequestClass();

$params = $this->request->route()->parameters();

$id = last($params);
Expand Down
39 changes: 39 additions & 0 deletions src/Http/Requests/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
namespace Unusualify\Modularous\Http\Requests;

use Closure;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Unusualify\Modularity\Services\MessageStage;
use Unusualify\Modularous\Traits\ManageTraits;

abstract class Request extends FormRequest
Expand Down Expand Up @@ -45,12 +48,48 @@ public function rules()
case 'PUT':
return $this->mergeRules(array_merge($this->rulesForAll(), $this->rulesForUpdate()));

case 'DELETE':
return $this->rulesForDelete();

default:break;
}

return [];
}

public function rulesForDelete()
{
return [];
}

protected function prepareForValidation()
{
if ($this->method() === 'DELETE' && $this->route()) {
$parameters = $this->route()->parameters();

if (! empty($parameters) && ! $this->has('id')) {
$this->merge(['id' => last($parameters)]);
}
}
}


protected function failedValidation(Validator $validator)
{
if ($this->method() === 'DELETE') {
$response = response()->json([
'message' => $validator->errors()->first(),
'errors' => $validator->errors(),
'variant' => MessageStage::ERROR->value,
], 422);

throw new ValidationException($validator, $response);
}

parent::failedValidation($validator);
}


public function mergeRules($rules)
{
$locales = getLocales();
Expand Down
6 changes: 5 additions & 1 deletion vue/src/js/hooks/useTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,11 @@ export default function useTable (props, context) {
}

let successCallback = (res) => {
if(res.status === 200) {
if (res.status === 422) {
if (runAlert && res.data?.message) {
store.dispatch(ACTIONS.SHOW_ALERT, res.data)
}
} else if (res.status === 200) {

if(runAlert && res.data.variant && res.data.message){
store.dispatch(ACTIONS.SHOW_ALERT, res.data)
Expand Down
14 changes: 10 additions & 4 deletions vue/src/js/store/api/datatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ export default {
// const url = window[import.meta.env.VUE_APP_NAME].ENDPOINTS.destroy.replace(':id', id)
// var url = window[import.meta.env.VUE_APP_NAME].ENDPOINTS.index.replace(':id', item.id);
url = url.replace(':id', id)
axios.delete(url).then(function (resp) {
console.log(url)
axios.delete(url, {
validateStatus: status => (status >= 200 && status < 300) || status === 422
}).then(function (resp) {
if (callback && typeof callback === 'function') callback(resp)
}, function (resp) {
const error = {
Expand All @@ -68,7 +71,9 @@ export default {
forceDelete (url, id, callback, errorCallback) {
// const url = window[import.meta.env.VUE_APP_NAME].ENDPOINTS.forceDelete
url = url.replace(':id', id)
axios.put(url, { id }).then(function (resp) {
axios.put(url, { id }, {
validateStatus: status => (status >= 200 && status < 300) || status === 422
}).then(function (resp) {
if (callback && typeof callback === 'function') callback(resp)
}, function (resp) {
const error = {
Expand All @@ -83,7 +88,9 @@ export default {
restore (url, id, callback) {
// const url = window[import.meta.env.VUE_APP_NAME].ENDPOINTS.restore
url = url.replace(':id', id)
axios.put(url, { id }).then(function (resp) {
axios.put(url, { id }, {
validateStatus: status => (status >= 200 && status < 300) || status === 422
}).then(function (resp) {
if (callback && typeof callback === 'function') callback(resp)
}, function (resp) {
const error = {
Expand Down Expand Up @@ -121,7 +128,6 @@ export default {
if (errorCallback && typeof errorCallback === 'function') errorCallback(error)
})
},

bulkPublish (url, params, callback) {
// const url = window[import.meta.env.VUE_APP_NAME].CMS_URLS.bulkPublish
axios.post(url, { ids: params.ids, publish: params.toPublish }).then(function (resp) {
Expand Down
Loading