| 52 | |
| 53 | const isAdminOrHasAccess = |
| 54 | (): Access => |
| 55 | ({ req: { user: _user } }) => { |
| 56 | const user = _user as User | undefined |
| 57 | |
| 58 | if (!user) return false |
| 59 | if (user.role === 'admin') return true |
| 60 | |
| 61 | const userProductIDs = (user.products || []).reduce< |
| 62 | Array<string> |
| 63 | >((acc, product) => { |
| 64 | if (!product) return acc |
| 65 | if (typeof product === 'string') { |
| 66 | acc.push(product) |
| 67 | } else { |
| 68 | acc.push(product.id) |
| 69 | } |
| 70 | |
| 71 | return acc |
| 72 | }, []) |
| 73 | |
| 74 | return { |
| 75 | id: { |
| 76 | in: userProductIDs, |
| 77 | }, |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | export const Products: CollectionConfig = { |
| 82 | slug: 'products', |