@wisemen/address
v0.2.6
Published
TypeScript address model with NestJS integration, TypeORM column support, and validation.
Maintainers
Keywords
Readme
@wisemen/address
TypeScript address model with NestJS integration, TypeORM column support, and validation.
Installation
pnpm add @wisemen/addressUsage
Basic Address Model
import { Address } from '@wisemen/address'
const address = new Address()
address.placeName = 'Home'
address.streetName = 'Main Street'
address.streetNumber = '123'
address.city = 'New York'
address.postalCode = '10001'
address.country = 'USA'TypeORM Column
import { Entity, PrimaryGeneratedColumn } from 'typeorm'
import { AddressColumn } from '@wisemen/address'
@Entity()
class User {
@PrimaryGeneratedColumn('uuid')
id: string
@AddressColumn({ nullable: true })
address: Address | null
}NestJS DTO Validation
import { AddressCommand } from '@wisemen/address'
class CreateUserDto {
@ValidateNested()
@Type(() => AddressCommand)
address: AddressCommand
}NestJS Response
import { AddressResponse } from '@wisemen/address'
@Get()
async getUser(): Promise<UserResponse> {
const user = await this.userService.findOne()
return {
id: user.id,
address: user.address ? new AddressResponse(user.address) : null
}
}Custom Validator
import { IsAddress } from '@wisemen/address'
class LocationDto {
@IsAddress()
address: Address
}License
GPL
