fix: title increment based on DB max, not stored template only
Release APK / build (push) Has been cancelled
Release APK / build (push) Has been cancelled
After each incident save, query existing titles with the same prefix to find the real max number, then use max(dbMax, tplNum) + 1. Prevents duplicate counters when incidents were created before the template was configured. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -163,6 +163,20 @@ export async function deleteIncident(id: string): Promise<void> {
|
||||
await db.runAsync("DELETE FROM incidents WHERE id = ?", [id]);
|
||||
}
|
||||
|
||||
export async function getMaxTitleNumber(prefix: string): Promise<number> {
|
||||
const db = await getDb();
|
||||
const rows = await db.getAllAsync<{ title: string }>(
|
||||
"SELECT title FROM incidents WHERE title LIKE ?",
|
||||
[`${prefix}%`]
|
||||
);
|
||||
let max = 0;
|
||||
for (const row of rows) {
|
||||
const n = parseInt(row.title.slice(prefix.length), 10);
|
||||
if (!isNaN(n) && n > max) max = n;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
export async function getDistinctServices(): Promise<string[]> {
|
||||
const db = await getDb();
|
||||
const rows = await db.getAllAsync<{ service: string }>(
|
||||
|
||||
Reference in New Issue
Block a user