Skip to content

Commit

Permalink
Merge pull request #4036 from airqo-platform/staging
Browse files Browse the repository at this point in the history
move to production
  • Loading branch information
Baalmart authored Dec 10, 2024
2 parents ee15b95 + c1e369b commit ae2e15a
Show file tree
Hide file tree
Showing 26 changed files with 357 additions and 98 deletions.
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-aa6aa4ba-1733753092
tag: prod-ee15b958-1733833086
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-03a25cf1-1733249950
tag: prod-ee15b958-1733833086
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-1838aa7a-1733249623
tag: stage-dfe6eb16-1733832983
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-aa6aa4ba-1733753092
tag: prod-ee15b958-1733833086
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-aa6aa4ba-1733753092
tag: prod-ee15b958-1733833086
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-aa6aa4ba-1733753092
tag: prod-ee15b958-1733833086
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-aa6aa4ba-1733753092
tag: prod-ee15b958-1733833086
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-aa6aa4ba-1733753092
tag: prod-ee15b958-1733833086
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
2 changes: 1 addition & 1 deletion k8s/website/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-website-api
tag: stage-ac4d3c16-1733830718
tag: stage-7a1d5dd3-1733836788
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-aa6aa4ba-1733753092
tag: prod-ee15b958-1733833086
nameOverride: ''
fullnameOverride: ''
podAnnotations: {}
Expand Down
12 changes: 6 additions & 6 deletions src/device-registry/config/global/db-projections.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const dbProjections = {
lat_long: 1,
country: 1,
network: 1,
group: 1,
groups: 1,
data_provider: 1,
district: 1,
sub_county: 1,
Expand Down Expand Up @@ -379,7 +379,7 @@ const dbProjections = {
mobility: 1,
status: 1,
network: 1,
group: 1,
groups: 1,
api_code: 1,
serial_number: 1,
authRequired: 1,
Expand Down Expand Up @@ -591,7 +591,7 @@ const dbProjections = {
shape: 1,
createdAt: 1,
network: 1,
group: 1,
groups: 1,
sites: "$sites",
numberOfSites: {
$cond: {
Expand Down Expand Up @@ -675,7 +675,7 @@ const dbProjections = {
name: 1,
description: 1,
cohort_tags: 1,
group: 1,
groups: 1,
createdAt: 1,
visibility: 1,
cohort_codes: 1,
Expand Down Expand Up @@ -817,7 +817,7 @@ const dbProjections = {
airqloud_tags: 1,
isCustom: 1,
network: 1,
group: 1,
groups: 1,
metadata: 1,
center_point: 1,
sites: "$sites",
Expand Down Expand Up @@ -1065,7 +1065,7 @@ const dbProjections = {
date: 1,
description: 1,
network: 1,
group: 1,
groups: 1,
activityType: 1,
maintenanceType: 1,
recallType: 1,
Expand Down
6 changes: 3 additions & 3 deletions src/device-registry/models/Activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const activitySchema = new Schema(
type: String,
trim: true,
},
group: {
type: String,
groups: {
type: [String],
trim: true,
},
activityType: { type: String, trim: true },
Expand Down Expand Up @@ -70,7 +70,7 @@ activitySchema.methods = {
_id: this._id,
device: this.device,
network: this.network,
group: this.group,
groups: this.groups,
date: this.date,
description: this.description,
activityType: this.activityType,
Expand Down
6 changes: 3 additions & 3 deletions src/device-registry/models/Airqloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ const airqloudSchema = new Schema(
type: String,
trim: true,
},
group: {
type: String,
groups: {
type: [String],
trim: true,
},
airqloud_tags: {
Expand Down Expand Up @@ -152,7 +152,7 @@ airqloudSchema.methods.toJSON = function() {
name: this.name,
long_name: this.long_name,
network: this.network,
group: this.group,
groups: this.groups,
description: this.description,
airqloud_tags: this.airqloud_tags,
admin_level: this.admin_level,
Expand Down
18 changes: 9 additions & 9 deletions src/device-registry/models/Cohort.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const cohortSchema = new Schema(
trim: true,
required: [true, "the network is required!"],
},
group: {
type: String,
groups: {
type: [String],
trim: true,
},
name: {
Expand Down Expand Up @@ -81,7 +81,7 @@ cohortSchema.methods.toJSON = function() {
cohort_tags,
cohort_codes,
network,
group,
groups,
visibility,
} = this;
return {
Expand All @@ -92,7 +92,7 @@ cohortSchema.methods.toJSON = function() {
cohort_tags,
cohort_codes,
network,
group,
groups,
};
};

Expand Down Expand Up @@ -202,7 +202,7 @@ cohortSchema.statics.list = async function(
name: 1,
createdAt: 1,
network: 1,
group: 1,
groups: 1,
devices: {
$cond: {
if: { $eq: [{ $size: "$devices" }, 0] },
Expand All @@ -214,15 +214,15 @@ cohortSchema.statics.list = async function(
.sort({ createdAt: -1 })
.project(inclusionProjection)
.project(exclusionProjection)
.group({
.groups({
_id: "$_id",
visibility: { $first: "$visibility" },
cohort_tags: { $first: "$cohort_tags" },
cohort_codes: { $first: "$cohort_codes" },
name: { $first: "$name" },
createdAt: { $first: "$createdAt" },
network: { $first: "$network" },
group: { $first: "$group" },
groups: { $first: "$groups" },
devices: { $first: "$devices" },
})
.skip(skip ? parseInt(skip) : 0)
Expand All @@ -240,7 +240,7 @@ cohortSchema.statics.list = async function(
name: cohort.name,
network: cohort.network,
createdAt: cohort.createdAt,
group: cohort.group,
groups: cohort.groups,
numberOfDevices: cohort.devices ? cohort.devices.length : 0,
devices: cohort.devices
? cohort.devices
Expand All @@ -250,7 +250,7 @@ cohortSchema.statics.list = async function(
status: device.status,
name: device.name,
network: device.network,
group: device.group,
groups: device.groups,
device_number: device.device_number,
description: device.description,
long_name: device.long_name,
Expand Down
76 changes: 40 additions & 36 deletions src/device-registry/models/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ const deviceSchema = new mongoose.Schema(
trim: true,
required: [true, "the network is required!"],
},
group: {
type: String,
groups: {
type: [String],
trim: true,
},
serial_number: {
Expand Down Expand Up @@ -237,6 +237,20 @@ deviceSchema.plugin(uniqueValidator, {
message: `{VALUE} must be unique!`,
});

const checkDuplicates = (arr, fieldName) => {
const duplicateValues = arr.filter(
(value, index, self) => self.indexOf(value) !== index
);

if (duplicateValues.length > 0) {
return new HttpError(
`Duplicate values found in ${fieldName} array.`,
httpStatus.BAD_REQUEST
);
}
return null;
};

deviceSchema.pre(
[
"update",
Expand Down Expand Up @@ -326,18 +340,16 @@ deviceSchema.pre(
this.device_codes.push(this.serial_number);
}

// Check for duplicate values in cohorts array
const duplicateValues = this.cohorts.filter(
(value, index, self) => self.indexOf(value) !== index
);
// Check for duplicates in cohorts
const cohortsDuplicateError = checkDuplicates(this.cohorts, "cohorts");
if (cohortsDuplicateError) {
return next(cohortsDuplicateError);
}

if (duplicateValues.length > 0) {
return next(
new HttpError(
"Duplicate values found in cohorts array.",
httpStatus.BAD_REQUEST
)
);
// Check for duplicates in groups
const groupsDuplicateError = checkDuplicates(this.groups, "groups");
if (groupsDuplicateError) {
return next(groupsDuplicateError);
}
}

Expand Down Expand Up @@ -371,28 +383,20 @@ deviceSchema.pre(
updateData.access_code = access_code.toUpperCase();
}

// Handle $addToSet for device_codes, previous_sites, and pictures
const addToSetUpdates = {};

if (updateData.device_codes) {
addToSetUpdates.device_codes = { $each: updateData.device_codes };
delete updateData.device_codes; // Remove from main update object
}

if (updateData.previous_sites) {
addToSetUpdates.previous_sites = { $each: updateData.previous_sites };
delete updateData.previous_sites; // Remove from main update object
}

if (updateData.pictures) {
addToSetUpdates.pictures = { $each: updateData.pictures };
delete updateData.pictures; // Remove from main update object
}

// If there are any $addToSet updates, merge them into the main update object
if (Object.keys(addToSetUpdates).length > 0) {
updateData.$addToSet = addToSetUpdates;
}
// Handle array fields using $addToSet
const arrayFieldsToAddToSet = [
"device_codes",
"previous_sites",
"groups",
"pictures",
];
arrayFieldsToAddToSet.forEach((field) => {
if (updateData[field]) {
updateData.$addToSet = updateData.$addToSet || {};
updateData.$addToSet[field] = { $each: updateData[field] };
delete updateData[field];
}
});

next();
} catch (error) {
Expand All @@ -415,7 +419,7 @@ deviceSchema.methods = {
alias: this.alias,
mobility: this.mobility,
network: this.network,
group: this.group,
groups: this.groups,
api_code: this.api_code,
serial_number: this.serial_number,
authRequired: this.authRequired,
Expand Down
8 changes: 4 additions & 4 deletions src/device-registry/models/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const gridSchema = new Schema(
trim: true,
required: [true, "the network is required!"],
},
group: {
type: String,
groups: {
type: [String],
trim: true,
},
geoHash: {
Expand Down Expand Up @@ -121,7 +121,7 @@ gridSchema.methods.toJSON = function() {
name,
long_name,
network,
group,
groups,
visibility,
description,
grid_tags,
Expand All @@ -139,7 +139,7 @@ gridSchema.methods.toJSON = function() {
description,
grid_tags,
network,
group,
groups,
admin_level,
grid_codes,
centers,
Expand Down
Loading

0 comments on commit ae2e15a

Please sign in to comment.