Skip to content

refactor(useCustomerStore): Allows you to adjust methods without duplication.#22

Open
dvjeshka wants to merge 14 commits intograndant:masterfrom
dvjeshka:lk
Open

refactor(useCustomerStore): Allows you to adjust methods without duplication.#22
dvjeshka wants to merge 14 commits intograndant:masterfrom
dvjeshka:lk

Conversation

@dvjeshka
Copy link
Contributor

@dvjeshka dvjeshka commented Jan 16, 2026

layers/lk/store/useCustomerStore.ts

import type {
  RegisterResult,
  UpdateCustomerResult
} from "~~/types/customer";

export const useCustomerStore = defineStore("customer", () => {
  const {customer,loading,error,...base} = useCustomerLogic();

  async function register(input: {
    ...
    phoneNumber: string;
    customFields:Record<string, unknown>
  }): Promise<RegisterResult | undefined> {
    try {
      const result = (await GqlRegisterCustomerAccount({ input }))
        .registerCustomerAccount;

      return result;
    } catch (err) {
      console.error("Registration error:", err);
      return undefined;
    }
  }

  async function updateCustomer(input): Promise<UpdateCustomerResult | undefined> {
    loading.value = true;
    error.value = null;

    try {
      const result = (await GqlLKUpdateCustomer({ input })).updateCustomer;
      customer.value = result;
      return result;
    } catch (err) {
      console.error("updateCustomer request error:", err);
      return undefined;
    }
  }

  return {
    customer,
    loading,
    error,
    ...base,
    updateCustomer,
    register
  };
});

@grandant
Copy link
Owner

I don't see how this changes anything in a positive way. I think the logic belongs into the Pinia store as it was before the refactor.

It is possible to use the store logic in a new composable if you need testing or have other usages in mind.

Can you clarify what the intention please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants