Skip to content

Commit

Permalink
Merge pull request #3851 from airqo-platform/staging
Browse files Browse the repository at this point in the history
move to production
  • Loading branch information
Baalmart authored Nov 15, 2024
2 parents 23d4fda + 25dce4c commit 6468ba0
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 61 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-c1581d38-1731588486
tag: prod-23d4fdac-1731654380
api:
name: airqo-analytics-api
label: analytics-api
Expand Down
2 changes: 1 addition & 1 deletion k8s/auth-service/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-auth-api
tag: prod-c1581d38-1731588486
tag: prod-23d4fdac-1731654380
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
4 changes: 2 additions & 2 deletions k8s/calibrate/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ app:
initContainer:
image:
repository: eu.gcr.io/airqo-250220/airqo-calibrate-pickle-file
tag: prod-c1581d38-1731588486
tag: prod-23d4fdac-1731654380
replicaCount: 3
image:
repository: eu.gcr.io/airqo-250220/airqo-calibrate-api
tag: prod-c1581d38-1731588486
tag: prod-23d4fdac-1731654380
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
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-c1581d38-1731588486
tag: prod-23d4fdac-1731654380
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-d40838b5-1731501583
tag: stage-7f82e957-1731690079
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-c1581d38-1731588486
tag: prod-23d4fdac-1731654380
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-c1581d38-1731588486
tag: prod-23d4fdac-1731654380
nameOverride: ''
fullnameOverride: ''
2 changes: 1 addition & 1 deletion k8s/locate/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-locate-api
tag: prod-c1581d38-1731588486
tag: prod-23d4fdac-1731654380
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
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-c1581d38-1731588486
tag: prod-23d4fdac-1731654380
api:
name: airqo-prediction-api
label: prediction-api
Expand Down
110 changes: 59 additions & 51 deletions src/device-registry/models/Site.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const siteSchema = new Schema(
trim: true,
unique: true,
required: [true, "generated name is required!"],
immutable: true,
},
airqloud_id: {
type: ObjectId,
Expand All @@ -112,6 +113,7 @@ const siteSchema = new Schema(
trim: true,
unique: true,
required: [true, "lat_long is required!"],
immutable: true,
},
description: {
type: String,
Expand All @@ -127,6 +129,7 @@ const siteSchema = new Schema(
latitude: {
type: Number,
required: [true, "latitude is required!"],
immutable: true,
},
approximate_latitude: {
type: Number,
Expand All @@ -135,6 +138,7 @@ const siteSchema = new Schema(
longitude: {
type: Number,
required: [true, "longitude is required!"],
immutable: true,
},
approximate_longitude: {
type: Number,
Expand Down Expand Up @@ -360,60 +364,64 @@ const siteSchema = new Schema(
}
);

siteSchema.post("save", async function(doc) {});

siteSchema.pre("save", function(next) {
if (this.isModified("latitude")) {
delete this.latitude;
}
if (this.isModified("longitude")) {
delete this.longitude;
}
if (this.isModified("_id")) {
delete this._id;
}
if (this.isModified("generated_name")) {
delete this.generated_name;
}

this.site_codes = [this._id, this.name, this.generated_name, this.lat_long];
if (this.search_name) {
this.site_codes.push(this.search_name);
}
if (this.location_name) {
this.site_codes.push(this.location_name);
}
if (this.formatted_name) {
this.site_codes.push(this.formatted_name);
}

// Check for duplicate values in the grids array
const duplicateValues = this.grids.filter(
(value, index, self) => self.indexOf(value) !== index
);
if (duplicateValues.length > 0) {
const error = new Error("Duplicate values found in grids array.");
return next(error);
}
siteSchema.pre(
["updateOne", "findOneAndUpdate", "updateMany", "update", "save"],
function(next) {
if (this.getUpdate) {
const updates = this.getUpdate();
if (updates) {
if (updates.latitude) delete updates.latitude;
if (updates.longitude) delete updates.longitude;

if (updates.$set) {
if (updates.$set.latitude || updates.$set.longitude) {
return next(
new HttpError(
"Cannot modify latitude or longitude after creation",
httpStatus.BAD_REQUEST,
{
message: "Cannot modify latitude or longitude after creation",
}
)
);
}
delete updates.$set.latitude;
delete updates.$set.longitude;
}

if (updates.$push) {
delete updates.$push.latitude;
delete updates.$push.longitude;
}
}
}

return next();
});
if (this.isNew) {
if (this.isModified("latitude")) delete this.latitude;
if (this.isModified("longitude")) delete this.longitude;
if (this.isModified("_id")) delete this._id;
if (this.isModified("generated_name")) delete this.generated_name;
this.site_codes = [
this._id,
this.name,
this.generated_name,
this.lat_long,
];
if (this.search_name) this.site_codes.push(this.search_name);
if (this.location_name) this.site_codes.push(this.location_name);
if (this.formatted_name) this.site_codes.push(this.formatted_name);

const duplicateValues = this.grids.filter(
(value, index, self) => self.indexOf(value) !== index
);
if (duplicateValues.length > 0) {
return next(new Error("Duplicate values found in grids array."));
}
}

siteSchema.pre("update", function(next) {
if (this.isModified("latitude")) {
delete this.latitude;
next();
}
if (this.isModified("longitude")) {
delete this.longitude;
}
if (this.isModified("_id")) {
delete this._id;
}
if (this.isModified("generated_name")) {
delete this.generated_name;
}
return next();
});
);

siteSchema.index({ lat_long: 1 }, { unique: true });
siteSchema.index({ generated_name: 1 }, { unique: true });
Expand Down

0 comments on commit 6468ba0

Please sign in to comment.