Clear "Untitled" names

pull/256/head
Candid Dauth 2023-11-15 14:59:34 +01:00
rodzic e6d612f772
commit d8c79e950c
2 zmienionych plików z 24 dodań i 3 usunięć

Wyświetl plik

@ -7,6 +7,14 @@ interface MetaModel extends Model<InferAttributes<MetaModel>, InferCreationAttri
value: string;
}
export interface MetaProperties {
dropdownKeysMigrated: "1";
hasElevation: "1";
hasLegendOption: "1";
hasBboxes: "1";
untitledMigrationCompleted: "1";
}
export default class DatabaseMeta {
MetaModel = createModel<MetaModel>();
@ -25,12 +33,12 @@ export default class DatabaseMeta {
});
}
async getMeta(key: string): Promise<string | undefined> {
async getMeta<K extends keyof MetaProperties>(key: K): Promise<MetaProperties[K] | undefined> {
const entry = await this.MetaModel.findOne({ where: { key } });
return entry?.value ?? undefined;
return entry?.value ?? undefined as any;
}
async setMeta(key: string, value: string): Promise<void> {
async setMeta<K extends keyof MetaProperties>(key: K, value: MetaProperties[K]): Promise<void> {
await this.MetaModel.upsert({key, value});
}

Wyświetl plik

@ -23,6 +23,7 @@ export default class DatabaseMigrations {
await this._legendMigration();
await this._bboxMigration();
await this._spatialMigration();
await this._untitledMigration();
}
@ -420,4 +421,16 @@ export default class DatabaseMigrations {
}
}
/** Clear "Untitled marker", "Untitled line" and "New FacilMap" names. These are now rendered in the frontend instead. */
async _untitledMigration() {
if(await this._db.meta.getMeta("untitledMigrationCompleted") == "1")
return;
await this._db.markers.MarkerModel.update({ name: "" }, { where: { name: "Untitled marker" } });
await this._db.lines.LineModel.update({ name: "" }, { where: { name: "Untitled line" } });
await this._db.pads.PadModel.update({ name: "" }, { where: { name: "New FacilMap" } });
await this._db.meta.setMeta("untitledMigrationCompleted", "1");
}
}