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

135
Views
I want to return function after doing mapSeries

I want to return querys(function) after doing mapSeries

how do i this? please help me!

async querys(querys) {
        const pool = await poolPromise;
        if (pool != null) {
            const transaction = new sql.Transaction(pool);
            
            await new Promise(resolve => transaction.begin(resolve));
            const request = new sql.Request(transaction)
    
            try {
                let results = []
                // ------------- Series -------------
                async.mapSeries(querys, async (query, callback) => {
                                console.log('----------')
                                const result = await request.query(query);
                                // return result.recordset;
                                results.push(result.recordset);
                }, async (err) => {
                    if (err) {
                        throw new Error(err);
                    }
                    else {
                        await transaction.commit();
                    }
                });
                console.log('hello');
                // -------------- return ---------------
                return [true, results];
            } catch(err) {
                await transaction.rollback();
                return [false, err];
            }
        }
        else {
            return [false, 'connect error'];
        }
    },

querys

expected output : [true, [object], [object] ... ]

real output : [true, []]

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

self answer

added promise

async querys(querys) {
        return new Promise( async resolve => {
            const pool = await poolPromise;

            if (pool != null) {
                const transaction = new sql.Transaction(pool);
                
                await new Promise(resolve => transaction.begin(resolve));
                const request = new sql.Request(transaction)
        
                async.mapSeries(querys, async (query, callback) => {
                    const result = await request.query(query);

                    return result.recordset;
                }
                , async (err, results) => {
                    if (err) {
                        console.log(err);

                        console.log('rollback');
                        await transaction.rollback();

                        resolve({isError: true, err: '데이터 가져오기 오류'});
                    }
                    else {
                        await transaction.commit();

                        resolve({isError: false, data: results})
                    }
                });
            }
            else {
                resolve({isError: true, err: '데이터에 연결할 수 없습니다.'});
            }
        });
    },
about 4 years ago · Juan Pablo Isaza Report
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!