Skip to content

Commit

Permalink
Attempt to fix TS error in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminJohnson2204 committed Apr 19, 2024
1 parent 57259cc commit 8e9c77d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
9 changes: 4 additions & 5 deletions backend/dist/src/controllers/vsr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions backend/src/controllers/vsr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,27 +296,27 @@ 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
// with an _id in the vsrIds list

// 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);
}
Expand Down

0 comments on commit 8e9c77d

Please sign in to comment.