Skip to content

Commit

Permalink
merged dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ydahal1 committed Aug 28, 2024
2 parents 420fff0 + b2428d9 commit f5da4d1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ module.exports = {
unique: true,
type: DataTypes.STRING,
},
region: {
allowNull: false,
type: DataTypes.STRING,
},
severityThreshold: {
allowNull: false,
type: DataTypes.INTEGER,
},
severityAlertRecipients: {
allowNull: false,
type: DataTypes.JSON,
},
metaData: {
allowNull: true,
type: DataTypes.JSON,
},
createdAt: {
allowNull: false,
type: DataTypes.DATE,
Expand Down
16 changes: 16 additions & 0 deletions Tombolo/server/models/asr_domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ module.exports = (sequelize, DataTypes) => {
unique: true,
type: DataTypes.STRING,
},
region: {
allowNull: false,
type: DataTypes.STRING,
},
severityThreshold: {
allowNull: false,
type: DataTypes.INTEGER,
},
severityAlertRecipients: {
allowNull: false,
type: DataTypes.JSON,
},
metaData:{
allowNull: true,
type: DataTypes.JSON,
},
createdAt: {
allowNull: false,
type: DataTypes.DATE,
Expand Down
37 changes: 29 additions & 8 deletions Tombolo/server/routes/asr/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const DomainProduct = models.asr_domain_to_products;
// Create a new domain
router.post("/domains/",[
body("name").notEmpty().withMessage("Domain name is required"),
body("region").notEmpty().withMessage("Region is required"),
body("monitoringTypeIds")
.optional()
.isArray()
Expand All @@ -33,10 +34,11 @@ router.post("/domains/",[

/* if monitoring type is provided,
create domain, next iterate over monitoringTypeId and make entry to asr_domain_monitoring_types*/
const { name, monitoringTypeIds, createdBy } = req.body;
const { name, region, severityThreshold, severityAlertRecipients, monitoringTypeIds, createdBy } =
req.body;
let domain;
if (monitoringTypeIds) {
domain = await Domains.create({ name, createdBy });
domain = await Domains.create({ name, region, severityThreshold, severityAlertRecipients, createdBy });

// create domain monitoring type mapping
const createPromises = monitoringTypeIds.map((monitoringId) => {
Expand All @@ -53,7 +55,7 @@ router.post("/domains/",[

// if no monitoring type is provided, create domain without monitoring type
else {
domain = await Domains.create({ name, createdBy });
domain = await Domains.create({ name, region, severityThreshold,severityAlertRecipients, createdBy });
}
res.status(200).json({message: "Domain created successfully", domain});
} catch (error) {
Expand Down Expand Up @@ -125,12 +127,25 @@ router.patch(
}

// Update domain and delete or add relation in the junction table
const { name, monitoringTypeIds, updatedBy } = req.body;
const {
name,
region,
severityThreshold,
severityAlertRecipients,
monitoringTypeIds,
updatedBy,
} = req.body;
let response;
if (monitoringTypeIds) {
response = await sequelize.transaction(async (t) => {
await Domains.update(
{ name, updatedBy },
{
name,
region,
severityThreshold,
severityAlertRecipients,
updatedBy,
},
{ where: { id: req.params.id }, transaction: t }
);

Expand All @@ -156,7 +171,7 @@ router.patch(
});
} else {
response = await Domains.update(
{ name, updatedBy },
{ name, region, severityThreshold, severityAlertRecipients, updatedBy },
{ where: { id: req.params.id } }
);
}
Expand Down Expand Up @@ -251,7 +266,7 @@ router.get("/products/", async(req, res) => {
attributes: [], // Exclude the junction table from the result
},
as: "associatedDomains",
attributes: ["id", "name"],
attributes: ["id", "name", "region", "severityThreshold", "severityAlertRecipients"],
},
],
order: [["createdAt", "DESC"]],
Expand Down Expand Up @@ -403,7 +418,13 @@ router.get("/domainsForSpecificMonitoring/:monitoringTypeId",
include: [
{
model: Domains,
attributes: ["id", "name"],
attributes: [
"id",
"name",
"region",
"severityThreshold",
"severityAlertRecipients",
],
},
],
raw: true,
Expand Down

0 comments on commit f5da4d1

Please sign in to comment.