-- NOTE: This file is auto generated by ./sql-generator

-- PartnerRepository.getAll
select
  "partner".*,
  (
    select
      to_json(obj)
    from
      (
        select
          "id",
          "name",
          "email",
          "avatarColor",
          "profileImagePath",
          "profileChangedAt"
        from
          "user" as "sharedBy"
        where
          "sharedBy"."id" = "partner"."sharedById"
      ) as obj
  ) as "sharedBy",
  (
    select
      to_json(obj)
    from
      (
        select
          "id",
          "name",
          "email",
          "avatarColor",
          "profileImagePath",
          "profileChangedAt"
        from
          "user" as "sharedWith"
        where
          "sharedWith"."id" = "partner"."sharedWithId"
      ) as obj
  ) as "sharedWith"
from
  "partner"
  inner join "user" as "sharedBy" on "partner"."sharedById" = "sharedBy"."id"
  and "sharedBy"."deletedAt" is null
  inner join "user" as "sharedWith" on "partner"."sharedWithId" = "sharedWith"."id"
  and "sharedWith"."deletedAt" is null
where
  (
    "sharedWithId" = $1
    or "sharedById" = $2
  )

-- PartnerRepository.get
select
  "partner".*,
  (
    select
      to_json(obj)
    from
      (
        select
          "id",
          "name",
          "email",
          "avatarColor",
          "profileImagePath",
          "profileChangedAt"
        from
          "user" as "sharedBy"
        where
          "sharedBy"."id" = "partner"."sharedById"
      ) as obj
  ) as "sharedBy",
  (
    select
      to_json(obj)
    from
      (
        select
          "id",
          "name",
          "email",
          "avatarColor",
          "profileImagePath",
          "profileChangedAt"
        from
          "user" as "sharedWith"
        where
          "sharedWith"."id" = "partner"."sharedWithId"
      ) as obj
  ) as "sharedWith"
from
  "partner"
  inner join "user" as "sharedBy" on "partner"."sharedById" = "sharedBy"."id"
  and "sharedBy"."deletedAt" is null
  inner join "user" as "sharedWith" on "partner"."sharedWithId" = "sharedWith"."id"
  and "sharedWith"."deletedAt" is null
where
  "sharedWithId" = $1
  and "sharedById" = $2

-- PartnerRepository.update
update "partner"
set
  "inTimeline" = $1
where
  "sharedWithId" = $2
  and "sharedById" = $3
returning
  *,
  (
    select
      to_json(obj)
    from
      (
        select
          "id",
          "name",
          "email",
          "avatarColor",
          "profileImagePath",
          "profileChangedAt"
        from
          "user" as "sharedBy"
        where
          "sharedBy"."id" = "partner"."sharedById"
      ) as obj
  ) as "sharedBy",
  (
    select
      to_json(obj)
    from
      (
        select
          "id",
          "name",
          "email",
          "avatarColor",
          "profileImagePath",
          "profileChangedAt"
        from
          "user" as "sharedWith"
        where
          "sharedWith"."id" = "partner"."sharedWithId"
      ) as obj
  ) as "sharedWith"

-- PartnerRepository.remove
delete from "partner"
where
  "sharedWithId" = $1
  and "sharedById" = $2
