( credentialSetId: string, providerId: string, executor: DbOrTx )
| 100 | } |
| 101 | |
| 102 | async function credentialSetHasProviderCredential( |
| 103 | credentialSetId: string, |
| 104 | providerId: string, |
| 105 | executor: DbOrTx |
| 106 | ): Promise<boolean> { |
| 107 | const members = await executor |
| 108 | .select({ userId: credentialSetMember.userId }) |
| 109 | .from(credentialSetMember) |
| 110 | .where( |
| 111 | and( |
| 112 | eq(credentialSetMember.credentialSetId, credentialSetId), |
| 113 | eq(credentialSetMember.status, 'active') |
| 114 | ) |
| 115 | ) |
| 116 | |
| 117 | if (members.length === 0) return false |
| 118 | |
| 119 | const [credential] = await executor |
| 120 | .select({ id: account.id }) |
| 121 | .from(account) |
| 122 | .where( |
| 123 | and( |
| 124 | inArray( |
| 125 | account.userId, |
| 126 | members.map((member) => member.userId) |
| 127 | ), |
| 128 | eq(account.providerId, providerId), |
| 129 | or(isNotNull(account.accessToken), isNotNull(account.refreshToken)) |
| 130 | ) |
| 131 | ) |
| 132 | .limit(1) |
| 133 | |
| 134 | return Boolean(credential) |
| 135 | } |
| 136 | |
| 137 | interface CredentialSetSyncResult { |
| 138 | error: TriggerSaveError | null |
no test coverage detected