-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cannot sign declaration unless op-adm has logged in
- Loading branch information
Showing
8 changed files
with
819 additions
and
2,300 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
app/api/module/Api/src/Domain/QueryHandler/User/OperatorAdminForOrganisationHasLoggedIn.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Dvsa\Olcs\Api\Domain\QueryHandler\User; | ||
|
||
use DateTimeImmutable; | ||
use Doctrine\ORM\AbstractQuery; | ||
use Dvsa\Olcs\Api\Domain\Exception\BadRequestException; | ||
use Dvsa\Olcs\Api\Domain\Exception\RuntimeException; | ||
use Dvsa\Olcs\Api\Domain\Query\User\UserListSelfserve as ListDto; | ||
use Dvsa\Olcs\Api\Domain\QueryHandler\AbstractQueryHandler; | ||
use Dvsa\Olcs\Api\Domain\QueryHandler\Result; | ||
use Dvsa\Olcs\Api\Domain\Repository; | ||
use Dvsa\Olcs\Api\Entity; | ||
use Dvsa\Olcs\Transfer\Query\QueryInterface; | ||
use Dvsa\Olcs\Transfer\Query\User\OperatorAdminForOrganisationHasLoggedIn as Qry; | ||
|
||
/** | ||
* Returns true if an operator admin for the organisation has logged in | ||
*/ | ||
class OperatorAdminForOrganisationHasLoggedIn extends AbstractQueryHandler | ||
{ | ||
protected $repoServiceName = Repository\User::class; | ||
|
||
/** | ||
* Handle query | ||
* | ||
* @param QueryInterface $query query | ||
* | ||
* @throws BadRequestException|RuntimeException | ||
*/ | ||
public function handleQuery(QueryInterface $query): array | ||
{ | ||
if (!$query instanceof Qry) { | ||
throw new BadRequestException('Expected instance of: ' . Qry::class); | ||
} | ||
|
||
if (empty($query->getOrganisation())) { | ||
throw new BadRequestException('Organisation ID is required'); | ||
} | ||
|
||
$repo = $this->getRepo(Repository\User::class); | ||
|
||
$params = [ | ||
'organisation' => $query->getOrganisation(), | ||
'roles' => [Entity\User\Role::ROLE_OPERATOR_ADMIN], | ||
'page' => 1, | ||
'limit' => 100, | ||
'sort' => 'id', | ||
'order' => 'DESC', | ||
]; | ||
|
||
$lastLoginDate = DateTimeImmutable::createFromFormat("Y-m-d", '1970-01-01'); | ||
if (!empty($query->getLastLoggedInFrom())) { | ||
$lastLoginDate = DateTimeImmutable::createFromFormat("Y-m-d", $query->getLastLoggedInFrom()); | ||
} | ||
|
||
$params['lastLoggedInFrom'] = $lastLoginDate; | ||
|
||
$userListDto = ListDto::create($params); | ||
|
||
$result = [ | ||
'organisation' => (int) $query->getOrganisation(), | ||
'lastLoggedInFrom' => $lastLoginDate->format('Y-m-d'), | ||
'operatorAdminHasLoggedIn' => false, | ||
]; | ||
|
||
if ($repo->fetchCount($userListDto) > 0) { | ||
$result['operatorAdminHasLoggedIn'] = true; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.