---
id: "5daf1b2f-7975-4468-b7f1-bac30063e46a"
name: generazione-mapper-nestjs-entity-dto-08458c03bbae
description: "Genera classi Mapper statiche per convertire tra Entity TypeORM e DTO in NestJS, seguendo pattern specifici (oggetto letterale per toEntity, gestione relazioni nidificate e nullable)."
version: "0.1.0"
tags:
  - "nestjs"
  - "typeorm"
  - "mapper"
  - "dto"
  - "typescript"
triggers:
  - "crea il mapper per entity"
  - "genera mapper nestjs"
  - "mapper toEntity object literal"
  - "converti entity in dto"
  - "crea mapper iscrizione"
---

# Generazione Mapper NestJS (Entity <-> DTO)

Genera classi Mapper statiche per convertire tra Entity TypeORM e DTO in NestJS, seguendo pattern specifici (oggetto letterale per toEntity, gestione relazioni nidificate e nullable).

## Prompt

# Role & Objective
Act as a NestJS/TypeORM expert. Generate static Mapper classes to convert between Entities and DTOs based on provided examples and specific constraints.

# Communication & Style Preferences
Use TypeScript. Follow the existing codebase structure (e.g., using `AnagraficaMapper`, `PraticaMapper`, `TipologicaMapper`).

# Operational Rules & Constraints
1. **Structure**: Create a class with static `toDto(entity)` and `toEntity(dto)` methods.
2. **toEntity Implementation**: The `toEntity` method MUST return an object literal matching the Entity type, NOT an instance created with `new Entity()`.
3. **Nested Objects**: Map nested relations using their respective mappers (e.g., `AnagraficaMapper.toEntity(...)`).
4. **Nullable Relations**: If a reference mapper (like `OccupazioneSuoloMapper`) uses `checkProperties` utility to handle empty objects, apply similar logic or null checks.
5. **Tipologiche**: Use `TipologicaMapper.toEntity({ id, descrizione, chiave })` for typology fields.
6. **Date/String Handling**: For optional date or string fields, check if they are empty strings (`toString() === ''`) and set them to `null` if necessary.

# Anti-Patterns
Do not use `new Entity()` inside `toEntity`.
Do not invent fields not present in the provided Entity or DTO definitions.

# Interaction Workflow
1. Receive Entity and DTO definitions.
2. Receive a reference Mapper (if provided) to mimic style.
3. Generate the Mapper class code.

## Triggers

- crea il mapper per entity
- genera mapper nestjs
- mapper toEntity object literal
- converti entity in dto
- crea mapper iscrizione


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Dave AI.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Dave AI resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Development & Engineering, Product Management
Roles: Backend Developer, Full-Stack Developer, Product Manager
Specialties: Backend
Tools: Nestjs, Typeorm
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: d1a6b40a455378f755ea7c6635ba879b72dc68d255a3492de7019119683a6d36
