Skip to content

Commit 144ad83

Browse files
committed
fix avoid crash if book does not exists anymore
1 parent 9b928f0 commit 144ad83

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ SUPER_SECRET='your-secret-key'
1212
# Url to the MongoDb database
1313
# DB_URL='your-db-url-with-user-and-password'
1414
DB_URL='mongodb://127.0.0.1:27017'
15+
DB_URL='mongodb+srv://<user>:<password>@cluster0.jyosd.mongodb.net/?retryWrites=true&w=majority'
1516

1617
# Path to external frontend - If not provided, basic frontend in static/index.html is used
1718
FRONTEND='../EasyLibVue/dist'

app/booklendings.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ router.get('', async (req, res) => {
2727
return {
2828
self: '/api/v1/booklendings/' + dbEntry._id,
2929
student: {
30-
self: '/api/v1/students/' + dbEntry.student._id,
31-
email: dbEntry.student.email
30+
self: '/api/v1/students/' + dbEntry.student?._id,
31+
email: dbEntry.student?.email
3232
},
3333
book: {
34-
self: '/api/v1/books/' + dbEntry.book._id,
35-
title: dbEntry.book.title
34+
self: '/api/v1/books/' + dbEntry.book?._id,
35+
title: dbEntry.book?.title
3636
}
3737
};
3838
});

scripts/clearBooks.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
require('dotenv').config()
2-
var Books = require('../app/models/book'); // get our mongoose model
2+
var mongoose = require('mongoose');
33

4+
var Books = require('../app/models/book'); // get our mongoose model
45

5-
6-
var mongoose = require('mongoose');
76
// connect to database
87
mongoose.connect(process.env.DB_URL)
9-
.then ( async () => {
8+
.then( async () => {
109
console.log("Connected to Database")
1110

1211
// Clear books

0 commit comments

Comments
 (0)