오늘의 서커스 내용 세션의 정보를 가져오는데 세션의 앱은 ApplicationGrants를 받아야 하고 세션의 프로필 ID는 ApplicationGrantProfiles으로 프로필별 승인을 받거나 전체 프로필 승인(ApplicationGrantProfiles.profileId == null)을 받야아 가져올 수 있는데 세션의 프로필을 헤더로 오버라이드할 수 있고 오버라이드된 프로필 역시 위 조건을 지키는 경우만 리턴되게 하는 쿼리를 짰어요

const headerProfileId = c.req.header('X-Actor-Profile-Id');
    const session = await db
      .select({
        id: Sessions.id,
        applicationId: Sessions.applicationId,
        accountId: Sessions.accountId,
        scopes: Sessions.scopes,
        languages: Accounts.languages,
        profileId: Profiles.id,
      })
      .from(Sessions)
      .innerJoin(Accounts, eq(Sessions.accountId, Accounts.id))
      .innerJoin(ApplicationGrants, eq(Sessions.applicationId, ApplicationGrants.applicationId))
      .leftJoin(
        ApplicationGrantProfiles,
        eq(ApplicationGrants.id, ApplicationGrantProfiles.applicationGrantId),
      )
      .leftJoin(
        Profiles,
        and(
          eq(Profiles.id, headerProfileId ?? Sessions.profileId),
          eq(Profiles.state, ProfileState.ACTIVE),
          isNotNull(ApplicationGrantProfiles.id),
          or(
            eq(ApplicationGrantProfiles.profileId, Profiles.id),
            isNull(ApplicationGrantProfiles.profileId),
          ),
        ),
      )
      .where(eq(Sessions.token, accessToken))
      .limit(1)
      .then(first);
1

😂

1 person reacted.

Hi, I'm who's behind Fedify, Hollo, BotKit, and this website, Hackers' Pub!

Fedify, Hollo, BotKit, 그리고 보고 계신 이 사이트 Hackers' Pub을 만들고 있습니다.

FedifyHolloBotKit、そしてこのサイト、Hackers' Pubを作っています。

嗨,我是 FedifyHolloBotKit 以及這個網站 Hackers' Pub 的開發者!