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 * @return \Illuminate\Http\Response */ public function comment(CommentRequest $request, string $objectType, string $objectId) { $actionObjectType = ActionObjectType::from($objectType); $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 }; ActionRepository::create( $objectId, $actionObjectType, ObjectAction::COMMENTED, projectId: $projectId, comment: $request->comment, ); return $this->created(); } /** * update comment * * @param CommentRequest $request * @param string $id * @return \Illuminate\Http\Response */ public function updateComment(CommentRequest $request, string $id) { $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); $action->comment = $request->comment; $action->save(); return $this->noContent(); } }