Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda