( organizationId: string, periodStart: Date, executor: DbClient = db )
| 156 | } |
| 157 | |
| 158 | export async function getOrgMemberRefreshBounds( |
| 159 | organizationId: string, |
| 160 | periodStart: Date, |
| 161 | executor: DbClient = db |
| 162 | ): Promise<Record<string, { userStart: Date }>> { |
| 163 | const rows = await executor |
| 164 | .select({ |
| 165 | userId: member.userId, |
| 166 | snapshotAt: userStats.proPeriodCostSnapshotAt, |
| 167 | }) |
| 168 | .from(member) |
| 169 | .leftJoin(userStats, eq(member.userId, userStats.userId)) |
| 170 | .where(eq(member.organizationId, organizationId)) |
| 171 | |
| 172 | const bounds: Record<string, { userStart: Date }> = {} |
| 173 | for (const row of rows) { |
| 174 | if (row.snapshotAt && row.snapshotAt > periodStart) { |
| 175 | bounds[row.userId] = { userStart: row.snapshotAt } |
| 176 | } |
| 177 | } |
| 178 | return bounds |
| 179 | } |
no test coverage detected