| 1 | import { schema } from '@ghost/db'; |
| 2 | import { and, eq |
| 3 | |
| 4 | /** Who pays for a repository's stored files: its organization, or its owner when it belongs to no organization. */ |
| 5 | export type StorageAccount |
| 6 | |
| 7 | export function storageAccountOf(repository |
| 8 | ownerId: string |
| 9 | organizationId: string |
| 10 | }): StorageAccount { |
| 11 | return repository.organizationId |
| 12 | ? { organizationId: repository |
| 13 | : { userId: repository |
| 14 | } |
| 15 | |
| 16 | /** Repositories whose files count against `account`. */ |
| 17 | export function billedTo(account |
| 18 | return 'organizationId' in |
| 19 | ? eq(schema. |
| 20 | : and( |
| 21 | eq(schema.repository |
| 22 | isNull(schema.repository |
| 23 | ); |
| 24 | } |
| 25 | |
| 26 | export function storageAccountKey(account |
| 27 | return 'organizationId' in |
| 28 | ? `organization:${account. |
| 29 | : `user:${account. |
| 30 | } |