> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wellapp.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# CompanyMedia

> CompanyMedia is a soft-deleteable pivot (bridge) entity that links a Company to a Media asset

CompanyMedia is a soft-deleteable pivot (bridge) entity that links a Company to a Media asset. It records when a media file (logo, avatar, or banner) was associated with a company and is the persistence mechanism for the "add/remove company media" mutations. The entity carries no scalar attributes of its own beyond timestamps; all descriptive content lives on the related Media row. Two compound indexes optimise the Hasura array-relationship traversals in both directions: `(company_pk, deleted_at)` for the forward pass and `(media_pk)` for the reverse pass.

| Naming                          | Value                             |
| ------------------------------- | --------------------------------- |
| Object                          | CompanyMedia                      |
| Resource type (JSON:API `type`) | `company_media`                   |
| Collection / records root       | — <sub>(not a records root)</sub> |
| REST base                       | `/v1/company-media`               |
| Entity class                    | `CompanyMedia`                    |

<Note>
  **Internal object.** Not currently exposed on the public REST API. The operations below describe the intended contract.
</Note>

## API operations

| Operation | Method & path                   | Status     |
| --------- | ------------------------------- | ---------- |
| List      | `GET /v1/company-media`         | 🟡 Planned |
| Retrieve  | `GET /v1/company-media/{id}`    | 🟡 Planned |
| Create    | `POST /v1/company-media`        | 🟡 Planned |
| Update    | `PATCH /v1/company-media/{id}`  | 🟡 Planned |
| Delete    | `DELETE /v1/company-media/{id}` | 🟡 Planned |

## Data model

### Attributes

| Field       | Type               | Required | Constraints                                                                                 | Allowed values | Description                                                                                                                           |
| ----------- | ------------------ | -------- | ------------------------------------------------------------------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| created\_at | datetime 🔒 system | ✅ Yes    | Auto-set via onCreate hook; not nullable                                                    | —              | Timestamp when the company–media association was created. Set automatically on insert; never updated.                                 |
| deleted\_at | datetime \| null   | ⚪ No     | Nullable. Non-null value soft-deletes the row; all queries must filter deleted\_at IS NULL. | —              | Soft-delete sentinel. Set to the deletion timestamp when the media is unlinked from the company; null when the association is active. |

### Relationships

| Name    | Type               | Required | Description                                                                                                                                                                            |
| ------- | ------------------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| company | to-one (ManyToOne) | ✅ Yes    | The Company to which this media asset is attached. Indexed as part of the composite `(company_pk, deleted_at)` index for Hasura array-relationship traversals. Target entity: Company. |
| media   | to-one (ManyToOne) | ✅ Yes    | The Media asset (logo, avatar, or banner) being linked to the company. Indexed on `(media_pk)` for the reverse array-relationship traversal. Target entity: Media.                     |

### System-computed

* created\_at — set via MikroORM onCreate hook (new Date()); not writable by callers
* deleted\_at — written by soft-delete mutations (useAddCompanyMedia / useDeleteCompanyMedia service layer); never set by the user directly via PATCH
* pk — internal auto-increment integer primary key; never exposed in the public API. No public UUID (\*\_id) column exists on this entity — the entity is identified in the API by its relationship context (company\_id + media\_id pair), not by a standalone resource id
* Indexes maintained by migrations: idx\_company\_media\_company\_deleted (company\_pk, deleted\_at) — hot-path for Hasura forward traversal; idx\_company\_media\_media (media\_pk) — hot-path for Hasura reverse traversal. Both created in Migration20260416000000\_hasura\_and\_service\_hot\_path\_indexes\_round4.

## Example

```json theme={null}
{
  "data": {
    "type": "company_media",
    "id": "a3f1c2e4-8b7d-4a9f-bc12-0d5e6f7a8b9c",
    "attributes": {
      "created_at": "2025-11-14T09:32:00.000Z",
      "deleted_at": null
    },
    "relationships": {
      "company": {
        "data": { "type": "company", "id": "e1d2f3a4-5b6c-7d8e-9f0a-1b2c3d4e5f60" }
      },
      "media": {
        "data": { "type": "media", "id": "f9e8d7c6-b5a4-3c2d-1e0f-9a8b7c6d5e4f" }
      }
    }
  }
}
```

<sub>Source: `apps/api/src/database/entities/CompanyMedia.ts` · domain: financial-graph · tier: Supporting</sub>
