Skip to content

Commit

Permalink
Merge pull request #789 from kayleb01/develop
Browse files Browse the repository at this point in the history
Added linting and fix the sidebar issue
  • Loading branch information
kayleb01 authored Oct 31, 2021
2 parents 8cf3ce5 + 25b7257 commit c8d629c
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 18 deletions.
13 changes: 6 additions & 7 deletions app/Helpers/Collaborator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

class Collaborator
{
protected $userService;
public function __construct(UserService $userService)
{
$this->userService = $userService;
}

public static function isAdmin(array $todo, $userId): bool
{
Expand Down Expand Up @@ -71,7 +66,7 @@ public function sendMails(array $user_ids, $subject, $message)
for ($i = 0; $i < count($user_ids); $i++) {
# code...
$data['user_id'] = $user_ids[$i];
$user = $this->userService->findUser($data, $bearerToken);
$user = $this->findUser($data, $bearerToken);
// Log::info($user['email'])
$this->sendMail($user, $subject, $message);
}
Expand All @@ -92,7 +87,7 @@ public static function sortAdminFirst(array $collaborators): array
{
$adminFirstList = [];

foreach ($collaborators as $collaborator) {
foreach ($collaborators as $collaborator) {
if ($collaborator['admin_status'] == 1) {
array_unshift($adminFirstList, $collaborator);
} else {
Expand All @@ -102,4 +97,8 @@ public static function sortAdminFirst(array $collaborators): array

return $adminFirstList;
}
public function findUser($data, $bearerToken)
{
return $this->httpRepository->findUser($data, $bearerToken);
}
}
10 changes: 5 additions & 5 deletions app/Services/SidebarService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Http\Resources\SidebarResource;

class SidebarService
{
{
/**
* todoService
*
Expand All @@ -19,11 +19,11 @@ class SidebarService
* @param SideBarItemsController $sideBarItemsController
* @return void
*/
public function __construct(todoService $todoService)
public function __construct(TodoService $todoService)
{
$this->todoService = $todoService;
}

public function sidebar($dataType)
{
$org_id = Config::get('organisation_id');
Expand Down Expand Up @@ -60,7 +60,7 @@ public function sidebar($dataType)
"public_rooms" => collect($publicTodos),
"joined_rooms" => collect($privateTodos)
];
//publish to centrifugo and return
//publish to centrifugo and return
(new TodoService)->publishToRoomChannel($workspaceChannelName, $dataRtcPayload, " ", " ");
$response = (new SidebarResource(['public_rooms' => collect($publicTodos), 'joined_rooms' => collect($privateTodos)]));
return $this->jsonEncoded($response, $dataType);
Expand Down Expand Up @@ -108,5 +108,5 @@ public function sidebarDataAttr()
"joined_rooms" => $dataText["joined_rooms"],
];
return $data;
}
}
}
157 changes: 151 additions & 6 deletions app/Services/TaskService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
namespace App\Services;

use App\Helpers\Response;
use Illuminate\Support\Str;
use App\Helpers\Collaborator;
use App\Services\TodoService;
use App\Repositories\TaskRepository;
//use App\Services\ServiceTrait;

class TaskService extends TaskRepository
{
//use ServiceTrait;

protected $todoService;

public function __construct(TodoService $todoService)
{
$this->todoService = $todoService;
}
/**
* @return mixed
*/
public function all()
{

return Response::checkAndServe($this->httpRepository->all());
}

Expand All @@ -24,7 +33,7 @@ public function all()
*/
public function create(array $data)
{

return Response::checkAndServe($this->httpRepository->create($data));
}

Expand All @@ -34,7 +43,7 @@ public function create(array $data)
*/
public function find($id)
{

return Response::checkAndServe($this->httpRepository->find($id));
}

Expand All @@ -54,7 +63,7 @@ public function findBy($attr, $value)
*/
public function update($data, $id)
{

return Response::checkAndServe($this->httpRepository->update($id, $data));
}

Expand All @@ -64,7 +73,7 @@ public function update($data, $id)
*/
public function delete($id)
{

return Response::checkAndServe($this->httpRepository->delete($id));
}

Expand Down Expand Up @@ -96,4 +105,140 @@ public function getLatestTask()
}
}

/**
* @param string
* @return mixed
*/
public function toggleStatus($id)
{
$task = $this->todoService->find($id); // Get the Task

$archived = array_key_exists('archived_at', $task)
&& $task['archived_at'] ? '' : Carbon::now(); // Set new date if it is null or empty, else set back to empty

// prepare the payload
$data = array();
$data['archived_at'] = $archived;

//response from zccore
return response()->json($this->update($data, $id));
}

public function taskCategory($request)
{
// Search for the category
$allTasks = $this->todoService->all();
Sort::sortAll($request);

$newArr = [];
foreach ($allTasks as $value) {
if (isset($value['category_id']) && $value['category_id'] == $request->category_id) {
array_push($newArr, $value);
}
}

return $newArr;
}

public function taskCollection($request)
{
$allTasks = $this->todoService->all();
Sort::sortAll($request);

$sort = $request->order;
if ($sort) {
$allTasks = collect($allTasks->sortBy('created_at'))->toArray;
}

$time = time();
$arr = array();
foreach ($allTasks as $value) {
if (array_key_exists('end_date', [$value])) {
$end_date = $value['end_date'];
$convert_date = strtotime($end_date);
if ($convert_date >= $time) {

$arr = $value;
}
}
}
return $arr;
}

public function sort($request)
{
$parameter = $request->sort;
$tasks = $this->todoService->all();
$collectionTasks = collect($tasks)->sortBy($parameter);
return $collectionTasks;
}

public function markTask($request, $todoId)
{
// inialize value for task
$todo = $this->todoService->findBy('_id', $todoId);
if (isset($todo['status']) && $todo['status'] == 404) {
return response()->json($todo, 404);
}
for ($i = 0; $i < count($todo['tasks']); $i++) {
if ($todo['tasks'][$i]['task_id'] == $request->task_id) {
$todo['tasks'][$i]['status'] = $request->status;
}
}

unset($todo['_id']);

$result = $this->todoService->update($todo, $todoId);
if (isset($result['modified_documents']) && $result['modified_documents'] > 0) {
$todoWithId = array_merge(['_id' => $todoId], $todo);
$this->publishToRoomChannel($todo['channel'], $todoWithId, 'todo', 'update');

// Send Mail
$user_ids = Collaborator::listAllUsersInTodo($todo);
$collab = new Collaborator;
$collab->sendMails($user_ids, 'Task Added', 'A task with the title' . $request->title . 'has been marked in the todo');
return $todoWithId;
} else {
abort(500, $result);
}
}

/**
* @param Request $request, $todoId string
* @return mixed
*/
public function add($request, $todoId)
{
$todo = $this->todoService->find($todoId);

if (isset($todo['status']) && $todo['status'] == 404) {
return response()->json($todo, 404);
}


$newTasks = [
"task_id" => Str::uuid(), "title" => $request->title,
"recurring" => $request->recurring, "status" => 0
];

array_push($todo['tasks'], $newTasks);
unset($todo['_id']);

$result = $this->todoService->update($todo, $todoId);

if (isset($result['modified_documents']) && $result['modified_documents'] > 0) {

// Publish To Centrifugo
$todoWithId = array_merge(['_id' => $todoId], $todo);
$this->publishToRoomChannel($todo['channel'], $todoWithId, "Task", "create");
// Send Mail
$user_ids = Collaborator::listAllUsersInTodo($todo);
$collab = new Collaborator;
$collab->sendMails($user_ids, 'Task Added', 'A task with the title'.$request->title.'has been added to the todo');

return $todoWithId;
}

abort(500, $result);
}
}

0 comments on commit c8d629c

Please sign in to comment.