Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/quantumsheep/class-validator-mongo-object-id

Add a decorator to validate MongoDB's ObjectId using class-validator
https://github.com/quantumsheep/class-validator-mongo-object-id

class-validator mongodb mongoose nestjs objectid validator

Last synced: 16 days ago
JSON representation

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

Awesome Lists containing this project

README

        

[![npm](https://img.shields.io/npm/v/class-validator-mongo-object-id)](https://www.npmjs.com/package/class-validator-mongo-object-id)

# 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
```bash
npm install --save class-validator-mongo-object-id
```

## How to use
Here is an example along with commonly used `IsString` from [`class-validator`](https://github.com/typestack/class-validator) package.

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

class EditUserDTO {
@IsObjectId()
userId: string;

@IsString()
username: string;
}
```