modelBuilder()->where("company_id", Auth::user()->company_id)->findOrFail($objectId); return $this->success([ 'data' => ActionRepository::actionWithHistory($actionObjectType, $objectId), ]); } /** * 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(); } }