GroupInviteResource.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Resources\V3;
  3. use App\Http\Resources\Concerns\ResolvesActor;
  4. use App\Services\V3\GroupInviteService;
  5. use Illuminate\Http\Request;
  6. /**
  7. * 打开邀请链接看到的内容:哪个团队、谁邀请的、以什么角色加入。
  8. *
  9. * `member_role` 是查看者在这个团队里现有的角色:没登录或还不是成员为 null。
  10. * 载荷由 {@see GroupInviteService::preview()} 组好,团队的 creator 已预加载,本类不查库。
  11. */
  12. class GroupInviteResource extends BaseResource
  13. {
  14. use ResolvesActor;
  15. /**
  16. * @param Request $request
  17. * @return array{
  18. * group: array{id: string, name: string, description: string|null, status: int, owner: array{id: string, nickName: string, userName: string, realName: string, sn: int, avatar: string|null, roles: array|null}|null},
  19. * inviter: array{id: string, nickName: string, userName: string, realName: string, sn: int, avatar: string|null, roles: array|null},
  20. * role: string,
  21. * expires_at: string,
  22. * member_role: string|null
  23. * }
  24. */
  25. public function toArray($request): array
  26. {
  27. $group = $this->resource['group'];
  28. return [
  29. 'group' => [
  30. 'id' => $group->uid,
  31. 'name' => $group->name,
  32. 'description' => $group->description,
  33. 'status' => (int) $group->status,
  34. 'owner' => $this->actor($group->creator),
  35. ],
  36. 'inviter' => $this->resource['inviter'],
  37. 'role' => $this->resource['role'],
  38. 'expires_at' => $this->resource['expires_at'],
  39. 'member_role' => $this->resource['member']?->effectiveRole(),
  40. ];
  41. }
  42. }