a lot of refactos
This commit is contained in:
+50
-16
@@ -58,14 +58,14 @@ export class SimRepository {
|
||||
if(!isValidUuid(simulationUuid)) return({ ok: false, err: 'Invalid simulation UUID' })
|
||||
|
||||
const rows = await MySQLClient.poolExecute(this.db, `
|
||||
SELECT s.sim_id,
|
||||
BIN_TO_UUID(s.sim_uuid) AS sim_uuid,
|
||||
BIN_TO_UUID(s.sim_root_kf_uuid) AS sim_root_kf_uuid
|
||||
FROM ${this.#qualify(this.simDb, 'simulations')} s
|
||||
INNER JOIN ${this.#qualify(this.guiDb, 'simowners')} o ON o.own_sim_uuid = s.sim_uuid
|
||||
INNER JOIN ${this.#qualify(this.guiDb, 'users')} u ON o.own_usr_id = u.usr_id
|
||||
WHERE u.usr_uuid = ?
|
||||
AND s.sim_uuid = UUID_TO_BIN(?)
|
||||
SELECT sim_id,
|
||||
BIN_TO_UUID(sim_uuid) AS sim_uuid,
|
||||
BIN_TO_UUID(sim_root_kf_uuid) AS sim_root_kf_uuid
|
||||
FROM ${this.#qualify(this.simDb, 'simulations')}
|
||||
INNER JOIN ${this.#qualify(this.guiDb, 'simowners')} ON own_sim_uuid = sim_uuid
|
||||
INNER JOIN ${this.#qualify(this.guiDb, 'users')} ON own_usr_id = usr_id
|
||||
WHERE usr_uuid = ?
|
||||
AND sim_uuid = UUID_TO_BIN(?)
|
||||
`, [userUuid, simulationUuid])
|
||||
|
||||
if(!rows.length) return({ ok: false, err: 'Simulation not found or access denied' })
|
||||
@@ -88,20 +88,54 @@ export class SimRepository {
|
||||
if(!isValidUuid(simulationUuid)) return({ ok: false, err: 'Invalid simulation UUID' })
|
||||
|
||||
const rows = await MySQLClient.poolExecute(this.db, `
|
||||
SELECT s.sim_id,
|
||||
BIN_TO_UUID(s.sim_uuid) AS sim_uuid,
|
||||
BIN_TO_UUID(s.sim_root_kf_uuid) AS sim_root_kf_uuid
|
||||
FROM ${this.#qualify(this.simDb, 'simulations')} s
|
||||
INNER JOIN ${this.#qualify(this.guiDb, 'simowners')} o ON o.own_sim_uuid = s.sim_uuid
|
||||
INNER JOIN ${this.#qualify(this.guiDb, 'users')} u ON o.own_usr_id = u.usr_id
|
||||
WHERE u.usr_uuid = ?
|
||||
AND s.sim_uuid = UUID_TO_BIN(?)
|
||||
SELECT sim_id,
|
||||
BIN_TO_UUID(sim_uuid) AS sim_uuid,
|
||||
BIN_TO_UUID(sim_root_kf_uuid) AS sim_root_kf_uuid
|
||||
FROM ${this.#qualify(this.simDb, 'simulations')}
|
||||
INNER JOIN ${this.#qualify(this.guiDb, 'simowners')} ON own_sim_uuid = sim_uuid
|
||||
INNER JOIN ${this.#qualify(this.guiDb, 'users')} ON own_usr_id = usr_id
|
||||
WHERE usr_uuid = ?
|
||||
AND sim_uuid = UUID_TO_BIN(?)
|
||||
`, [userUuid, simulationUuid])
|
||||
|
||||
if(!rows.length) return({ ok: false, err: 'Simulation not found or access denied' })
|
||||
return({ ok: true, sim: rows[0] })
|
||||
}
|
||||
|
||||
async listSimulationOwnerUuids(simulationUuid) {
|
||||
if(!isValidUuid(simulationUuid)) return({ ok: false, err: 'Invalid simulation UUID' })
|
||||
|
||||
const rows = await MySQLClient.poolExecute(this.db, `
|
||||
SELECT BIN_TO_UUID(usr_uuid) AS owner_uuid
|
||||
FROM ${this.#qualify(this.guiDb, 'simowners')}
|
||||
INNER JOIN ${this.#qualify(this.guiDb, 'users')} ON own_usr_id = usr_id
|
||||
WHERE own_sim_uuid = UUID_TO_BIN(?)
|
||||
`, [simulationUuid])
|
||||
|
||||
return({
|
||||
ok: true,
|
||||
ownerUuids: rows.map(row => row.owner_uuid),
|
||||
})
|
||||
}
|
||||
|
||||
async listOwnerSimulations(userUuid) {
|
||||
if(!isValidUuid(userUuid)) return({ ok: false, err: 'Invalid user UUID' })
|
||||
|
||||
const rows = await MySQLClient.poolExecute(this.db, `
|
||||
SELECT BIN_TO_UUID(sim_uuid) AS simulation_id
|
||||
FROM ${this.#qualify(this.simDb, 'simulations')}
|
||||
INNER JOIN ${this.#qualify(this.guiDb, 'simowners')} ON own_sim_uuid = sim_uuid
|
||||
INNER JOIN ${this.#qualify(this.guiDb, 'users')} ON own_usr_id = usr_id
|
||||
WHERE usr_uuid = ?
|
||||
ORDER BY sim_id
|
||||
`, [userUuid])
|
||||
|
||||
return({
|
||||
ok: true,
|
||||
simulationIds: rows.map(row => row.simulation_id),
|
||||
})
|
||||
}
|
||||
|
||||
async loadKeyframeAgents(keyframeId) {
|
||||
const rows = await MySQLClient.poolExecute(this.db, `
|
||||
SELECT BIN_TO_UUID(ekfs_agent_id) AS agent_id,
|
||||
|
||||
Reference in New Issue
Block a user