Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend Release to Main [1.97] #1086

Merged
merged 7 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Check mark: ✅
Cross Mark: ❌

# createPopupEditorBackup

> ## Positive case
1. ✅ Receives a POST request in the **/api/backup/popupeditors/** route.
2. ✅ Return 201 if create new popup successfully.

> ## Negative case
1. ✅ Returns 403 when no permission.
2. ✅ Returns 400 when missing popupName, popupContent.
3. ✅ Returns 500 when any error in saving.

> ## Edge case
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Check mark: ✅
Cross Mark: ❌

# getAllPopupEditorBackups

> ## Positive case
1. ✅ Receives a GET request in the **/api/backup/popupeditors/** route.
2. ✅ Return 200 if get all ppopup editor backup successfully.

> ## Negative case
1. ✅ Returns 400 when catching any error in finding.

> ## Edge case
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Check mark: ✅
Cross Mark: ❌

# getPopupEditorBackupById

> ## Positive case
1. ✅ Receives a GET request in the **/api/backup/popupeditor/:id** route.
2. ✅ Return 200 if get get PopupEditor Backup ById successfully.

> ## Negative case
1. ✅ Returns 404 when catching any error in finding by id.

> ## Edge case
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Check mark: ✅
Cross Mark: ❌

# updatePopupEditorBackup

> ## Positive case
1. ✅ Receives a POST request in the **/backup/popupeditor/:id** route.
2. ✅ Return 201 if find popup and update popup successfully.
3. ✅ Return 201 if no find and update popup successfully.

> ## Negative case
1. ✅ Returns 403 when no permission.
2. ✅ Returns 400 when missing popupName, popupContent.
3. ✅ Returns 500 when any error in finding.
4. ✅ Returns 500 when any error in saving.

> ## Edge case
41 changes: 19 additions & 22 deletions src/controllers/popupEditorBackupController.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
const { hasPermission } = require('../utilities/permissions');
const helper = require('../utilities/permissions');

const popupEditorBackupController = function (PopupEditorBackups) {
const getAllPopupEditorBackups = function (req, res) {
PopupEditorBackups.find()
.then(results => res.status(200).send(results))
.catch(error => res.status(404).send(error));
.then((results) => res.status(200).send(results))
.catch((error) => res.status(404).send(error));
};

const getPopupEditorBackupById = function (req, res) {
const getPopupEditorBackupById = async function (req, res) {
const popupId = req.params.id;
try {
PopupEditorBackups.find({ popupId: { $in: popupId } }, (error, popupBackup) => {
res.status(200).send(popupBackup[0]);
});
const popupBackup = await PopupEditorBackups.findById(popupId);
res.status(200).send(popupBackup);
} catch (error) {
res.status(404).send(error);
}
};

const createPopupEditorBackup = async function (req, res) {
if (!await hasPermission(req.body.requestor, 'createPopup')) {
res
.status(403)
.send({ error: 'You are not authorized to create new popup' });
if (!(await helper.hasPermission(req.body.requestor, 'createPopup'))) {
res.status(403).send({ error: 'You are not authorized to create new popup' });
return;
}

Expand All @@ -38,16 +35,15 @@ const popupEditorBackupController = function (PopupEditorBackups) {
popup.popupName = req.body.popupName;
popup.popupContent = req.body.popupContent;

popup.save()
.then(results => res.status(201).send(results))
.catch(error => res.status(500).send({ error }));
popup
.save()
.then((results) => res.status(201).send(results))
.catch((error) => res.status(500).send({ error }));
};

const updatePopupEditorBackup = async function (req, res) {
if (!await hasPermission(req.body.requestor, 'updatePopup')) {
res
.status(403)
.send({ error: 'You are not authorized to create new popup' });
if (!(await helper.hasPermission(req.body.requestor, 'updatePopup'))) {
res.status(403).send({ error: 'You are not authorized to create new popup' });
return;
}

Expand All @@ -64,15 +60,16 @@ const popupEditorBackupController = function (PopupEditorBackups) {
PopupEditorBackups.find({ popupId: { $in: popupId } }, (error, popupBackup) => {
if (popupBackup.length > 0) {
popupBackup[0].popupContent = req.body.popupContent;
popupBackup[0].save().then(results => res.status(201).send(results));
popupBackup[0].save().then((results) => res.status(201).send(results));
} else {
const popup = new PopupEditorBackups();
popup.popupId = req.params.id;
popup.popupContent = req.body.popupContent;
popup.popupName = req.body.popupName;
popup.save()
.then(results => res.status(201).send(results))
.catch(err => res.status(500).send({ err }));
popup
.save()
.then((results) => res.status(201).send(results))
.catch((err) => res.status(500).send({ err }));
}
});
} catch (error) {
Expand Down
Loading
Loading