( resourceType: ShareResourceType, resourceIds: string[] )
| 63 | * Used to enrich the files list without an N+1 query. |
| 64 | */ |
| 65 | export async function getSharesForResources( |
| 66 | resourceType: ShareResourceType, |
| 67 | resourceIds: string[] |
| 68 | ): Promise<Map<string, ShareRecord>> { |
| 69 | const result = new Map<string, ShareRecord>() |
| 70 | if (resourceIds.length === 0) return result |
| 71 | |
| 72 | const rows = await db |
| 73 | .select() |
| 74 | .from(publicShare) |
| 75 | .where( |
| 76 | and(eq(publicShare.resourceType, resourceType), inArray(publicShare.resourceId, resourceIds)) |
| 77 | ) |
| 78 | |
| 79 | for (const row of rows) { |
| 80 | result.set(row.resourceId, mapShareRecord(row)) |
| 81 | } |
| 82 | return result |
| 83 | } |
| 84 | |
| 85 | interface UpsertFileShareInput { |
| 86 | workspaceId: string |
no test coverage detected