From 8e9c77dc67ab551737b311e9fdec88707dcb6532 Mon Sep 17 00:00:00 2001 From: benjaminjohnson2204 Date: Fri, 19 Apr 2024 00:04:23 -0700 Subject: [PATCH] Attempt to fix TS error in backend --- backend/dist/src/controllers/vsr.js | 9 ++++----- backend/src/controllers/vsr.ts | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/backend/dist/src/controllers/vsr.js b/backend/dist/src/controllers/vsr.js index 12af104..2a1ba94 100644 --- a/backend/dist/src/controllers/vsr.js +++ b/backend/dist/src/controllers/vsr.js @@ -252,18 +252,17 @@ const bulkExportVSRS = (req, res, next) => __awaiter(void 0, void 0, void 0, fun // with an _id in the vsrIds list // Need to convert each ID string to an ObjectId object const vsrObjectIds = (_b = req.query.vsrIds) === null || _b === void 0 ? void 0 : _b.split(",").map((_id) => new mongodb_1.ObjectId(_id)); - vsrs = yield vsr_1.default.find({ + vsrs = (yield vsr_1.default.find({ _id: { $in: vsrObjectIds, }, - }); + })).map((doc) => doc.toObject()); } else { // If the "vsrIds" query parameter is not provided or is empty, export all VSRs in the database - vsrs = yield vsr_1.default.find(); + vsrs = (yield vsr_1.default.find()).map((doc) => doc.toObject()); } - const plainVsrs = vsrs.map((doc) => doc.toObject()); - yield writeSpreadsheet(plainVsrs, res); + yield writeSpreadsheet(vsrs, res); } catch (error) { next(error); diff --git a/backend/src/controllers/vsr.ts b/backend/src/controllers/vsr.ts index 3c0cfff..6e73bb9 100644 --- a/backend/src/controllers/vsr.ts +++ b/backend/src/controllers/vsr.ts @@ -296,7 +296,7 @@ export const bulkExportVSRS: RequestHandler = async (req, res, next) => { "Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", }); - let vsrs; + let vsrs: VSR[]; if (req.query.vsrIds && ((req.query.vsrIds.length ?? 0) as number) > 0) { // If the "vsrIds" query parameter exists and is non-empty, then find & export all VSRs @@ -304,19 +304,19 @@ export const bulkExportVSRS: RequestHandler = async (req, res, next) => { // Need to convert each ID string to an ObjectId object const vsrObjectIds = (req.query.vsrIds as string)?.split(",").map((_id) => new ObjectId(_id)); - vsrs = await VSRModel.find({ - _id: { - $in: vsrObjectIds, - }, - }); + vsrs = ( + await VSRModel.find({ + _id: { + $in: vsrObjectIds, + }, + }) + ).map((doc) => doc.toObject()); } else { // If the "vsrIds" query parameter is not provided or is empty, export all VSRs in the database - vsrs = await VSRModel.find(); + vsrs = (await VSRModel.find()).map((doc) => doc.toObject()); } - const plainVsrs = vsrs.map((doc) => doc.toObject()); - - await writeSpreadsheet(plainVsrs, res); + await writeSpreadsheet(vsrs, res); } catch (error) { next(error); }