Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!