commit code
This commit is contained in:
parent
80d2191b7c
commit
75eb89406f
|
|
@ -3,6 +3,8 @@
|
||||||
namespace Modules\Admin\app\Http\Controllers;
|
namespace Modules\Admin\app\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Services\JiraService;
|
||||||
use App\Traits\AnalyzeData;
|
use App\Traits\AnalyzeData;
|
||||||
use App\Traits\HasFilterRequest;
|
use App\Traits\HasFilterRequest;
|
||||||
use App\Traits\HasOrderByRequest;
|
use App\Traits\HasOrderByRequest;
|
||||||
|
|
@ -22,6 +24,20 @@ class CriteriasController extends Controller
|
||||||
use HasSearchRequest;
|
use HasSearchRequest;
|
||||||
use AnalyzeData;
|
use AnalyzeData;
|
||||||
|
|
||||||
|
protected $jiraService;
|
||||||
|
|
||||||
|
public function __construct(JiraService $jiraService)
|
||||||
|
{
|
||||||
|
$this->jiraService = $jiraService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllUserJira()
|
||||||
|
{
|
||||||
|
$all_users = User::all();
|
||||||
|
$users = $this->jiraService->getUsersByEmails($all_users);
|
||||||
|
return $users;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all criterias of a sprint
|
* Get all criterias of a sprint
|
||||||
*
|
*
|
||||||
|
|
@ -31,13 +47,63 @@ class CriteriasController extends Controller
|
||||||
public function getCriteriasForSprint($sprintId)
|
public function getCriteriasForSprint($sprintId)
|
||||||
{
|
{
|
||||||
$sprint = Sprint::with('criterias')->find($sprintId);
|
$sprint = Sprint::with('criterias')->find($sprintId);
|
||||||
// Nếu không tìm thấy sprint, trả về response lỗi
|
|
||||||
if (!$sprint) {
|
if (!$sprint) {
|
||||||
return AbstractController::ResultError('Sprint not found', [], 404);
|
$allUser = self::getAllUserJira();
|
||||||
}
|
|
||||||
|
|
||||||
// Trả về thông tin sprint và criterias
|
$issues = $this->jiraService->getAllIssueByIdSprint($sprintId);
|
||||||
return AbstractController::ResultSuccess($sprint);
|
$uniqueUsers = [];
|
||||||
|
// echo json_encode($issues);
|
||||||
|
// die;
|
||||||
|
if ($issues) {
|
||||||
|
$issues = $issues["issues"];
|
||||||
|
foreach ($issues as $key => $issue) {
|
||||||
|
$assignee = $issue["fields"]["assignee"];
|
||||||
|
if ($assignee) {
|
||||||
|
if (!in_array($assignee["accountId"], $uniqueUsers)) {
|
||||||
|
array_push($uniqueUsers, $assignee["accountId"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// echo json_encode(allUser)
|
||||||
|
// dd();
|
||||||
|
|
||||||
|
$filteredObjects = array_filter($allUser, function ($user) use ($uniqueUsers) {
|
||||||
|
$user = $user[0];
|
||||||
|
return in_array($user['accountId'], $uniqueUsers);
|
||||||
|
});
|
||||||
|
|
||||||
|
$result = array_map(function ($item) {
|
||||||
|
$item = $item[0];
|
||||||
|
return [
|
||||||
|
'accountId' => $item['accountId'],
|
||||||
|
'emailAddress' => $item['emailAddress'],
|
||||||
|
'displayName' => $item['displayName'],
|
||||||
|
];
|
||||||
|
}, $filteredObjects);
|
||||||
|
|
||||||
|
//Get all user trong db => find info theo id
|
||||||
|
|
||||||
|
//Get criteria for sprint
|
||||||
|
$criterias = Criteria::where('type', "SPRINT")->get();
|
||||||
|
//Get criteria for user
|
||||||
|
$users = Criteria::where('type', "MEMBER")->get();
|
||||||
|
echo json_encode($result);
|
||||||
|
echo json_encode($users);
|
||||||
|
dd();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
"criterias" => $criterias,
|
||||||
|
"users" => $users
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$users = $sprint->users()->get();
|
||||||
|
$data = $sprint;
|
||||||
|
$data->users = $users;
|
||||||
|
}
|
||||||
|
return AbstractController::ResultSuccess($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function convertDataReponse($criterias)
|
public function convertDataReponse($criterias)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Modules\Admin\app\Models;
|
namespace Modules\Admin\app\Models;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Sprint extends Model
|
class Sprint extends Model
|
||||||
|
|
@ -12,6 +13,39 @@ class Sprint extends Model
|
||||||
public function criterias()
|
public function criterias()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Criteria::class, 'sprints_criterias')
|
return $this->belongsToMany(Criteria::class, 'sprints_criterias')
|
||||||
->withPivot('point', 'expect_result', 'actual_result', 'note');
|
->withPivot('point', 'expect_result', 'actual_result', 'note', "created_by");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// Định nghĩa một quan hệ với bảng users thông qua bảng users_criterias
|
||||||
|
public function users2()
|
||||||
|
{
|
||||||
|
return $this->hasManyThrough(
|
||||||
|
User::class, // Model đích
|
||||||
|
UserCriteria::class, // Model trung gian
|
||||||
|
'sprint_id', // Khóa ngoại trong bảng users_criterias
|
||||||
|
'email', // Trường để khớp trong bảng users
|
||||||
|
'id', // Khóa chính trong bảng sprint
|
||||||
|
'user_email' // Trường để khớp trong bảng users_criterias
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function users()
|
||||||
|
{
|
||||||
|
return $this->hasMany(UserCriteria::class)
|
||||||
|
->leftjoin('users', 'users.email', '=', 'users_criterias.user_email')
|
||||||
|
->leftjoin('criterias', 'criterias.id', '=', 'users_criterias.criteria_id')
|
||||||
|
->select(
|
||||||
|
'users.id as user_id',
|
||||||
|
'users.name as user',
|
||||||
|
'users.email as user_email',
|
||||||
|
|
||||||
|
'criteria_id',
|
||||||
|
'users_criterias.point as point',
|
||||||
|
'users_criterias.note as note',
|
||||||
|
'users_criterias.created_by as created_by',
|
||||||
|
|
||||||
|
'criterias.name as name',
|
||||||
|
'criterias.description as criteria_description',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,23 @@
|
||||||
|
|
||||||
namespace Modules\Admin\app\Models;
|
namespace Modules\Admin\app\Models;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class UserCriteria extends Model
|
class UserCriteria extends Model
|
||||||
{
|
{
|
||||||
protected $table = 'users_criterias';
|
protected $table = 'users_criterias';
|
||||||
protected $fillable = ['user_id', 'criteria_id', 'sprint_id', 'point', 'note'];
|
protected $fillable = ['user_id', 'criteria_id', 'sprint_id', 'point', 'note', 'user_email'];
|
||||||
}
|
|
||||||
|
// Định nghĩa quan hệ với model User
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'user_email', 'email');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Định nghĩa quan hệ với model Sprint
|
||||||
|
public function sprint()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Sprint::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -297,7 +297,7 @@ class JiraService
|
||||||
}
|
}
|
||||||
public function getAllBoardByIdProjects($id)
|
public function getAllBoardByIdProjects($id)
|
||||||
{
|
{
|
||||||
$response = $this->client->get('/rest/agile/1.0/board?projectKeyOrI=/' . $id);
|
$response = $this->client->get('/rest/agile/1.0/board?projectKeyOrId=' . $id);
|
||||||
return json_decode($response->getBody()->getContents(), true);
|
return json_decode($response->getBody()->getContents(), true);
|
||||||
}
|
}
|
||||||
public function getAllSprintByIdBoard($id)
|
public function getAllSprintByIdBoard($id)
|
||||||
|
|
|
||||||
|
|
@ -43,4 +43,15 @@ export const handleTicket = API_URL + 'v1/admin/ticket/handle-ticket'
|
||||||
export const getAllUsers = API_URL + 'v1/users'
|
export const getAllUsers = API_URL + 'v1/users'
|
||||||
export const createOrUpdateUser = API_URL + 'v1/users/createOrUpdate'
|
export const createOrUpdateUser = API_URL + 'v1/users/createOrUpdate'
|
||||||
export const deleteUser = API_URL + 'v1/users/delete'
|
export const deleteUser = API_URL + 'v1/users/delete'
|
||||||
export const getQRCode = API_URL + 'v1/users/qrcode'
|
export const getQRCode = API_URL + 'v1/users/qrcode'
|
||||||
|
|
||||||
|
//SprintReview
|
||||||
|
export const getAllCriteriasBySprint = API_URL + 'v1/admin/criterias/sprints'
|
||||||
|
|
||||||
|
export const getAllProject = API_URL + 'v1/admin/jira/all-project'
|
||||||
|
export const getAllBoardByIdProject = API_URL + 'v1/admin/jira/get-all-board-by-id-project'
|
||||||
|
export const getDetailProjectById = API_URL + 'v1/admin/jira/get-detail-project-by-id'
|
||||||
|
export const getAllSprintByIdBoard = API_URL + 'v1/admin/jira/get-all-sprint-by-id-board'
|
||||||
|
export const getAllIssuesByIdSprint = API_URL + 'v1/admin/jira/get-all-issue-by-id-sprint'
|
||||||
|
|
||||||
|
export const updateSprintReview = API_URL + 'v1/admin/sprint-review/update'
|
||||||
Loading…
Reference in New Issue