Skip to content

Commit

Permalink
fix spaces server/api/controller/alert.js
Browse files Browse the repository at this point in the history
  • Loading branch information
nullhexcode committed Dec 26, 2023
1 parent d78d4f5 commit 39ace23
Showing 1 changed file with 57 additions and 57 deletions.
114 changes: 57 additions & 57 deletions server/api/controller/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,70 @@ const alertChecker = require('../utils/alertChecker');
const alertCheckerUpdate = require('../utils/alertCheckerUpdate');

class AlertController extends Controller {
async create(req, res, next) {
await alertChecker(req);
async create(req, res, next) {
await alertChecker(req);

return super.create(req, res, next).then(savedAlert => {
Email.newAlert(req.session.person, savedAlert)
.then(() => savedAlert)
.catch(err => console.error(err));
// console.log('email sent');
alertCheckerUpdate(req);
});
}

update(req, res) {
return super.update(req, res).then(() => {
alertCheckerUpdate(req);
});
}
return super.create(req, res, next).then(savedAlert => {
Email.newAlert(req.session.person, savedAlert)
.then(() => savedAlert)
.catch(err => console.error(err));
// console.log('email sent');
alertCheckerUpdate(req);
});
}

delete(req, transaction) {
return super.delete(req, transaction).then(deletedAlert => {
alertCheckerUpdate(deletedAlert);
});
}
update(req, res) {
return super.update(req, res).then(() => {
alertCheckerUpdate(req);
});
}

/**
* Return person's alerts. Must be logged in.
* @param {IncomingRequest} req
*/
browse(req) {
if (!req.session.person) {
throw new Exception.NotAllowed('Must be logged in');
delete(req, transaction) {
return super.delete(req, transaction).then(deletedAlert => {
alertCheckerUpdate(deletedAlert);
});
}
return this.model
.query('where', 'person_id', '=', req.session.person.id)
.fetchAll()
.then(collection => {
Log.debug(this.tableName, 'browse success user', req.session.person.id);
return collection;
});
}

/**
* Unsubscribe from alert by token, when clicking an unsubscribe
* link in an email
* @param {IncomingRequest} req
*/
unsubscribe(req) {
return Alert.ByToken(req.params.token)
.fetch()
.then(fetchedModel => {
if (!fetchedModel) {
// return successfully even if alert was not found since
// it is probably already unsubscribed
return null;
/**
* Return person's alerts. Must be logged in.
* @param {IncomingRequest} req
*/
browse(req) {
if (!req.session.person) {
throw new Exception.NotAllowed('Must be logged in');
}
return this.model
.query('where', 'person_id', '=', req.session.person.id)
.fetchAll()
.then((collection) => {
Log.debug(this.tableName, 'browse success user', req.session.person.id);
return collection;
});
}

/**
* Unsubscribe from alert by token, when clicking an unsubscribe
* link in an email
* @param {IncomingRequest} req
*/
unsubscribe(req) {
return Alert.ByToken(req.params.token)
.fetch()
.then((fetchedModel) => {
if (!fetchedModel) {
// return successfully even if alert was not found since
// it is probably already unsubscribed
return null;
}

Log.debug(
this.tableName,
'unsubscribe success id:',
fetchedModel.get('id'),
);
return fetchedModel.destroy();
});
}
Log.debug(
this.tableName,
'unsubscribe success id:',
fetchedModel.get('id')
);
return fetchedModel.destroy();
});
}
}

module.exports = new AlertController(Alert);

0 comments on commit 39ace23

Please sign in to comment.