From 2ab674800925bb4cc67730b0d02fc86511eff87d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20S=C3=BCdkamp?= Date: Sat, 23 Sep 2023 11:49:34 +0200 Subject: [PATCH] checkin fix --- controllers/scoreController.ts | 15 +++++++++++---- dist/controllers/scoreController.js | 7 +++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/controllers/scoreController.ts b/controllers/scoreController.ts index b23a36d..0b28e92 100644 --- a/controllers/scoreController.ts +++ b/controllers/scoreController.ts @@ -128,7 +128,8 @@ module.exports.checkout_post = async (req: any, res: any) => { score = await score.save(); if (score) { const user = await User.findOne({ id: userId }); - if (user) { // we don't expect error because we validated the user id before + if (user) { + // we don't expect error because we validated the user id before await sendCheckoutConfirmationEmail( user, score, @@ -229,6 +230,7 @@ module.exports.checkin_post = async (req: any, res: any) => { try { if (scoreId && comment != undefined) { + // checkin request let score = await Score.findOne({ id: scoreId }); if (score) { if (score.checkedOutByUserId) { @@ -275,12 +277,13 @@ module.exports.checkin_post = async (req: any, res: any) => { }); } } else if (scoreId) { + // search score and return checkin form const score = await Score.findOne({ id: scoreId }); if (score) { const checkedOutByUserId = score.checkedOutByUserId; if (checkedOutByUserId) { - const user = await User.findOne({ _id: checkedOutByUserId }); + const user = await User.findOne({ id: checkedOutByUserId }); if (user) { res.status(200).json({ checkinScore: score, checkinUser: user }); } else { @@ -400,7 +403,9 @@ const sendCheckoutConfirmationEmail = async ( const html = ` Liebe Chorsängerin, lieber Chorsänger,

- Du hast Noten "${(await getScoreTypeMap()).get(score.signature)}" mit Nummer ${score.id} vom Hans-Sachs-Chor ausgeliehen.
+ Du hast Noten "${(await getScoreTypeMap()).get( + score.signature + )}" mit Nummer ${score.id} vom Hans-Sachs-Chor ausgeliehen.
Bitte behandle die Noten pfleglich und nehme Eintragungen nur mit Bleistift vor.
Nach dem Konzert müssen die Noten zeitnah wieder zurückgegeben werden.
Radiere bitte vorher deine Eintragungen aus.
@@ -448,7 +453,9 @@ const sendCheckinConfirmationEmail = async ( const html = ` Liebe Chorsängerin, lieber Chorsänger,

- Du hast die Noten "${(await getScoreTypeMap()).get(score.signature)}" mit Nummer ${score.id} erfolgreich zurückgegeben. Vielen Dank! + Du hast die Noten "${(await getScoreTypeMap()).get( + score.signature + )}" mit Nummer ${score.id} erfolgreich zurückgegeben. Vielen Dank!

Dein Hans-Sachs-Chor Notenwart `; diff --git a/dist/controllers/scoreController.js b/dist/controllers/scoreController.js index cbe2969..0e64112 100644 --- a/dist/controllers/scoreController.js +++ b/dist/controllers/scoreController.js @@ -110,7 +110,8 @@ module.exports.checkout_post = (req, res) => __awaiter(void 0, void 0, void 0, f score = yield score.save(); if (score) { const user = yield User_1.User.findOne({ id: userId }); - if (user) { // we don't expect error because we validated the user id before + if (user) { + // we don't expect error because we validated the user id before yield sendCheckoutConfirmationEmail(user, score, process.env.EMAIL_TEST_RECIPIENT); } res.status(201).json({ checkoutScore: score }); @@ -213,6 +214,7 @@ module.exports.checkin_post = (req, res) => __awaiter(void 0, void 0, void 0, fu const { scoreId, comment } = req.body; try { if (scoreId && comment != undefined) { + // checkin request let score = yield Score_1.Score.findOne({ id: scoreId }); if (score) { if (score.checkedOutByUserId) { @@ -259,11 +261,12 @@ module.exports.checkin_post = (req, res) => __awaiter(void 0, void 0, void 0, fu } } else if (scoreId) { + // search score and return checkin form const score = yield Score_1.Score.findOne({ id: scoreId }); if (score) { const checkedOutByUserId = score.checkedOutByUserId; if (checkedOutByUserId) { - const user = yield User_1.User.findOne({ _id: checkedOutByUserId }); + const user = yield User_1.User.findOne({ id: checkedOutByUserId }); if (user) { res.status(200).json({ checkinScore: score, checkinUser: user }); }