Skip to content

Commit

Permalink
checkin fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hsc-nue committed Sep 23, 2023
1 parent c18838d commit 2ab6748
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 11 additions & 4 deletions controllers/scoreController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -400,7 +403,9 @@ const sendCheckoutConfirmationEmail = async (
const html = `
Liebe Chorsängerin, lieber Chorsänger,
<p>
Du hast Noten "${(await getScoreTypeMap()).get(score.signature)}" mit Nummer ${score.id} vom Hans-Sachs-Chor ausgeliehen.<br>
Du hast Noten "${(await getScoreTypeMap()).get(
score.signature
)}" mit Nummer ${score.id} vom Hans-Sachs-Chor ausgeliehen.<br>
Bitte behandle die Noten pfleglich und nehme Eintragungen nur mit Bleistift vor.<br>
Nach dem Konzert müssen die Noten zeitnah wieder zurückgegeben werden.<br>
Radiere bitte vorher deine Eintragungen aus.<br>
Expand Down Expand Up @@ -448,7 +453,9 @@ const sendCheckinConfirmationEmail = async (
const html = `
Liebe Chorsängerin, lieber Chorsänger,
<p>
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!
<p>
Dein Hans-Sachs-Chor Notenwart
`;
Expand Down
7 changes: 5 additions & 2 deletions dist/controllers/scoreController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 });
}
Expand Down

0 comments on commit 2ab6748

Please sign in to comment.