Skip to content

Commit

Permalink
Profile changes logging
Browse files Browse the repository at this point in the history
  • Loading branch information
megastary committed Oct 21, 2023
1 parent 0f5c137 commit 62cfb5f
Showing 1 changed file with 75 additions and 6 deletions.
81 changes: 75 additions & 6 deletions routes/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import { Router } from 'express'
import User from '../models/user.js'
import { ensureAuthenticated } from '../functions/ensureAuthenticated.js'
import { checkKiosk } from '../functions/checkKiosk.js'
import logger from '../functions/logger.js'
var router = Router()

/* GET profile page. */
router.get('/', ensureAuthenticated, checkKiosk, function (req, res, next) {
router.get('/', ensureAuthenticated, checkKiosk, function (req, res, _next) {
res.render('shop/profile', {
title: 'Profil | Lednice IT',
user: req.user
})
})

router.post('/', ensureAuthenticated, function (req, res, next) {
router.post('/', ensureAuthenticated, function (req, res, _next) {
var newValue = req.body.value === 'true'
if (req.body.name === 'checkAllProducts') {
User.findByIdAndUpdate(
Expand All @@ -25,23 +26,53 @@ router.post('/', ensureAuthenticated, function (req, res, next) {
}
)
.then(() => {
logger.info(
`server.routes.profile.post__User:[${req.user.displayName}] set preference showAllProducts:[${newValue}].`,
{
metadata: {
result: req.user
}
}
)
res.status(200).send()
return
})
.catch((err) => {
console.log(err)
logger.error(
`server.routes.profile.post__Failed to set preference showAllProducts:[${newValue}] for user:[${req.user.displayName}].`,
{
metadata: {
error: err.message
}
}
)
res.status(400).send()
})
} else if (req.body.name === 'checkSendEmailEshop') {
User.findByIdAndUpdate(req.user.id, {
sendMailOnEshopPurchase: newValue
})
.then(() => {
logger.info(
`server.routes.profile.post__User:[${req.user.displayName}] set preference sendMailOnEshopPurchase:[${newValue}].`,
{
metadata: {
result: req.user
}
}
)
res.status(200).send()
return
})
.catch((err) => {
console.log(err)
logger.error(
`server.routes.profile.post__Failed to set preference sendMailOnEshopPurchase:[${newValue}] for user:[${req.user.displayName}].`,
{
metadata: {
error: err.message
}
}
)
res.status(400).send()
return
})
Expand All @@ -50,11 +81,26 @@ router.post('/', ensureAuthenticated, function (req, res, next) {
sendDailyReport: newValue
})
.then(() => {
logger.info(
`server.routes.profile.post__User:[${req.user.displayName}] set preference sendDailyReport:[${newValue}].`,
{
metadata: {
result: req.user
}
}
)
res.status(200).send()
return
})
.catch((err) => {
console.log(err)
logger.error(
`server.routes.profile.post__Failed to set preference sendDailyReport:[${newValue}] for user:[${req.user.displayName}].`,
{
metadata: {
error: err.message
}
}
)
res.status(400).send()
return
})
Expand All @@ -64,15 +110,38 @@ router.post('/', ensureAuthenticated, function (req, res, next) {
IBAN: req.body.value
})
.then(() => {
logger.info(
`server.routes.profile.post__User:[${req.user.displayName}] set new IBAN:[${req.body.value}].`,
{
metadata: {
result: req.user
}
}
)
res.status(200).send()
return
})
.catch((err) => {
console.log(err)
logger.error(
`server.routes.profile.post__Failed to set IBAN:[${req.body.value}] for user:[${req.user.displayName}].`,
{
metadata: {
error: err.message
}
}
)
res.status(400).send()
return
})
} else {
logger.warn(
`server.routes.profile.post__User:[${req.user.displayName}] tried to set invalid IBAN:[${req.body.value}].`,
{
metadata: {
result: req.user
}
}
)
res.status(400).send()
return
}
Expand Down

0 comments on commit 62cfb5f

Please sign in to comment.