Skip to content

Commit

Permalink
Merge branch 'staging' into update-fix/Clean_up
Browse files Browse the repository at this point in the history
Updates from airqo staging
  • Loading branch information
NicholasTurner23 committed Dec 12, 2024
2 parents f9559ce + 3b2cde0 commit c50c928
Show file tree
Hide file tree
Showing 14 changed files with 750 additions and 1,043 deletions.
2 changes: 1 addition & 1 deletion k8s/analytics/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ images:
celeryWorker: eu.gcr.io/airqo-250220/airqo-analytics-celery-worker
reportJob: eu.gcr.io/airqo-250220/airqo-analytics-report-job
devicesSummaryJob: eu.gcr.io/airqo-250220/airqo-analytics-devices-summary-job
tag: prod-3cb7d03d-1734014240
tag: prod-48e4e72c-1734023346
api:
name: airqo-analytics-api
label: analytics-api
Expand Down
2 changes: 1 addition & 1 deletion k8s/device-registry/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 3
image:
repository: eu.gcr.io/airqo-250220/airqo-device-registry-api
tag: prod-3cb7d03d-1734014240
tag: prod-48e4e72c-1734023346
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/device-registry/values-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 2
image:
repository: eu.gcr.io/airqo-250220/airqo-stage-device-registry-api
tag: stage-a67d93c7-1733998369
tag: stage-04fa3ebc-1734023297
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/exceedance/values-prod-airqo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ app:
configmap: env-exceedance-production
image:
repository: eu.gcr.io/airqo-250220/airqo-exceedance-job
tag: prod-3cb7d03d-1734014240
tag: prod-48e4e72c-1734023346
nameOverride: ''
fullnameOverride: ''
2 changes: 1 addition & 1 deletion k8s/exceedance/values-prod-kcca.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ app:
configmap: env-exceedance-production
image:
repository: eu.gcr.io/airqo-250220/kcca-exceedance-job
tag: prod-3cb7d03d-1734014240
tag: prod-48e4e72c-1734023346
nameOverride: ''
fullnameOverride: ''
2 changes: 1 addition & 1 deletion k8s/predict/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ images:
predictJob: eu.gcr.io/airqo-250220/airqo-predict-job
trainJob: eu.gcr.io/airqo-250220/airqo-train-job
predictPlaces: eu.gcr.io/airqo-250220/airqo-predict-places-air-quality
tag: prod-3cb7d03d-1734014240
tag: prod-48e4e72c-1734023346
api:
name: airqo-prediction-api
label: prediction-api
Expand Down
2 changes: 1 addition & 1 deletion k8s/spatial/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 3
image:
repository: eu.gcr.io/airqo-250220/airqo-spatial-api
tag: prod-3cb7d03d-1734014240
tag: prod-48e4e72c-1734023346
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/website/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ app:
replicaCount: 3
image:
repository: eu.gcr.io/airqo-250220/airqo-website-api
tag: prod-3cb7d03d-1734014240
tag: prod-48e4e72c-1734023346
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/workflows/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ images:
initContainer: eu.gcr.io/airqo-250220/airqo-workflows-xcom
redisContainer: eu.gcr.io/airqo-250220/airqo-redis
containers: eu.gcr.io/airqo-250220/airqo-workflows
tag: prod-3cb7d03d-1734014240
tag: prod-48e4e72c-1734023346
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
53 changes: 53 additions & 0 deletions src/device-registry/controllers/create-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,59 @@ const manageSite = {
return;
}
},
updateManySites: async (req, res, next) => {
try {
logText("the BULK update operation starts....");
const errors = extractErrorsFromRequest(req);
if (errors) {
next(
new HttpError("bad request errors", httpStatus.BAD_REQUEST, errors)
);
return;
}

const request = req;
const defaultTenant = constants.DEFAULT_TENANT || "airqo";
request.query.tenant = isEmpty(req.query.tenant)
? defaultTenant
: req.query.tenant;

const result = await createSiteUtil.updateManySites(request, next);

if (isEmpty(result) || res.headersSent) {
return;
}

if (result.success === true) {
const status = result.status ? result.status : httpStatus.OK;
return res.status(status).json({
message: result.message,
success: true,
bulk_update_notes: result.data,
metadata: result.metadata,
});
} else if (result.success === false) {
const status = result.status
? result.status
: httpStatus.INTERNAL_SERVER_ERROR;
return res.status(status).json({
message: result.message,
success: false,
errors: result.errors ? result.errors : { message: "" },
});
}
} catch (error) {
logger.error(`🐛🐛 Internal Server Error ${error.message}`);
next(
new HttpError(
"Internal Server Error",
httpStatus.INTERNAL_SERVER_ERROR,
{ message: error.message }
)
);
return;
}
},
refresh: async (req, res, next) => {
try {
logText("refreshing site details................");
Expand Down
64 changes: 64 additions & 0 deletions src/device-registry/models/Site.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ const { getModelByTenant } = require("@config/database");
const log4js = require("log4js");
const logger = log4js.getLogger(`${constants.ENVIRONMENT} -- site-model`);

function sanitizeObject(obj, invalidKeys) {
invalidKeys.forEach((key) => {
if (Object.hasOwn(obj, key)) {
delete obj[key];
}
});
return obj;
}

const categorySchema = new Schema(
{
area_name: { type: String },
Expand Down Expand Up @@ -804,6 +813,61 @@ siteSchema.statics = {
);
}
},
async bulkModify({ filter = {}, update = {}, opts = {} }, next) {
try {
const invalidKeys = [
"_id",
"longitude",
"latitude",
"lat_long",
"generated_name",
];
const sanitizedUpdate = sanitizeObject(update, invalidKeys);

// Perform bulk update with additional options
const bulkUpdateResult = await this.updateMany(
filter,
{ $set: sanitizedUpdate },
{
new: true,
runValidators: true,
...opts,
}
);

if (bulkUpdateResult.nModified > 0) {
return {
success: true,
message: `Successfully modified ${bulkUpdateResult.nModified} sites`,
data: {
modifiedCount: bulkUpdateResult.nModified,
matchedCount: bulkUpdateResult.n,
},
status: httpStatus.OK,
};
} else {
return {
success: true,
message: "No sites were updated",
data: {
modifiedCount: 0,
matchedCount: bulkUpdateResult.n,
},
status: httpStatus.OK,
};
}
} catch (error) {
const stringifiedMessage = JSON.stringify(error ? error : "");
logger.error(`🐛🐛 Bulk Modify Sites Error -- ${stringifiedMessage}`);
next(
new HttpError(
"Internal Server Error",
httpStatus.INTERNAL_SERVER_ERROR,
{ message: error.message }
)
);
}
},
async remove({ filter = {} } = {}, next) {
try {
let options = {
Expand Down
Loading

0 comments on commit c50c928

Please sign in to comment.