質問編集履歴

2

修正

2021/03/29 10:56

投稿

ryota002
ryota002

スコア18

test CHANGED
File without changes
test CHANGED
@@ -218,7 +218,11 @@
218
218
 
219
219
 
220
220
 
221
- return await Promise.all(myPromise);
221
+ await Promise.all(myPromise);
222
+
223
+
224
+
225
+ return usersData;
222
226
 
223
227
  };
224
228
 

1

promise.allで書いたものを追記しました

2021/03/29 10:56

投稿

ryota002
ryota002

スコア18

test CHANGED
File without changes
test CHANGED
@@ -144,6 +144,94 @@
144
144
 
145
145
 
146
146
 
147
+ > promise.allを使って書きました。
148
+
149
+ ```js
150
+
151
+ const admin = require("firebase-admin");
152
+
153
+ const serviceAccount = require("../keys/serviceAccountKey.json");
154
+
155
+ const fetchProcessingsData = require("./fetchProcessingsData");
156
+
157
+
158
+
159
+ const fetchUsersData = () => {
160
+
161
+ if (!admin.apps.length) {
162
+
163
+ admin.initializeApp({
164
+
165
+ credential: admin.credential.cert(serviceAccount),
166
+
167
+ });
168
+
169
+ }
170
+
171
+
172
+
173
+ const db = admin.firestore();
174
+
175
+
176
+
177
+ const usersData = [];
178
+
179
+
180
+
181
+ const USER = "User";
182
+
183
+
184
+
185
+ const myPromise = db
186
+
187
+ .collection(USER)
188
+
189
+ .get()
190
+
191
+ .then((querySnapshot) => {
192
+
193
+ return new Promise(async () => {
194
+
195
+ querySnapshot.forEach(async (doc) => {
196
+
197
+ const processings = await fetchProcessingsData(doc.id);
198
+
199
+ usersData.push({
200
+
201
+ userInfo: doc.data(),
202
+
203
+ processings: processings,
204
+
205
+ });
206
+
207
+ });
208
+
209
+ });
210
+
211
+ })
212
+
213
+ .catch((error) => {
214
+
215
+ console.error(error);
216
+
217
+ });
218
+
219
+
220
+
221
+ return await Promise.all(myPromise);
222
+
223
+ };
224
+
225
+
226
+
227
+ module.exports = fetchUsersData;
228
+
229
+
230
+
231
+ ```
232
+
233
+
234
+
147
235
  ### 補足情報(FW/ツールのバージョンなど)
148
236
 
149
237