Skip to content

Commit

Permalink
feat: various missing Count endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
TyIsI committed Dec 16, 2024
1 parent 3ae3552 commit 91d184d
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/contracts/IMemberCardService1.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@
use vhs\services\IContract;

interface IMemberCardService1 extends IContract {
/**
* @permission administrator
*
* @param $filters
*
* @return mixed
*/
public function CountGenuineCards($filters);

/**
* @permission administrator|user
*
* @param $userid
* @param $filters
*
* @return mixed
*
* @throws \Exception
*/
public function CountGenuineUserCards($userid, $filters);

/**
* @permission administrator
*
Expand Down
9 changes: 9 additions & 0 deletions app/contracts/IPreferenceService1.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
use vhs\services\IContract;

interface IPreferenceService1 extends IContract {
/**
* @permission administrator
*
* @param $filters
*
* @return array
*/
public function CountSystemPreferences($filters);

/**
* @permission administrator
*
Expand Down
9 changes: 9 additions & 0 deletions app/contracts/IPrivilegeService1.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
use vhs\services\IContract;

interface IPrivilegeService1 extends IContract {
/**
* @permission administrator|user|grants
*
* @param $filters
*
* @return mixed
*/
public function CountPrivileges($filters);

/**
* @permission administrator
*
Expand Down
49 changes: 49 additions & 0 deletions app/services/MemberCardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,31 @@
use vhs\security\exceptions\UnauthorizedException;

class MemberCardService implements IMemberCardService1 {
/**
* @permission administrator
*
* @param $filters
*
* @return mixed
*/
public function CountGenuineCards($filters) {
return GenuineCard::count($filters);
}

/**
* @permission administrator
*
* @param $userid
* @param $filters
*
* @return mixed
*/
public function CountGenuineUserCards($userid, $filters) {
$filters = $this->addUserIDToFilters($userid, $filters);

return GenuineCard::count($filters);
}

/**
* @permission administrator
*
Expand Down Expand Up @@ -208,4 +233,28 @@ public function ValidateGenuineCard($key) {

return !is_null($keys) && count($keys) == 1;
}

private function addUserIDToFilters($userid, $filters) {
$userService = new UserService();
$user = $userService->GetUser($userid);

if (is_string($filters)) {
//todo total hack.. this is to support GET params for downloading payments
$filters = json_decode($filters);
}

if (is_null($user)) {
throw new UnauthorizedException('User not found or you do not have access');
}

$userFilter = Filter::Equal('userid', $user->id);

if (is_null($filters) || $filters == '') {
$filters = $userFilter;
} else {
$filters = Filter::_And($userFilter, $filters);
}

return $filters;
}
}
11 changes: 11 additions & 0 deletions app/services/PreferenceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
use vhs\services\Service;

class PreferenceService extends Service implements IPreferenceService1 {
/**
* @permission administrator
*
* @param $filters
*
* @return array
*/
public function CountSystemPreferences($filters) {
return SystemPreference::count($filters);
}

/**
* @permission administrator
*
Expand Down
11 changes: 11 additions & 0 deletions app/services/PrivilegeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
use vhs\services\ServiceRegistry;

class PrivilegeService extends Service implements IPrivilegeService1 {
/**
* @permission administrator|user|grants
*
* @param $filters
*
* @return mixed
*/
public function CountPrivileges($filters) {
return Privilege::count($filters);
}

/**
* @permission administrator
*
Expand Down

0 comments on commit 91d184d

Please sign in to comment.