parent
a5a1c9f793
commit
04a4e6473b
|
|
@ -1,5 +1,4 @@
|
||||||
import { buildBurialSiteName } from '../helpers/burialSites.helpers.js';
|
import { buildBurialSiteName } from '../helpers/burialSites.helpers.js';
|
||||||
import getBurialSites from './getBurialSites.js';
|
|
||||||
import getCemetery from './getCemetery.js';
|
import getCemetery from './getCemetery.js';
|
||||||
import { acquireConnection } from './pool.js';
|
import { acquireConnection } from './pool.js';
|
||||||
export default async function rebuildBurialSiteNames(cemeteryId, user, connectedDatabase) {
|
export default async function rebuildBurialSiteNames(cemeteryId, user, connectedDatabase) {
|
||||||
|
|
@ -14,32 +13,27 @@ export default async function rebuildBurialSiteNames(cemeteryId, user, connected
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*
|
const result = database
|
||||||
* Get the burial sites
|
.function('buildBurialSiteName', buildBurialSiteNameUserFunction)
|
||||||
*/
|
.prepare(`update BurialSites
|
||||||
const burialSites = await getBurialSites({
|
set burialSiteName = buildBurialSiteName(?, burialSiteNameSegment1, burialSiteNameSegment2, burialSiteNameSegment3, burialSiteNameSegment4, burialSiteNameSegment5),
|
||||||
cemeteryId
|
recordUpdate_userName = ?,
|
||||||
}, {
|
recordUpdate_timeMillis = ?
|
||||||
limit: -1,
|
where cemeteryId = ?
|
||||||
offset: 0
|
and recordDelete_timeMillis is null`)
|
||||||
}, database);
|
.run(cemetery.cemeteryKey, user.userName, Date.now(), cemeteryId);
|
||||||
let updateCount = 0;
|
|
||||||
for (const burialSite of burialSites.burialSites) {
|
|
||||||
const burialSiteName = buildBurialSiteName(cemetery.cemeteryKey, burialSite);
|
|
||||||
if (burialSiteName !== burialSite.burialSiteName) {
|
|
||||||
const result = database
|
|
||||||
.prepare(`update BurialSites
|
|
||||||
set burialSiteName = ?,
|
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where burialSiteId = ?
|
|
||||||
and recordDelete_timeMillis is null`)
|
|
||||||
.run(burialSiteName, user.userName, Date.now(), burialSite.burialSiteId);
|
|
||||||
updateCount += result.changes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release();
|
database.release();
|
||||||
}
|
}
|
||||||
return updateCount;
|
return result.changes;
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/max-params
|
||||||
|
function buildBurialSiteNameUserFunction(cemeteryKey, burialSiteNameSegment1, burialSiteNameSegment2, burialSiteNameSegment3, burialSiteNameSegment4, burialSiteNameSegment5) {
|
||||||
|
return buildBurialSiteName(cemeteryKey, {
|
||||||
|
burialSiteNameSegment1,
|
||||||
|
burialSiteNameSegment2,
|
||||||
|
burialSiteNameSegment3,
|
||||||
|
burialSiteNameSegment4,
|
||||||
|
burialSiteNameSegment5
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import type { PoolConnection } from 'better-sqlite-pool'
|
||||||
|
|
||||||
import { buildBurialSiteName } from '../helpers/burialSites.helpers.js'
|
import { buildBurialSiteName } from '../helpers/burialSites.helpers.js'
|
||||||
|
|
||||||
import getBurialSites from './getBurialSites.js'
|
|
||||||
import getCemetery from './getCemetery.js'
|
import getCemetery from './getCemetery.js'
|
||||||
import { acquireConnection } from './pool.js'
|
import { acquireConnection } from './pool.js'
|
||||||
|
|
||||||
|
|
@ -27,44 +26,39 @@ export default async function rebuildBurialSiteNames(
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
const result = database
|
||||||
* Get the burial sites
|
.function('buildBurialSiteName', buildBurialSiteNameUserFunction)
|
||||||
*/
|
.prepare(
|
||||||
|
`update BurialSites
|
||||||
const burialSites = await getBurialSites(
|
set burialSiteName = buildBurialSiteName(?, burialSiteNameSegment1, burialSiteNameSegment2, burialSiteNameSegment3, burialSiteNameSegment4, burialSiteNameSegment5),
|
||||||
{
|
recordUpdate_userName = ?,
|
||||||
cemeteryId
|
recordUpdate_timeMillis = ?
|
||||||
},
|
where cemeteryId = ?
|
||||||
{
|
and recordDelete_timeMillis is null`
|
||||||
limit: -1,
|
)
|
||||||
offset: 0
|
.run(cemetery.cemeteryKey, user.userName, Date.now(), cemeteryId)
|
||||||
},
|
|
||||||
database
|
|
||||||
)
|
|
||||||
|
|
||||||
let updateCount = 0
|
|
||||||
|
|
||||||
for (const burialSite of burialSites.burialSites) {
|
|
||||||
const burialSiteName = buildBurialSiteName(cemetery.cemeteryKey, burialSite)
|
|
||||||
|
|
||||||
if (burialSiteName !== burialSite.burialSiteName) {
|
|
||||||
const result = database
|
|
||||||
.prepare(
|
|
||||||
`update BurialSites
|
|
||||||
set burialSiteName = ?,
|
|
||||||
recordUpdate_userName = ?,
|
|
||||||
recordUpdate_timeMillis = ?
|
|
||||||
where burialSiteId = ?
|
|
||||||
and recordDelete_timeMillis is null`
|
|
||||||
)
|
|
||||||
.run(burialSiteName, user.userName, Date.now(), burialSite.burialSiteId)
|
|
||||||
|
|
||||||
updateCount += result.changes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connectedDatabase === undefined) {
|
if (connectedDatabase === undefined) {
|
||||||
database.release()
|
database.release()
|
||||||
}
|
}
|
||||||
return updateCount
|
|
||||||
|
return result.changes
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/max-params
|
||||||
|
function buildBurialSiteNameUserFunction(
|
||||||
|
cemeteryKey: string,
|
||||||
|
burialSiteNameSegment1: string,
|
||||||
|
burialSiteNameSegment2: string,
|
||||||
|
burialSiteNameSegment3: string,
|
||||||
|
burialSiteNameSegment4: string,
|
||||||
|
burialSiteNameSegment5: string
|
||||||
|
): string {
|
||||||
|
return buildBurialSiteName(cemeteryKey, {
|
||||||
|
burialSiteNameSegment1,
|
||||||
|
burialSiteNameSegment2,
|
||||||
|
burialSiteNameSegment3,
|
||||||
|
burialSiteNameSegment4,
|
||||||
|
burialSiteNameSegment5
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue