# DocumentManager

**Kind:** Class

**Source:** [`atloria-monorepo/packages/core/src/managers/document-manager.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/packages/core/src/managers/document-manager.ts#L13)

DocumentManager handles document business logic
This class is framework-agnostic and can be used in any environment

## Methods

| Method | Signature | Returns |
|---|---|---|
| `validate` | `validate(doc: Partial<Document>)` | `ValidationResult` |
| `canEdit` | `canEdit(user: User, doc: Document)` | `boolean` |
| `canPublish` | `canPublish(user: User, _doc: Document)` | `boolean` |
| `canDelete` | `canDelete(user: User, _doc: Document)` | `boolean` |
| `createVersion` | `createVersion(doc: Document)` | `Partial<Document>` |
| `applyAudienceFilter` | `applyAudienceFilter(docs: Document[], audience: string)` | `Document[]` |
| `applyAudiencesFilter` | `applyAudiencesFilter(docs: Document[], audiences: string[])` | `Document[]` |
| `isOutdated` | `isOutdated(doc: Document, allVersions: Document[])` | `boolean` |
| `getLatestPublishedVersion` | `getLatestPublishedVersion(slug: string, allVersions: Document[])` | `Document | null` |
| `canView` | `canView(user: User | null, doc: Document)` | `boolean` |

## Where it refuses work

- `DocumentManager` stops the work with an early return when `user.role === UserRole.ADMIN || user.role === UserRole.MAINTAINER`.
- `DocumentManager` stops the work with an early return when `user.role === UserRole.CONTRIBUTOR && doc.createdById === user.id`.
- `DocumentManager` stops the work with an early return when `publishedVersions.length === 0`.
- `DocumentManager` stops the work with an early return when `doc.isPublic`.
- `DocumentManager` stops the work with an early return when `!user`.
