-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(users, tasks): init data privacy management example ✨
- Loading branch information
1 parent
d315875
commit 58edcab
Showing
7 changed files
with
142 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> | ||
|
||
<head> | ||
<title></title> | ||
</head> | ||
|
||
<body> | ||
<p>Dear {{displayName}},</p> | ||
<p>You have asked to get all your data. We are happy to transfer it to you below, do not hesitate to contact <a href="mailto:{{appContact}}">us</a> if us with any questions.</p> | ||
<p>The {{appName}} Support Team.</p> | ||
<br/> | ||
<i style='color:#9b9b9b'>Please do not reply to this email, you can contact us <a href="mailto:{{appContact}}">here</a>.</i> | ||
<br /> | ||
<pre style='background: #f5f2f0; color:#72972c; padding: 15px; border-radius: 7px;'>{{result}}</pre> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Module dependencies | ||
*/ | ||
const TasksRepository = require('../repositories/tasks.repository'); | ||
|
||
/** | ||
* @desc Function to ask repository to get all task from a specific user | ||
* @param {Object} user | ||
* @return {Promise} user tasks | ||
*/ | ||
exports.userList = async (user) => { | ||
const result = await TasksRepository.userlist(user); | ||
return Promise.resolve(result); | ||
}; | ||
|
||
/** | ||
* @desc Function to ask repository to delete all task from a specific user | ||
* @param {Object} user | ||
* @return {Promise} confirmation of delete | ||
*/ | ||
exports.userDelete = async (user) => { | ||
const result = await TasksRepository.userdelete(user); | ||
return Promise.resolve(result); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Module dependencies | ||
*/ | ||
const path = require('path'); | ||
|
||
const errors = require(path.resolve('./lib/helpers/errors')); | ||
const responses = require(path.resolve('./lib/helpers/responses')); | ||
const mails = require(path.resolve('./lib/helpers/mails')); | ||
const config = require(path.resolve('./config')); | ||
const UserService = require('../services/user.service'); | ||
|
||
|
||
const TaskDataService = require(path.resolve('./modules/tasks/services/tasks.data.service')); | ||
|
||
/** | ||
* @desc Endpoint to ask the service to delete the user connected and all his data | ||
* @param {Object} req - Express request object | ||
* @param {Object} res - Express response object | ||
*/ | ||
exports.delete = async (req, res) => { | ||
try { | ||
const result = { | ||
user: await UserService.delete(req.user), | ||
tasks: await TaskDataService.userDelete(req.user), | ||
}; | ||
result.user.id = req.user.id; | ||
responses.success(res, 'user and his data were deleted')(result); | ||
} catch (err) { | ||
responses.error(res, 422, 'Unprocessable Entity', errors.getMessage(err))(err); | ||
} | ||
}; | ||
|
||
/** | ||
* @desc Endpoint to ask the service to get all user data | ||
* @param {Object} req - Express request object | ||
* @param {Object} res - Express response object | ||
*/ | ||
exports.get = async (req, res) => { | ||
try { | ||
const result = { | ||
user: await UserService.get(req.user), | ||
tasks: await TaskDataService.userList(req.user), | ||
}; | ||
responses.success(res, 'user data')(result); | ||
} catch (err) { | ||
responses.error(res, 422, 'Unprocessable Entity', errors.getMessage(err))(err); | ||
} | ||
}; | ||
|
||
/** | ||
* @desc Endpoint to ask the service to get all user data and send it to user mail | ||
* @param {Object} req - Express request object | ||
* @param {Object} res - Express response object | ||
*/ | ||
exports.getMail = async (req, res) => { | ||
try { | ||
const result = { | ||
user: await UserService.get(req.user), | ||
tasks: await TaskDataService.userList(req.user), | ||
}; | ||
|
||
// send mail | ||
const mail = await mails.sendMail({ | ||
template: 'data-privacy-email', | ||
from: config.mailer.from, | ||
to: req.user.email, | ||
subject: `${config.app.title}: your data`, | ||
params: { | ||
result: JSON.stringify(result), | ||
displayName: `${req.user.firstName} ${req.user.lastName}`, | ||
appName: config.app.title, | ||
appContact: config.app.contact, | ||
}, | ||
}); | ||
|
||
if (!mail.accepted) return responses.error(res, 400, 'Bad Request', 'Failure sending email')(); | ||
responses.success(res, 'An email has been sent to the user email with data')(); | ||
} catch (err) { | ||
responses.error(res, 422, 'Unprocessable Entity', errors.getMessage(err))(err); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters