Last active
January 4, 2023 05:40
-
-
Save ashishakya/6db66a24ef7b1156029b5e9a68fa8f4d to your computer and use it in GitHub Desktop.
Updated snippet via Qaasaa
This file contains hidden or 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
| <?php | |
| namespace App\Services\Tenancy; | |
| use App\Criterias\BaseCriteria; | |
| use App\Repositories\Tenancy\BaseRepository; | |
| use Illuminate\Contracts\Pagination\LengthAwarePaginator; | |
| use Illuminate\Support\Collection; | |
| use Prettus\Repository\Exceptions\RepositoryException; | |
| use Prettus\Repository\Presenter\FractalPresenter; | |
| abstract class BaseService | |
| { | |
| /** | |
| * @return BaseRepository | |
| */ | |
| abstract public function repository(): BaseRepository; | |
| /** | |
| * @param array $with | |
| * | |
| * @return $this | |
| */ | |
| public function with(array $with): self | |
| { | |
| $this->repository()->with($with); | |
| return $this; | |
| } | |
| /** | |
| * @param int|null $perPage | |
| * | |
| * @return Collection|array | |
| */ | |
| public function getPaginated($perPage = 10) | |
| { | |
| return $this->repository()->paginate($perPage); | |
| } | |
| /** | |
| * @return LengthAwarePaginator|Collection|mixed | |
| */ | |
| public function get() | |
| { | |
| return $this->repository()->get(); | |
| } | |
| /** | |
| * @param FractalPresenter $presenter | |
| * | |
| * @return $this | |
| */ | |
| public function withPresenter(FractalPresenter $presenter): self | |
| { | |
| $this->repository()->setPresenter($presenter); | |
| return $this; | |
| } | |
| /** | |
| * @param BaseCriteria $criteria | |
| * | |
| * @return $this | |
| * @throws RepositoryException | |
| */ | |
| public function withCriteria(BaseCriteria $criteria): self | |
| { | |
| $this->repository()->pushCriteria($criteria); | |
| return $this; | |
| } | |
| /** | |
| * @param $id | |
| * @param bool $withTrashed | |
| * | |
| * @return LengthAwarePaginator|Collection|mixed | |
| */ | |
| public function findById($id, $withTrashed=false) | |
| { | |
| if($withTrashed){ | |
| return $this->repository()->withTrashed()->find((int) $id); | |
| } | |
| return $this->repository()->find((int) $id); | |
| } | |
| /** | |
| * @param array $data | |
| * | |
| * @throws \Exception | |
| */ | |
| public function create(array $data) | |
| { | |
| try { | |
| $this->repository() | |
| ->create($data); | |
| } catch (\Exception $exception) { | |
| throw new \Exception(); | |
| } | |
| } | |
| /** | |
| * @param $id | |
| * | |
| * @throws \Exception | |
| */ | |
| public function delete($id) | |
| { | |
| try { | |
| $this->repository() | |
| ->delete($id); | |
| } catch (\Exception $e) { | |
| throw new \Exception(); | |
| } | |
| } | |
| /** | |
| * @param int $id | |
| * @param array $data | |
| * | |
| * @throws \Exception | |
| */ | |
| public function update(array $data, int $id) | |
| { | |
| try { | |
| $this->repository() | |
| ->update($data, $id); | |
| } catch (\Exception $e) { | |
| throw new \Exception(); | |
| } | |
| } | |
| /** | |
| * @param array $relations | |
| * | |
| * @return $this | |
| */ | |
| public function withCount(array $relations): self | |
| { | |
| $this->repository()->withCount($relations); | |
| return $this; | |
| } | |
| } |
This file contains hidden or 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
| updateLeadsCustomFields(this.editableCustomFieldId, formData) | |
| .then(({data}) => { | |
| this.alertSuccessMessage(data.message || "default success message") | |
| this.$emit("success") | |
| }) | |
| .catch((error) => { | |
| this.setErrors(error.response.data.errors) | |
| this.alertErrorMessage(error.response.data.message || "default error message" ) | |
| }) |
This file contains hidden or 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
| import Vue from "vue" | |
| const FormErrorsMixin = { | |
| data(){ | |
| return { | |
| errors:{} | |
| } | |
| }, | |
| methods:{ | |
| setErrors(errors){ | |
| this.errors = errors | |
| }, | |
| getErrorMessage(field) { | |
| if (this.errors[field]) { | |
| return Array.isArray(this.errors[field]) ? this.errors[field][0] : this.errors[field] | |
| } | |
| }, | |
| hasError(field) { | |
| let _self = this | |
| if (field instanceof Array) { | |
| field.forEach(function(fieldName) { | |
| if (_self.errors.hasOwnProperty(fieldName)) { | |
| return _self.errors.hasOwnProperty(fieldName) | |
| } | |
| }) | |
| } | |
| return this.errors.hasOwnProperty(field) | |
| }, | |
| clearErrors(field) { | |
| if (field) { | |
| let arrayName = field.toString().replace(/[\[\]']+/g, ".").replace(/\.$/, "") | |
| Vue.delete(this.errors, arrayName) | |
| return | |
| } | |
| this.errors = {} | |
| } | |
| } | |
| } | |
| export default FormErrorsMixin; |
This file contains hidden or 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
| import axios from "./axios" | |
| import { filterObject } from "./helper" | |
| import router from "@/app"; | |
| axios.interceptors.response.use(null, error => { | |
| let targetedRouteName = "ServerError"; | |
| switch (error.response.status) { | |
| case 401: targetedRouteName = "NotAllowed"; break; | |
| case 404: targetedRouteName = "PageNotFound"; break; | |
| } | |
| router.push({ name: targetedRouteName }); | |
| return Promise.reject(error); | |
| }); | |
| export const httpGet = async (targetUrl, queryParams) => { | |
| const filteredQueryParams = filterObject(queryParams) | |
| return await axios.get(targetUrl, { params: filteredQueryParams }) | |
| } | |
| export const httpPost = async (targetUrl, data) => { | |
| return await axios.post(targetUrl, data) | |
| } | |
| export const httpPatch = async (targetUrl, data) => { | |
| return await axios.patch(targetUrl, data) | |
| } | |
| export const httpDelete = async (targetUrl) => { | |
| return await axios.delete(targetUrl) | |
| } |
This file contains hidden or 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
| const NotificationMixin = { | |
| methods:{ | |
| alertSuccessMessage(successMessage) { | |
| this.$notify({ | |
| group: "foo", | |
| type: "success", | |
| title: this.trans("success"), | |
| text: successMessage, | |
| }) | |
| }, | |
| alertErrorMessage(errorMessage) { | |
| this.$notify({ | |
| group: "foo", | |
| type: "error", | |
| title: this.trans("Error"), | |
| text: errorMessage, | |
| }) | |
| }, | |
| } | |
| } | |
| export default NotificationMixin; |
This file contains hidden or 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
| import { | |
| httpGet, | |
| httpPost, | |
| } from "../utilities/Http" | |
| export const getLeadsFormFields = async (formSlug) => { | |
| const targetUrl = `/api/leads/forms/${formSlug}/fields` | |
| return await httpGet(targetUrl) | |
| } | |
| export const storeLeadsFormApplication = async (data) => { | |
| const targetUrl = `/api/leads/applications` | |
| return await httpPost(targetUrl, data) | |
| } | |
| export const fetchLeadFormApplicationList = async (queryParams)=>{ | |
| const targetUrl = `/api/leads/applications` | |
| return await httpGet(targetUrl, queryParams) | |
| } | |
| export const fetchLeadFormApplicationDetail = async (id)=>{ | |
| const targetUrl = `/api/leads/applications/${id}` | |
| return await httpGet(targetUrl) | |
| } | |
| export const approveLeadFormApplication = async (id)=>{ | |
| const targetUrl = `api/leads/applications/${id}/approve` | |
| return await httpPost(targetUrl) | |
| } | |
| export const rejectLeadFormApplication = async (id)=>{ | |
| const targetUrl = `api/leads/applications/${id}/reject` | |
| return await httpPost(targetUrl) | |
| } | |
This file contains hidden or 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
| function resetForm(){ | |
| document.getElementById("leads-candidate-form") | |
| .reset() | |
| } | |
| function scrollToTop(){ | |
| window.scrollTo({ top: 0, behavior: "smooth" }) | |
| } | |
| export const filterObject = (obj) => { | |
| for (let propName in obj) { | |
| if (obj[propName] === '' || obj[propName] === null || obj[propName] === undefined) { | |
| delete obj[propName]; | |
| } | |
| } | |
| return obj; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment