TASK-229 Validate all Endpoints for delete Old Ajax files

This commit is contained in:
Brayan Pereyra
2025-09-18 03:47:29 +00:00
parent 9ea66b21a1
commit a7fe9048bf
15 changed files with 937 additions and 45 deletions

View File

@@ -4,6 +4,8 @@ namespace ProcessMaker\Model;
use App\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use \Exception;
use \G;
/**
* Class Department
@@ -15,6 +17,100 @@ class Department extends Model
// Set our table name
protected $table = 'DEPARTMENT';
// We do not store timestamps
protected $fillable = [
'DEP_UID',
'DEP_TITLE',
'DEP_PARENT',
'DEP_MANAGER',
'DEP_LOCATION',
'DEP_STATUS',
'DEP_REF_CODE',
'DEP_LDAP_DN'
];
public $timestamps = false;
public function show($filters = array())
{
try {
$query = static::query();
if (is_array($filters['fields'])) {
$query->select($filters['fields']);
}
if (is_array($filters['conditions'])) {
if (!empty($filters['conditions']['text'])) {
$query->where('DEP_TITLE', 'like', '%' . $filters['conditions']['text'] . '%');
unset($filters['conditions']['text']);
}
$query->where($filters['conditions']);
}
$total = $query->count();
if (is_array($filters['start']) || is_array($filters['limit'])) {
$start = $filters['start'] ?? 0;
$limit = $filters['limit'] ?? 25;
$query->offset($start)->limit($limit);
}
if (is_array($filters['orderBy'])) {
$query->orderBy($filters['orderBy'][0], $filters['orderBy'][1] ?? 'asc');
}
$data = $query->get()->toArray();
$result = [
'total' => $total,
'data' => $data
];
return $result;
} catch (Exception $exception) {
return $exception->getMessage();
}
}
public static function saveData($departmentData)
{
try {
if (empty($departmentData['DEP_UID'])) {
$departmentData['DEP_UID'] = G::generateUniqueID();
$responseSave = self::create($departmentData);
} else {
$responseSave = self::where('DEP_UID', $departmentData['DEP_UID'])
->update($departmentData);
}
return $responseSave;
} catch (Exception $exception) {
return $exception->getMessage();
}
}
public static function getDepUidIfExistsDN($currentDN)
{
$query = Department::select(['DEP_UID'])
->where('DEP_STATUS', '=', 'ACTIVE')
->where('DEP_LDAP_DN', $currentDN);
$data =$query->get()->toArray();
$result = [
'total' => count($data),
'data' => $data
];
return $result;
}
public static function getDepartmentsWithDN()
{
$query = Department::select(['DEP_LDAP_DN'])
->where('DEP_LDAP_DN', '!=', '')
->whereNotNull('DEP_LDAP_DN');
$data =$query->get()->toArray();
$result = [
'total' => count($data),
'data' => $data
];
return $result;
}
}

View File

@@ -8,6 +8,7 @@ use G;
use Illuminate\Database\Eloquent\Model;
use ProcessMaker\Model\Groupwf;
use ProcessMaker\Model\RbacUsers;
use Illuminate\Support\Facades\DB;
class GroupUser extends Model
{
@@ -117,4 +118,19 @@ class GroupUser extends Model
throw new Exception("Error: {$e->getMessage()}.");
}
}
public static function getNumberOfUsersByGroups()
{
$query = GroupUser::select(['GROUP_USER.GRP_UID', DB::raw('COUNT(GROUP_USER.GRP_UID) AS NUM_REC')])
->leftJoin('USERS','USERS.USR_UID','=','GROUP_USER.USR_UID')
->where('USERS.USR_STATUS', '!=', 'CLOSED')
->groupBy('GROUP_USER.GRP_UID');
$data =$query->get()->toArray();
$result = [
'total' => count($data),
'data' => $data
];
return $result;
}
}

View File

@@ -4,6 +4,8 @@ namespace ProcessMaker\Model;
use App\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use \Exception;
use \G;
class Groupwf extends Model
{
@@ -11,9 +13,74 @@ class Groupwf extends Model
protected $table = 'GROUPWF';
protected $primaryKey = 'GRP_ID';
protected $fillable = [
'GRP_UID',
'GRP_ID',
'GRP_TITLE',
'GRP_STATUS',
'GRP_STATUS_ID',
'GRP_LDAP_DN',
'GRP_UX'
];
// We do not have create/update timestamps for this table
public $timestamps = false;
public function show($filters = array())
{
try {
$query = static::query();
if (is_array($filters['fields'])) {
$query->select($filters['fields']);
}
if (is_array($filters['conditions'])) {
if (!empty($filters['conditions']['text'])) {
$query->where('GRP_TITLE', 'like', '%' . $filters['conditions']['text'] . '%');
unset($filters['conditions']['text']);
}
$query->where($filters['conditions']);
}
$total = $query->count();
if (is_array($filters['start']) || is_array($filters['limit'])) {
$start = $filters['start'] ?? 0;
$limit = $filters['limit'] ?? 25;
$query->offset($start)->limit($limit);
}
if (is_array($filters['orderBy'])) {
$query->orderBy($filters['orderBy'][0], $filters['orderBy'][1] ?? 'asc');
}
$data =$query->get()->toArray();
$result = [
'total' => $total,
'data' => $data
];
return $result;
} catch (Exception $exception) {
return $exception->getMessage();
}
}
public static function saveData($groupwfData)
{
try {
if (empty($groupwfData['GRP_UID'])) {
$groupwfData['GRP_UID'] = G::generateUniqueID();
$responseSave = self::create($groupwfData);
} else {
$responseSave = self::where('GRP_UID', $groupwfData['GRP_UID'])
->update($groupwfData);
}
return $responseSave;
} catch (Exception $exception) {
return $exception->getMessage();
}
}
/**
* Scope a query to active groups
*
@@ -72,4 +139,17 @@ class Groupwf extends Model
$query = Groupwf::select('GRP_ID')->where('GRP_UID', $grpUid);
return $query->first()->toArray();
}
public static function getGroupWithDN($dn)
{
try {
$query = Groupwf::select('GRP_UID')
->where('GRP_STATUS', 'ACTIVE')
->where('GRP_LDAP_DN', $dn);
$response = $query->get()->toArray();
return $response;
} catch (\Exception $e) {
return false;
}
}
}

View File

@@ -5,6 +5,7 @@ namespace ProcessMaker\Model;
use App\Factories\HasFactory;
use Configurations;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Exception;
use RBAC;
@@ -300,4 +301,20 @@ class User extends Model
return $result;
}
public static function getNumberOfUsersByDepartments()
{
$query = User::select(['DEP_UID', DB::raw('COUNT(DEP_UID) AS NUM_REC')])
->where('USR_STATUS', '!=', 'CLOSED')
->where('DEP_UID', '!=', '')
->whereNotNull('DEP_UID')
->groupBy('DEP_UID');
$data =$query->get()->toArray();
$result = [
'total' => count($data),
'data' => $data
];
return $result;
}
}