prompts(backend): retarget enum rules at shared-types stage

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
MaKarin
2026-04-09 21:13:27 +03:00
parent a4f042a57c
commit a8094c12de

View File

@@ -104,38 +104,44 @@ Type and decorator rules:
| `decimal` | `string` | `@IsString()` | serialize with Prisma Decimal | | `decimal` | `string` | `@IsString()` | serialize with Prisma Decimal |
| `date` | `string` | `@IsString()` | serialize as ISO string | | `date` | `string` | `@IsString()` | serialize as ISO string |
| `boolean` | `boolean` | `@IsBoolean()` | | | `boolean` | `boolean` | `@IsBoolean()` | |
| enum name | `string` | `@IsEnum(EnumName)` | | | enum name | `EnumName` (imported from `../../enums/<kebab>.enum`) | `@IsEnum(EnumName)` | Do not use `string` |
Nullability rules: Nullability rules:
- every field that is not `is required` gets `@IsOptional()` before the type decorator - every field that is not `is required` gets `@IsOptional()` before the type decorator
- every generated DTO imports from `'class-validator'` - every generated DTO imports from `'class-validator'`
## Shared Enum Files ## Shared Types
Enums referenced by DTOs across multiple modules MUST be generated as standalone files at: Shared TypeScript types are generated by the `shared-types` stage BEFORE
`nest-entities` runs. Per-entity modules MUST import them; they must NEVER
redefine them.
``` Zones:
server/src/enums/<EnumName>.enum.ts
```
Example for `EquipmentStatus`: - `server/src/enums/<kebab-enum-name>.enum.ts` — one file per DSL enum
```ts - `server/src/shared/pagination.ts``PaginatedResponse<T>` and `ListQueryParams`
// server/src/enums/equipment-status.enum.ts - `server/src/shared/index.ts` — barrel for shared types
export enum EquipmentStatus {
Active = 'Active',
Repair = 'Repair',
Reserve = 'Reserve',
WriteOff = 'WriteOff',
}
```
DTO files import the enum with path `../../enums/<enum-name>.enum` (two levels up from `modules/<kebab>/dto/`): Import conventions depend on the importing file's depth:
```ts
import { EquipmentStatus } from '../../enums/equipment-status.enum';
```
Do NOT inline enum values into DTOs. Do NOT put enum files inside the module folder. - From a module/controller/service file at `server/src/modules/<kebab>/<file>.ts`:
```ts
import { EquipmentStatus } from '../../enums/equipment-status.enum';
import { PaginatedResponse, ListQueryParams } from '../../shared/pagination';
```
- From a DTO file at `server/src/modules/<kebab>/dto/<file>.ts` (one level deeper):
```ts
import { EquipmentStatus } from '../../../enums/equipment-status.enum';
import { PaginatedResponse, ListQueryParams } from '../../../shared/pagination';
```
Enum-typed DTO fields MUST be declared with the actual enum type, NOT
`string`. The enum is imported from the shared file above. `@IsEnum(EnumName)`
still applies at runtime for validation. Because the DTO type matches the
Prisma-generated enum type by name and by string values, service code can
pass DTOs into Prisma without `as EnumName` casts.
## Auth Import Paths ## Auth Import Paths