# Collection settings (https://survey.dimah.dev/docs/settings)



`settings` is the server-owned collection policy for one survey. It decides
whether an identified respondent reuses a response, whether closed responses
can reopen, when writes are accepted, and how many submissions are allowed.

<Callout>
  Settings are not SurveyJS JSON and are never copied into
  `response.definition`. `saveSurveySettings` replaces the complete object.
</Callout>

## Fields [#fields]

```ts
import type { SurveySettings } from "@dimah-survey/core";
```

<AutoTypeTable path="packages/core/src/types.ts" name="SurveySettings" />

`saveSurvey` inserts these defaults and then leaves the column alone.
`saveSurveySettings` replaces the whole object. Send every field. `closesAt`
must be later than `opensAt` when both are set. `maxResponses` is a positive
integer or `null`.

Dates are ISO strings. If legacy storage contains an invalid settings object,
the reader falls back to defaults rather than exposing malformed policy.

## Reuse identified responses [#reuse-identified-responses]

For an identified principal, `startResponse` applies `responses` inside the
store write:

| Policy       | Result                                                                 |
| ------------ | ---------------------------------------------------------------------- |
| `"one-open"` | Return the existing draft; otherwise create a new response             |
| `"single"`   | Return the latest response of any status; create only when none exists |

Anonymous starts always create a new response. Their response id is the
capability; they cannot list responses. See [Security](https://survey.dimah.dev/docs/security.md).

`"single"` can return a submitted or abandoned row. The fill `Model` opens in
display mode unless you reopen it. See [React](https://survey.dimah.dev/docs/react.md).

## Enforce the window and cap [#enforce-the-window-and-cap]

`opensAt` and `closesAt` are inclusive. Outside that window, start, partial
save, and submit throw `SURVEY_CLOSED`. Abandon, get, and reopen stay
available. `GET /survey/published` still returns the document, so the client
can show that the survey is closed.

`maxResponses` counts rows already stored as `submitted`. The check runs before
a new insert and before submit, inside the store lock. At the cap, both fail
with `RESPONSE_LIMIT`. Returning an existing identified row does not consume
capacity.

## Reopen a response [#reopen-a-response]

`reopen: true` lets `reopenResponse` move a submitted or abandoned row back to
`draft`. It clears `submittedAt` and does not change `definition` or `data`.

When reopening would create a second draft for the same survey and identified
respondent, the write fails with `OPEN_DRAFT`. `reopen: false` instead fails
with `RESPONSE_CLOSED`.
