# การตรวจสอบความถูกต้องและ DTO (Node.js / NestJS) > class-validator, class-transformer, DTO, ValidationPipe, custom validators, sanitization - 20 คำถามสัมภาษณ์ - Junior - [คำถามสัมภาษณ์: Node.js / NestJS](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions.md) ## 1. DTO (Data Transfer Object) ใน NestJS คืออะไร? **คำตอบ** DTO คือคลาส TypeScript ที่กำหนดโครงสร้างของข้อมูลที่ส่งผ่านระหว่างไคลเอนต์และเซิร์ฟเวอร์ ทำหน้าที่เป็นสัญญาข้อมูลและช่วยให้ตรวจสอบความถูกต้องของอินพุตได้โดยอัตโนมัติด้วย decorator เช่น @IsString หรือ @IsNumber DTO ช่วยเพิ่มความปลอดภัยโดยการกรองคุณสมบัติที่ไม่ได้รับอนุญาตและทำให้การบำรุงรักษาโค้ดง่ายขึ้น ## 2. แพ็กเกจใดที่ช่วยให้เพิ่มข้อจำกัดการตรวจสอบความถูกต้องให้กับ DTO ได้? **คำตอบ** แพ็กเกจ class-validator มอบ decorator สำหรับการตรวจสอบความถูกต้อง เช่น @IsString, @IsEmail, @Min, @Max ที่ช่วยให้กำหนดกฎการตรวจสอบบนคุณสมบัติของ DTO ได้ มันทำงานร่วมกับ ValidationPipe เพื่อตรวจสอบข้อมูลขาเข้าโดยอัตโนมัติ แพ็กเกจนี้ถูกใช้อย่างแพร่หลายในระบบนิเวศ NestJS เพื่อรับประกันความสมบูรณ์ของข้อมูล ## 3. decorator ใดที่ตรวจสอบว่าคุณสมบัติเป็นสตริง? **คำตอบ** decorator @IsString ตรวจสอบว่าคุณสมบัติเป็นชนิด string มันถูกนำไปใช้กับคุณสมบัติของ DTO โดยตรงและปฏิเสธค่าใดๆ ที่ไม่ใช่สตริงโดยอัตโนมัติ decorator นี้เป็นหนึ่งในตัวที่ใช้บ่อยที่สุดเพราะครอบคลุมกรณีการตรวจสอบที่พบบ่อยมากใน REST API ## มีอีก 17 คำถาม - ควรกำหนดค่า ValidationPipe ที่ไหนเพื่อตรวจสอบทุกเส้นทาง (route) ของแอปพลิเคชัน? - decorator ใดที่ตรวจสอบว่าฟิลด์ไม่ว่างเปล่า? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Node.js / NestJS อื่นๆ - [พื้นฐาน Node.js](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/nodejs-fundamentals.md): 20 คำถาม, Junior - [Core API ของ Node.js](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/nodejs-core-apis.md): 25 คำถาม, Junior - [การเขียนโปรแกรมแบบอะซิงโครนัส](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/asynchronous-programming.md): 25 คำถาม, Junior - [พื้นฐาน Express.js](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/express-basics.md): 20 คำถาม, Junior - [พื้นฐาน NestJS](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/nestjs-fundamentals.md): 23 คำถาม, Junior - [การออกแบบ REST API](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/rest-api-design.md): 20 คำถาม, Junior - [เอกสาร API และ Contract](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/api-documentation.md): 20 คำถาม, Junior - [การจัดการข้อผิดพลาด](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/error-handling.md): 20 คำถาม, Junior - [การทดสอบหน่วย (Unit Testing)](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/testing-unit.md): 20 คำถาม, Junior - [การจัดตารางงาน](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/scheduling-cron.md): 15 คำถาม, Junior - [Module และ DI ของ NestJS](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/nestjs-modules-di.md): 20 คำถาม, Mid-Level - [การกำหนดค่าและการจัดการสภาพแวดล้อม](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/configuration-environment.md): 20 คำถาม, Mid-Level - [การยืนยันตัวตนด้วย JWT](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/authentication-jwt.md): 25 คำถาม, Mid-Level - [การให้สิทธิ์และ RBAC](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/authorization-rbac.md): 20 คำถาม, Mid-Level - [ฐานข้อมูลด้วย TypeORM](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/database-typeorm.md): 30 คำถาม, Mid-Level - [Prisma ORM](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/prisma-orm.md): 25 คำถาม, Mid-Level - [Middleware และ Interceptor](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/middleware-interceptors.md): 20 คำถาม, Mid-Level - [การอัปโหลดไฟล์](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/file-upload.md): 15 คำถาม, Mid-Level - [WebSockets](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/websockets.md): 20 คำถาม, Mid-Level - [GraphQL กับ NestJS](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/graphql-basics.md): 25 คำถาม, Mid-Level - [การทดสอบแบบ End-to-End](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/testing-e2e.md): 20 คำถาม, Mid-Level - [การแคชด้วย Redis](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/caching-redis.md): 20 คำถาม, Mid-Level - [คิวด้วย Bull](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/queues-bull.md): 20 คำถาม, Mid-Level - [DevOps, Logging และ CI/CD](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/logging-monitoring.md): 25 คำถาม, Mid-Level - [Docker และ Containerization](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/docker-containerization.md): 25 คำถาม, Mid-Level - [ไมโครเซอร์วิส](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/microservices.md): 30 คำถาม, Senior - [แนวทางปฏิบัติที่ดีที่สุดด้านความปลอดภัย](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/security-best-practices.md): 25 คำถาม, Senior - [ประสิทธิภาพและการ Deploy บน Cloud](https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/performance-optimization.md): 30 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/node-nestjs/interview-questions/validation-dto