bug fixes / dbmapper fixes

This commit is contained in:
Dennis Eichhorn 2021-12-19 20:20:39 +01:00
parent f1e7cac376
commit 9d3a0a7887
4 changed files with 15 additions and 32 deletions

View File

@ -83,19 +83,19 @@ final class EmployeeMapper extends DataMapperFactory
], ],
'companyHistory' => [ 'companyHistory' => [
'mapper' => EmployeeHistoryMapper::class, 'mapper' => EmployeeHistoryMapper::class,
'table' => 'hr_staff_history', // @todo: is this requried? This is stored in the mapper already. In other places I'm not using this, either use it everywhere or nowhere. Using the mapper is slower but protects us from table name changes! 'table' => 'hr_staff_history',
'self' => 'hr_staff_history_staff', 'self' => 'hr_staff_history_staff',
'external' => null, 'external' => null,
], ],
'workHistory' => [ 'workHistory' => [
'mapper' => EmployeeWorkHistoryMapper::class, 'mapper' => EmployeeWorkHistoryMapper::class,
'table' => 'hr_staff_work_history', // @todo: is this requried? This is stored in the mapper already. In other places I'm not using this, either use it everywhere or nowhere. Using the mapper is slower but protects us from table name changes! 'table' => 'hr_staff_work_history',
'self' => 'hr_staff_work_history_staff', 'self' => 'hr_staff_work_history_staff',
'external' => null, 'external' => null,
], ],
'educationHistory' => [ 'educationHistory' => [
'mapper' => EmployeeEducationHistoryMapper::class, 'mapper' => EmployeeEducationHistoryMapper::class,
'table' => 'hr_staff_education_history', // @todo: is this requried? This is stored in the mapper already. In other places I'm not using this, either use it everywhere or nowhere. Using the mapper is slower but protects us from table name changes! 'table' => 'hr_staff_education_history',
'self' => 'hr_staff_education_history_staff', 'self' => 'hr_staff_education_history_staff',
'external' => null, 'external' => null,
], ],
@ -116,21 +116,4 @@ final class EmployeeMapper extends DataMapperFactory
* @since 1.0.0 * @since 1.0.0
*/ */
public const PRIMARYFIELD ='hr_staff_id'; public const PRIMARYFIELD ='hr_staff_id';
/**
* Get the employee from an account
*
* @param int $account Account to get the employee for
*
* @return ReadMapper
*
* @since 1.0.0
*/
public static function getFromAccount(int $account) : ReadMapper
{
return self::get()
->with('profile')
->with('profile/account')
->where('profile/account', $account);
}
} }

View File

@ -48,6 +48,6 @@ final class EmployeeMapperTest extends \PHPUnit\Framework\TestCase
$employeeR = EmployeeMapper::get()->where('id', $employee->getId())->execute(); $employeeR = EmployeeMapper::get()->where('id', $employee->getId())->execute();
self::assertEquals($employee->profile->getId(), $employeeR->profile->getId()); self::assertEquals($employee->profile->getId(), $employeeR->profile->getId());
self::assertGreaterThan(0, EmployeeMapper::getFromAccount(1)->limit(1)->execute()->getId()); self::assertGreaterThan(0, EmployeeMapper::get()->with('profile')->where('profile/account', 1)->limit(1)->execute()->getId());
} }
} }

View File

@ -40,9 +40,9 @@ final class EmployeeHistoryTest extends \PHPUnit\Framework\TestCase
self::assertEquals(0, $this->history->getId()); self::assertEquals(0, $this->history->getId());
self::assertNull($this->history->end); self::assertNull($this->history->end);
self::assertEquals(0, $this->history->employee); self::assertEquals(0, $this->history->employee);
self::assertNull($this->history->position); self::assertInstanceOf('\Modules\Organization\Models\NullPosition', $this->history->position);
self::assertNull($this->history->unit); self::assertInstanceOf('\Modules\Organization\Models\NullUnit', $this->history->unit);
self::assertNull($this->history->department); self::assertInstanceOf('\Modules\Organization\Models\NullDepartment', $this->history->department);
self::assertInstanceOf('\DateTime', $this->history->start); self::assertInstanceOf('\DateTime', $this->history->start);
} }
@ -56,14 +56,14 @@ final class EmployeeHistoryTest extends \PHPUnit\Framework\TestCase
$serialized = $this->history->jsonSerialize(); $serialized = $this->history->jsonSerialize();
unset($serialized['start']); unset($serialized['start']);
unset($serialized['unit']);
unset($serialized['department']);
unset($serialized['position']);
self::assertEquals( self::assertEquals(
[ [
'id' => 0, 'id' => 0,
'employee' => 2, 'employee' => 2,
'unit' => null,
'department' => null,
'position' => null,
'end' => null, 'end' => null,
], ],
$serialized $serialized