| 283 | }) |
| 284 | |
| 285 | async function isSenderAllowed(email: string, workspaceId: string): Promise<boolean> { |
| 286 | const [allowedSenderResult, memberResult] = await Promise.all([ |
| 287 | db |
| 288 | .select({ id: mothershipInboxAllowedSender.id }) |
| 289 | .from(mothershipInboxAllowedSender) |
| 290 | .where( |
| 291 | and( |
| 292 | eq(mothershipInboxAllowedSender.workspaceId, workspaceId), |
| 293 | eq(mothershipInboxAllowedSender.email, email) |
| 294 | ) |
| 295 | ) |
| 296 | .limit(1), |
| 297 | db |
| 298 | .select({ userId: permissions.userId }) |
| 299 | .from(permissions) |
| 300 | .innerJoin(user, eq(permissions.userId, user.id)) |
| 301 | .where( |
| 302 | and( |
| 303 | eq(permissions.entityType, 'workspace'), |
| 304 | eq(permissions.entityId, workspaceId), |
| 305 | sql`lower(${user.email}) = ${email}` |
| 306 | ) |
| 307 | ) |
| 308 | .limit(1), |
| 309 | ]) |
| 310 | |
| 311 | return !!(allowedSenderResult[0] || memberResult[0]) |
| 312 | } |
| 313 | |
| 314 | async function getRecentTaskCount(workspaceId: string): Promise<number> { |
| 315 | const oneHourAgo = new Date(Date.now() - 60 * 60 * 1000) |