const arr = {}; await Promise.all( UsersQuery.map(async function (data) { const city = await db.sequelize.query(` select * from city `, type: db.sequelize.QueryTypes.SELECT }); arr[data.user_id] = city[0].name; }) } UsersQuery.forEach(async function (data, index) { this[index].name = arr[data.user_id]; }, UsersQuery);
Use express, moment, moment-timezone
const moment = require('moment-timezone'); app.get('/moment', (req, res) => { const datestr = '2020-07-01'; res.status(200).json({ local_offset: moment(datestr).utc(), local_unix: moment(datestr).unix(), zone0_unix: moment(datestr).zone(0).unix(), zone8_unix: moment(datestr).zone(8).unix(), timezone0_unix: moment.tz(datestr, 'GMT').unix(), timezone8_unix: moment.tz(datestr, 'Asia/Taipei').unix(), }); }); // No use, just for keep function dateForTimezone(offset, d) { // Copy date if supplied or use current d = d? new Date(+d) : new Date(); // Use supplied offset or system offset = offset || -d.
const typeorm = require("typeorm"); const connectionManager = require("typeorm").getConnectionManager(); //const connectionManager = typeorm.getConnectionManager(); const connected = connectionManager.has("default"); if(!connected){ // ? load connection options from ormconfig or environment //const connectionOptions = await getConnectionOptions(); connectionManager.create({ //name: "default", type: "mysql", // "extra": { // "socketPath": "/cloudsql/ooxxooxx" // }, host: "oo.xx.oo.xx", port: 3306, username: "root", password: "ooxxooxx", database: "ooxxdb", synchronize: false, logging: true, // this.env === 'dev' ? true : false ssl: SSL, keepConnectionAlive: false, }); } try { db = connectionManager.
ajv schema to apidoc schema
https://github.com/willfarrell/apidoc-plugin-schema
required can’t product doc.
converter
https://github.com/apidoc/apidoc#converter
to swagger
https://github.com/fsbahman/apidoc-swagger
postman collection to apidoc
https://github.com/bonzzy/docmaster
RestClient -> curl -> postman
https://stackoverflow.com/questions/30362733/handling-errors-in-promise-all
Promise.all(state.routes.map(function(route) { return route.handler.promiseHandler().catch(function(err) { return err; }); })) .then(function(arrayOfValuesOrErrors) { // handling of my array containing values and/or errors. }) .catch(function(err) { console.log(err.message); // some coding error in handling happened }); Alternately, if you have a case where you don’t particularly care about the values of the resolved promises when there is one failure but you still want them to have run, you could do something like this which will resolve with the promises as normal when they all succeed and reject with the failed promises when any of them fail:
https://github.com/goldbergyoni/nodebestpractices
https://v8.dev/blog/fast-async