Fix nulls showing in certificate rows

This commit is contained in:
Jamie Curnow
2026-05-18 15:04:27 +10:00
parent 32a74d9781
commit 1e22574000
+12 -10
View File
@@ -15,6 +15,16 @@ Model.knex(db());
const boolFields = ["is_deleted"]; const boolFields = ["is_deleted"];
const cleanDomainNames = (domainNames) => {
// Sort domain_names
if (typeof domainNames !== "undefined") {
const newDomainNames = domainNames.filter((name) => name !== null);
newDomainNames.sort();
return newDomainNames;
}
return [];
};
class Certificate extends Model { class Certificate extends Model {
$beforeInsert() { $beforeInsert() {
this.created_on = now(); this.created_on = now();
@@ -26,25 +36,17 @@ class Certificate extends Model {
} }
// Default for domain_names // Default for domain_names
if (typeof this.domain_names === "undefined") { this.domain_names = cleanDomainNames(this.domain_names);
this.domain_names = [];
}
// Default for meta // Default for meta
if (typeof this.meta === "undefined") { if (typeof this.meta === "undefined") {
this.meta = {}; this.meta = {};
} }
this.domain_names.sort();
} }
$beforeUpdate() { $beforeUpdate() {
this.modified_on = now(); this.modified_on = now();
this.domain_names = cleanDomainNames(this.domain_names);
// Sort domain_names
if (typeof this.domain_names !== "undefined") {
this.domain_names.sort();
}
} }
$parseDatabaseJson(json) { $parseDatabaseJson(json) {