modelBuilder()->findOrFail($objectId); $objectIds = [$objectId]; if (ActionObjectType::CONTAINER_FILE->value == $objectType) { ContainerFileRepository::getSourceFileFiles($model)->each(function ($file) use (&$objectIds) { $objectIds[] = $file->id; $objectIds[] = $file->source_file_id; }); } return $this->success([ 'data' => ActionRepository::actionWithHistory($actionObjectType, array_unique($objectIds)), ]); } /** * action comment * * @param CommentRequest $request * @param string $objectType * @param string $objectId */ public function comment(FileAssociationService $service, CommentRequest $request, string $objectType, string $objectId,ImageUrlService $imgService) { $actionObjectType = ActionObjectType::from($objectType); $comment=$request->get('comment'); $newComment=$imgService->interceptImageUrl($comment); $object = $actionObjectType?->modelBuilderAllowed($objectId) ->where("company_id", Auth::user()->company_id) ->findOrFail($objectId); $projectId = match ($actionObjectType) { ActionObjectType::PROJECT => $objectId, ActionObjectType::TASK => $object->project_id, default => null }; $service->check( $request->get("file_ids", []), FileObjectType::ACTION, ); $action = ActionRepository::create( $objectId, $actionObjectType, ObjectAction::COMMENTED, projectId: $projectId, comment: $newComment, ); $service->association($action->id); return $this->created(); } /** * update comment * * @param CommentRequest $request * @param string $id * @return \Illuminate\Http\Response */ public function updateComment(CommentRequest $request, string $id,ImageUrlService $imgService) { $action = Action::query()->findOrFail($id); $actionObjectType = ActionObjectType::from($action->object_type); $actionObjectType?->modelBuilderAllowed($action->object_id) ->where("company_id", Auth::user()->company_id) ->findOrFail($action->object_id); $comment=$request->get('comment'); $newComment=$imgService->interceptImageUrl($comment); $action->comment = $newComment; $action->save(); return $this->noContent(); } public function lastDynamic(){ return $this->success([ 'data' => ActionRepository::allLatestDynamic() ]); } }