add route, controller and DB methods for updating status page
This commit is contained in:
1 parent
ff47af95fa
commit
76b21f1d8c
4 files changed
+60
-2
No files matched your search
@@ -33,6 +33,26 @@ class StatusPageController {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
updateStatusPage = async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
await createStatusPageBodyValidation.validateAsync(req.body);
|
||||||
|
await imageValidation.validateAsync(req.file);
|
||||||
|
} catch (error) {
|
||||||
|
next(handleValidationError(error, SERVICE_NAME));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const statusPage = await this.db.updateStatusPage(req.body, req.file);
|
||||||
|
return res.success({
|
||||||
|
msg: successMessages.STATUS_PAGE_UPDATE,
|
||||||
|
data: statusPage,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
next(handleError(error, SERVICE_NAME, "updateStatusPage"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
getStatusPage = async (req, res, next) => {
|
getStatusPage = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const statusPage = await this.db.getStatusPage();
|
const statusPage = await this.db.getStatusPage();
|
||||||
|
|||||||
@@ -27,6 +27,26 @@ const createStatusPage = async (statusPageData, image) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateStatusPage = async (statusPageData, image) => {
|
||||||
|
try {
|
||||||
|
if (image) {
|
||||||
|
statusPageData.logo = {
|
||||||
|
data: image.buffer,
|
||||||
|
contentType: image.mimetype,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const statusPage = await StatusPage.findOneAndUpdate({}, statusPageData, {
|
||||||
|
new: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
return statusPage;
|
||||||
|
} catch (error) {
|
||||||
|
error.service = SERVICE_NAME;
|
||||||
|
error.method = "updateStatusPage";
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getStatusPage = async () => {
|
const getStatusPage = async () => {
|
||||||
try {
|
try {
|
||||||
const statusPageQuery = await StatusPage.aggregate([
|
const statusPageQuery = await StatusPage.aggregate([
|
||||||
@@ -79,7 +99,18 @@ const getStatusPage = async () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
$project: {
|
$project: {
|
||||||
statusPage: 1,
|
statusPage: {
|
||||||
|
_id: 1,
|
||||||
|
color: 1,
|
||||||
|
companyName: 1,
|
||||||
|
isPublished: 1,
|
||||||
|
logo: 1,
|
||||||
|
originalMonitors: 1,
|
||||||
|
showCharts: 1,
|
||||||
|
showUptimePercentage: 1,
|
||||||
|
timezone: 1,
|
||||||
|
url: 1,
|
||||||
|
},
|
||||||
monitors: {
|
monitors: {
|
||||||
$sortArray: {
|
$sortArray: {
|
||||||
input: "$monitors",
|
input: "$monitors",
|
||||||
@@ -122,4 +153,4 @@ const deleteStatusPage = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export { createStatusPage, getStatusPage, deleteStatusPage };
|
export { createStatusPage, updateStatusPage, getStatusPage, deleteStatusPage };
|
||||||
@@ -18,6 +18,12 @@ class StatusPageRoutes {
|
|||||||
verifyJWT,
|
verifyJWT,
|
||||||
this.statusPageController.createStatusPage
|
this.statusPageController.createStatusPage
|
||||||
);
|
);
|
||||||
|
this.router.put(
|
||||||
|
"/",
|
||||||
|
upload.single("logo"),
|
||||||
|
verifyJWT,
|
||||||
|
this.statusPageController.updateStatusPage
|
||||||
|
);
|
||||||
this.router.delete("/", verifyJWT, this.statusPageController.deleteStatusPage);
|
this.router.delete("/", verifyJWT, this.statusPageController.deleteStatusPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -137,6 +137,7 @@ const successMessages = {
|
|||||||
STATUS_PAGE_BY_URL: "Got status page by url successfully",
|
STATUS_PAGE_BY_URL: "Got status page by url successfully",
|
||||||
STATUS_PAGE_CREATE: "Status page created successfully",
|
STATUS_PAGE_CREATE: "Status page created successfully",
|
||||||
STATUS_PAGE_DELETE: "Status page deleted successfully",
|
STATUS_PAGE_DELETE: "Status page deleted successfully",
|
||||||
|
STATUS_PAGE_UPDATE: "Status page updated successfully",
|
||||||
// Docker
|
// Docker
|
||||||
DOCKER_SUCCESS: "Docker container status fetched successfully",
|
DOCKER_SUCCESS: "Docker container status fetched successfully",
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user