appSettingsUpdater.js 796 B

1234567891011121314151617181920212223242526272829
  1. import appSettingService from '@/services/appSettingService'
  2. import { useNotifyStore } from '@/stores/notify'
  3. /**
  4. * Saves a setting on the backend
  5. * @param {string} preference
  6. * @param {any} value
  7. */
  8. export async function useAppSettingsUpdater(setting, value, returnValidationError = false) {
  9. let data = null
  10. let error = null
  11. await appSettingService.update(setting, value, { returnError: true })
  12. .then(response => {
  13. data = value
  14. useNotifyStore().success({ type: 'is-success', text: trans('settings.forms.setting_saved') })
  15. })
  16. .catch(err => {
  17. if( returnValidationError && err.response.status === 422 ) {
  18. error = err
  19. }
  20. else {
  21. useNotifyStore().error(err);
  22. }
  23. })
  24. return { data, error }
  25. }