Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
How to slice a value which is inside and obj and pass to next metod which uses it as an object

I have a specific situation where I have a method that getting an object as follow

async ({ locale }, ctx) => {
      const lang = await LanguageService(ctx).getLanguage({
        locale,
      });
      return lang.direction ? 'rtl' : 'ltr';
    },

The { locale } is equal to a request as locale: en_US.

The next method I need to use getLanguage accepts { locale } but I have to pass only the en.

So I thought to do slice but if I send it as for example

const sliced = locale.slice(0,2)
const lang = await LanguageService(ctx).getLanguage({
            sliced, // or locale: sliced
          });

From the next method the locale is showed as undefined and I have no clue how to pass only en in this situation I have

The method getLanguage

async getLanguage({ id, locale }) {
    console.log('locale: ', locale);
    if (!id && !locale) {
      const errorMessage = 'Specify ID or locale';
      throw new ApolloError(errorMessage);
    }

    const filter = id ? { id } : { locale };

    try {
      return await this.withDAO(({ languages }) =>
        languages.selectFirst(filter)
      );
    } catch (error) {
      throw new ApolloError(error.message);
    }
  }

This method needs { locale } and I need to pass en and not en_US

I have no clue how to reach that as when I reach this above method the console.log(locale) is showing undefined when I use slice.

There is a way I can use that obj in the way I need

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda