mirror of
				https://github.com/smyalygames/checklist-tester.git
				synced 2025-11-04 04:49:49 +01:00 
			
		
		
		
	fix(connector): id not being fetched from database after insert
This commit is contained in:
		
							parent
							
								
									2efc105ef2
								
							
						
					
					
						commit
						c615149624
					
				@ -4,7 +4,6 @@ import io.anthonyberg.connector.shared.database.ActionResultDatabase
 | 
			
		||||
import io.anthonyberg.connector.shared.database.DriverFactory
 | 
			
		||||
import io.anthonyberg.connector.shared.database.TestDatabase
 | 
			
		||||
import kotlinx.datetime.Clock
 | 
			
		||||
import kotlinx.datetime.Instant
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Database transactions for testing procedures
 | 
			
		||||
@ -35,15 +34,11 @@ class TestTransaction (driverFactory: DriverFactory) {
 | 
			
		||||
     * Tells the database that the test has ended
 | 
			
		||||
     *
 | 
			
		||||
     * @param id ID of the Test
 | 
			
		||||
     *
 | 
			
		||||
     * @return The final time for when the test ended
 | 
			
		||||
     */
 | 
			
		||||
    fun endTest(id: Int): Instant {
 | 
			
		||||
    fun endTest(id: Int) {
 | 
			
		||||
        val currentTime = Clock.System.now()
 | 
			
		||||
 | 
			
		||||
        testDb.endTest(testId = id.toLong(), endUTC = currentTime.toString())
 | 
			
		||||
 | 
			
		||||
        return currentTime
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -72,10 +67,8 @@ class TestTransaction (driverFactory: DriverFactory) {
 | 
			
		||||
     * Tells the database that the test has ended and adds the final state
 | 
			
		||||
     *
 | 
			
		||||
     * @param id ID of the ActionResult
 | 
			
		||||
     *
 | 
			
		||||
     * @return The time for when the test for the specific action finished
 | 
			
		||||
     */
 | 
			
		||||
    fun finishAction(id: Int, endState: String): Instant {
 | 
			
		||||
    fun finishAction(id: Int, endState: String) {
 | 
			
		||||
        val currentTime = Clock.System.now()
 | 
			
		||||
 | 
			
		||||
        actionResultDb.finishResult(
 | 
			
		||||
@ -83,7 +76,5 @@ class TestTransaction (driverFactory: DriverFactory) {
 | 
			
		||||
            endState = endState,
 | 
			
		||||
            endUTC = currentTime.toString()
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        return currentTime
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -15,14 +15,18 @@ internal class ActionResultDatabase (driverFactory: DriverFactory) {
 | 
			
		||||
        initState: String,
 | 
			
		||||
        startUTC: String
 | 
			
		||||
    ): Long {
 | 
			
		||||
        dbQuery.startResult(
 | 
			
		||||
            testId = testId,
 | 
			
		||||
            actionId = actionId,
 | 
			
		||||
            initState = initState,
 | 
			
		||||
            startUTC = startUTC
 | 
			
		||||
        )
 | 
			
		||||
        val id = dbQuery.transactionWithResult {
 | 
			
		||||
            dbQuery.startResult(
 | 
			
		||||
                testId = testId,
 | 
			
		||||
                actionId = actionId,
 | 
			
		||||
                initState = initState,
 | 
			
		||||
                startUTC = startUTC
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
        return dbQuery.lastInsertedRowId().executeAsOne()
 | 
			
		||||
            dbQuery.lastInsertedRowId().executeAsOne()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return id
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -10,12 +10,15 @@ internal class TestDatabase (driverFactory: DriverFactory) {
 | 
			
		||||
     * @return ID of the Test created
 | 
			
		||||
     */
 | 
			
		||||
    internal fun startTest(procedureId: Long, startUTC: String) : Long {
 | 
			
		||||
        dbQuery.startTest(
 | 
			
		||||
            procedureId = procedureId,
 | 
			
		||||
            startUTC = startUTC,
 | 
			
		||||
        )
 | 
			
		||||
        val id = dbQuery.transactionWithResult {
 | 
			
		||||
            dbQuery.startTest(
 | 
			
		||||
                procedureId = procedureId,
 | 
			
		||||
                startUTC = startUTC,
 | 
			
		||||
            )
 | 
			
		||||
            dbQuery.lastInsertedRowId().executeAsOne()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return dbQuery.lastInsertedRowId().executeAsOne()
 | 
			
		||||
        return id
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user