NestJS? ??? ??? ??? ? ??? ???? zod ??
zod? ??? ??? ? ??? ??? ??? ?????? ??? ??????.
NestJS? ?? ?????? ?????.
??
?? ?? ????.
1. ??? ??? ? ??? ???? ???? ??
- NestJS?? ????? ?? ???? ?? ??????
- ?? ??? ????? ?? ??? ???? ??? ?? NestJS???.
- ??? ??? ? ValidationPipe? ???? ???? ??? ??
2. Zod? ??? ??
- ?????? ???? ??
- ?? ???????
- ??? ? ??? ?? ?? ?? ? ???? ???
- ?? ? ?? ??? ??
??
class-validator ? class-transformer? NestJS?? ??? ??? ?? ????? ???? 2?? ??????.
?, ????? ??,
? ???? ?? ??? NestJS? ????? ?? ???.
?? ValidationPipe? ?? DTO
??? ????? ??? ?? ???/????? ?? ??? ?? ?? ? ??/???????.
??? Zod? ??? ???/????? ???? ???? ???.
?, 1??? ?? 3??? ?????
?? ?? ??? ? ?? ????? ?? ????? ? ?? ?????.
?? ????
??? ??? ?? ?? ??(???? ? ??)???.
??? ??? ??? ? ??? ???
1. ??
npm install class-validator class-transformer
2. ??? ?? ???
// main.ts .... import { ValidationPipe } from '@nestjs/common'; async function bootstrap() { .... // Enable validation globally app.useGlobalPipes(new ValidationPipe({ transform: true, // Automatically transform payloads to DTO instances whitelist: true, // Strip unknown properties forbidNonWhitelisted: true, // Throw error for unknown properties })); .... } ....
3. DTO(??? ?? ??) ??
import { IsNotEmpty, IsString, IsInt, Min } from "class-validator"; import { Type, Transform } from "class-transformer"; export class CreateUserDto { @Transform(({ value }) => value.trim()) // Trim whitespaces @IsNotEmpty({ message: "Nama tidak boleh kosong" }) @IsString({ message: "Nama harus berupa string" }) @Min(3, { message: "Minimal panjang nama 3 karakter" }) name: string; @Type(() => Number) // Transform input ke tipe Number @IsNotEmpty({ message: "Nama tidak boleh kosong" }) @IsInt({ message: "Umur harus berupa bilangan bulat" }) @Min(17, { message: "Minimal umur terdaftar 17 tahun" }) age: number; }
? ??? ????? ?????.
4. ??? ??
import { Body, Controller, Post } from "@nestjs/common"; import { CreateUserDto } from "./create-user.dto"; @Controller("users") export class UsersController { @Post() create(@Body() createUserDto: CreateUserDto) { // Pada titik ini data/payload createUserdDto // sudah tervalidasi & diubah sesuai definisinya // developer bisa langsung eksekusi service // atau logic yang lain } }
??
1. ??
npm install zod
2. ?? ?? ??
// user.validaiton.ts import { z, ZodType } from "zod"; export class UserValidation { static readonly CREATE: ZodType = z.object({ name: z .string({ message: "Nama harus berupa string" }) .nonempty({ message: "Nama tidak boleh kosong" }) .min(3, "Minimal panjang nama 13 karakter"), age: z .number({ message: "Umur harus berupa angka" }) .int({ message: "Umur harus berupa bilangan bulat" }) .min(17, "Minimal umur terdaftar 17 tahub"), }); } export type TCreateUserPayload = z.infer<typeof UserValidation.CREATE>;
*???: ?? ????? ? ???? ?? ?? ? ????
3. ??? ??
import { Body, Controller, Post } from "@nestjs/common"; import { UserValidation, TCreateUserPayload } from "./user.validation.ts"; @Controller("users") export class UsersController { @Post() create(@Body() createUserPayload: TCreateUserPayload) { const payload = UserValidation.CREATE.parse(createUserPayload); // Pada titik ini data/payload payload // sudah tervalidasi & diubah sesuai definisinya // developer bisa langsung eksekusi service // atau logic yang lain } }
??
?????? Zod? ???? ??? ?????.
??, ???? ? ?? ?? ??? ??? ?? ???? ????.
https://abdulghofurme.github.io/posts/zod-vs-class-validator-n-class-transformer/
? ??? zod ? ??? ??? ??? ? ??? ???? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











Java ? JavaScript? ?? ?? ????? ??? ?? ?? ?? ???? ????? ?????. Java? ??? ? ??? ?????? ??? ???? JavaScript? ?? ? ??? ??? ?????.

CommentAreCrucialInjavaScriptFormainingClarityandFosteringCollAboration.1) 1) thehelpindebugging, onboarding ? undervestandingStandingCodeevolution.2) awithy-linecommentsforquickexplanationsandmulti-linecommentsfordeTailedDescriptions.3) BestPricticesInclud

JavaScriptCommentsareEnsentialformaining, ?? ? ???? 1) Single-LinecommentsERUSEDFORQUICKEXPLANATIONS.2) Multi-linecommentSexplaincleClexLogicOrprovidedEdeDDocumentation.3) inlineecommentsClarifySpecificPartSofcode.bestPractic

javascriptassseveralprimitavivedatatatatatypes : ??, ???, ??, ????, null, ??, andbigint, andnon-primitiveTypes like-rucial-writingefficial, numberusesa64-bitformat, leadingtofloating-pointsli

JavaScript?? ??? ??? ?? ? ? ?? ??? ???????. 1. ?? ??? ??? ???? ?? ??? ????. ISO ?? ???? ???? ???? ???? ?? ????. 2. ?? ??? ?? ???? ??? ?? ???? ??? ? ??? ? ?? 0?? ????? ?? ??????. 3. ?? ?? ???? ???? ???? ?? ?????? ??? ? ????. 4. Luxon? ?? ???? ???? ?????? ???? ?? ????. ??? ?? ???? ????? ???? ??? ????? ?? ? ????.

JavaScriptIspreferredforwebDevelopment, whithjavaisbetterforlarge-scalebackendsystemsandandandoidapps.1) javascriptexcelsincreatinginteractivewebexperiences withitsdynatureanddommanipulation.2) javaoffersstrongtypingandobject-Orientededededededededededededededededdec

javascriptassevenfundamentalDatatatypes : ??, ???, ??, unull, ??, ? symbol.1) ?? seAdouble-precisionformat, ??? forwidevaluerangesbutbecautiouswithfatingfointarithmetic.2) stringsareimmutable, useefficientconcatenationmethendsf

TAGGSATTHEBOTTOMOFABLOGPOSTORWEBPAGESERVESPRACTICALPURSEO, USEREXPERIENCE, andDESIGN.1.ITHELPSWITHEOBYOWNSESPORENGENSTOESTOCESKESKERKESKERKERKERDER-RELEVANTTAGSWITHOUTHINGTEMAINCONTENT.2.ITIMPROVESEREXPERKEEPINGTOPONTEFOCUSOFOFOFOCUSOFOFOFOCUCUSONTHEATECLL
