Skip to content

Add a decorator to validate MongoDB's ObjectId using class-validator

License

Notifications You must be signed in to change notification settings

quantumsheep/class-validator-mongo-object-id

Repository files navigation

npm

ObjectId Class Validator

This package validates ObjectId in classes. It was originally made to be used in NestJS but works everywhere else.

How to install

npm install --save class-validator-mongo-object-id

How to use

Here is an example along with commonly used IsString from class-validator package.

import { IsString } from 'class-validator';
import { IsObjectId } from 'class-validator-mongo-object-id';

class EditUserDTO {
    @IsObjectId()
    userId: string;

    @IsString()
    username: string;
}

About

Add a decorator to validate MongoDB's ObjectId using class-validator

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages