Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
91d649d
#41 installed express-validator and did basic test with it
CoderTobi Oct 26, 2025
c11187a
#41 tested custom validator and created a helper for it.
CoderTobi Oct 27, 2025
9f02275
#41 added more validators to activities post
CoderTobi Oct 28, 2025
ce7f23a
#41 added validation helpers for activityID and exception to JSON
CoderTobi Oct 28, 2025
531c1c5
#41 reimplemented activity creation and exists
CoderTobi Oct 28, 2025
c7913f4
#41 WIP activities by plant_id
CoderTobi Oct 29, 2025
1d2c890
#41 updated 404 response of the backend
CoderTobi Oct 29, 2025
0ef0c02
#41 Added helper to calculate days between two days to comply with DRY
CoderTobi Oct 29, 2025
d518a1e
#41 reimplemented all activities by plant_id
CoderTobi Oct 29, 2025
687d2e6
#41 reimplemented delete activity
CoderTobi Oct 29, 2025
dca78bf
replaced var with let in activities service
CoderTobi Oct 29, 2025
8ed1a03
#41 reimplemented get plant by id and fixed some spelling
CoderTobi Nov 6, 2025
ed00b01
#41 fixed wrong variable name in last commit
CoderTobi Nov 6, 2025
2d5cde5
#41 reimplemented get composted plants
CoderTobi Nov 6, 2025
6071cc4
#41 reimplemented get all plants
CoderTobi Nov 6, 2025
a03a8e8
#41 reimplemented plant exists
CoderTobi Nov 6, 2025
da2da04
#41 reimplemented new plant post
CoderTobi Nov 8, 2025
5949d2b
#41 added TODOs in backend
CoderTobi Nov 8, 2025
e2b46d8
#41 WIP reimplementation of put plant
CoderTobi Nov 9, 2025
c898c07
#41 removed test error
CoderTobi Nov 9, 2025
0bbbb23
#41 fixed get all composted plants
CoderTobi Nov 9, 2025
679e588
#41 reimplemented put plant update
CoderTobi Nov 9, 2025
6bdd50e
#41 reimplemented delete plant
CoderTobi Nov 10, 2025
828d8a4
#41 added `.toInt()` after all `bail()` to keep it consistent. Also r…
CoderTobi Nov 10, 2025
600cfa4
#41 updated API
CoderTobi Nov 10, 2025
cd2ab11
#41 reimplemented image upload
CoderTobi Nov 15, 2025
cb09a2a
#41 created customError to batter handle error responses from the bac…
CoderTobi Nov 16, 2025
b5b3ae0
added multiline support to alerts display
CoderTobi Nov 16, 2025
fd9d126
#41 corrected use of backendError and correctly set the name of the e…
CoderTobi Nov 16, 2025
af86603
#41 completely reworked the error handler to work with the new valida…
CoderTobi Nov 16, 2025
86c990b
#41 fixed a wrong case in the error handler for the frontend
CoderTobi Nov 17, 2025
efc603d
Fixed a incorrect log message in the backend
CoderTobi Nov 17, 2025
59621bc
Added two new environment variables to disable sql and http logging o…
CoderTobi Nov 17, 2025
6cd686c
updated template to also mostly work on the dev dir
CoderTobi Nov 17, 2025
e05f116
added test to dev page to tes multiline error alert
CoderTobi Nov 17, 2025
eb6fdff
Fixed newlines in error handler on the frontend
CoderTobi Nov 17, 2025
0b91e97
- updated frontend version from 1.2.1 to 1.2.2
CoderTobi Nov 17, 2025
7f10cde
Updated dependency js-yaml from 4.0.0 to 4.1.0
CoderTobi Nov 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"cSpell.language": "en,de-DE"
"cSpell.language": "en,de-DE",
"cSpell.words": [
"repotted"
]
}
5 changes: 5 additions & 0 deletions backend/dao/plantsDao.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
const helper = require('../helper.js');
const daoHelper = require('./daoHelper.js');

// TODO Add JSDoc comments to all methods
// TODO Make date handling consistent (either use strings or DateTime objects throughout the DAO)
// Post uses DateTime objects, Put uses strings
// Strings is probably better because the validation middleware uses strings
// TODO change var to const/let

/**
* Data Access Object for plants
Expand Down
12 changes: 12 additions & 0 deletions backend/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ module.exports.compareDateTimes = function(leftdatetime, rightdatetime) {
return 0;
}

/**
* Probably not correctly implemented, see issue #39
* Calculates the number of days between two datetime objects
* @param {*} leftdatetime The left datetime object
* @param {*} rightdatetime The right datetime object
* @returns The number of days between the two datetime objects
*/
module.exports.calculateDaysBetween = function(leftdatetime, rightdatetime) {
const timeDifference = Math.abs(leftdatetime - rightdatetime);
return Math.floor(timeDifference / (1000 * 60 * 60 * 24));
}

// modifies a given datetime object
// adds or subs values to years, months, days, hours, minutes, seconds
// positive values are added, negative ones subbed. 0 values are ignored
Expand Down
39 changes: 34 additions & 5 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plant_manager_backend",
"version": "1.1.2",
"version": "1.1.3",
"description": "Backend for PlantManager with file upload and sqlite",
"main": "server.js",
"scripts": {
Expand All @@ -16,6 +16,7 @@
"cors": "^2.8.5",
"express": "^4.19.2",
"express-fileupload": "^1.5.0",
"express-validator": "^7.3.0",
"luxon": "^3.4.4",
"morgan": "^1.10.0"
},
Expand Down
22 changes: 15 additions & 7 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ try
// connect database
console.log('Connect database...');
const Database = require('better-sqlite3');
const dbOptions = { verbose: console.log };
let dbOptions = {}
if (process.env.LOG_SQLITE_QUERIES === 'true') {
console.log('Database debugging enabled');
dbOptions = { verbose: console.log };
}
const dbFile = './db/plantmanagerDB.sqlite';
const dbConnection = new Database(dbFile, dbOptions);

Expand Down Expand Up @@ -67,7 +71,11 @@ try
response.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
});
app.use(morgan('dev'));

// log all requests to the console
if (process.env.LOG_HTTP_QUERIES === 'true') {
app.use(morgan('dev'));
}

// ====== BINDING ENDPOINTS ======
const TOPLEVELPATH = '/api';
Expand All @@ -85,8 +93,8 @@ try

// send default error message if no matching endpoint found
app.use(function (request, response) {
console.log('Error occured, 404, resource not found');
response.status(404).json({'fehler': true, 'nachricht': 'Resource nicht gefunden'});
console.log('Error occurred, 404, resource not found');
response.status(404).json({ errors: [{ 'msg': "API Endpoint not found"}] });
});
// ===============================

Expand All @@ -97,9 +105,9 @@ try
console.log('Listening at localhost, port ' + HTTP_PORT);
console.log('\nUsage: http://localhost:' + HTTP_PORT + TOPLEVELPATH + "/SERVICENAME/SERVICEMETHOD/....");
console.log('\nPlant Manager Backend \nDeveloped by: QuadcoreDevelopment');
console.log('\n\n-----------------------------------------');
console.log('exit / stop Server by pressing 2 x CTRL-C');
console.log('-----------------------------------------\n\n');
console.log('\n\n-------------------------------------');
console.log('exit / stop Server by pressing CTRL-C');
console.log('-------------------------------------\n\n');
});
}
catch (ex)
Expand Down
Loading