# hinos-validation

> Plugin help validate bean before use in server layer

Latest version **1.1.3** (published 2018-04-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install hinos-validation
pnpm add hinos-validation
yarn add hinos-validation
bun add hinos-validation
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2018-04-04 |
| First published | 2017-05-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | doanthuanthanh88@gmail.com |
| Maintainers | doanthuanthanh88 |

## Links

- npm: https://www.npmjs.com/package/hinos-validation
- npm.io page: https://npm.io/package/hinos-validation

## Dependencies (1)

- [hinos-utils](https://npm.io/package/hinos-utils.md) ^2.0.3

## Recent versions

- 1.1.3 (latest) — 2018-04-04
- 1.1.2 — 2017-08-07
- 1.1.1 — 2017-07-22
- 1.1.0 — 2017-07-13
- 1.0.12 — 2017-07-12
- 1.0.11 — 2017-07-12
- 1.0.10 — 2017-07-12
- 1.0.9 — 2017-07-12
- 1.0.8 — 2017-07-12
- 1.0.7 — 2017-07-05
- 1.0.6 — 2017-06-28
- 1.0.5 — 2017-05-30
- 1.0.4 — 2017-05-30
- 1.0.3 — 2017-05-26
- 1.0.2 — 2017-05-24
- … 2 more at https://npm.io/package/hinos-validation/versions

## README

# hinos-validation
A plugin inject function help validates bean before using [hinos](https://github.com/doanthuanthanh88/hinos)

# Install
```nodejs
npm i hinos-validation -S
```

# Examples

### Typescript
File service
```nodejs
import { VALIDATE, Checker } from 'hinos-validation';
import { MONGO, Mongo, Uuid, Collection } from 'hinos-mongo';

export class ChartService {
    @MONGO()
    static mongo: Mongo;
    
    @VALIDATE((body: Chart) => { 
        body._id = <Uuid>Mongo.uuid();
        Checker.must('project_id', body.project_id, Uuid);
        Checker.must('account_id', body.account_id, Uuid);
        Checker.must('page_id', body.page_id, Uuid);
        Checker.must('oder', body.oder, Number, 1);
        Checker.must('name', body.name, String);
        Checker.option('des', body.des, String);
        Checker.must('options', body.options, Object);
        body.created_at = new Date();
        body.updated_at = new Date();
    })
    static async insert(body: Chart, validate?: Function): Promise<Chart> {
        // Auto call validate
        const rs: Chart = await ChartService.mongo.insert<Chart>(Chart, body);
        return rs;
    }
    
    @VALIDATE((body: Chart) => {
        body._id = <Uuid>Mongo.uuid();
        Checker.must('project_id', body.project_id, Uuid);
        Checker.must('account_id', body.account_id, Uuid);
        Checker.must('page_id', body.page_id, Uuid);
        Checker.must('oder', body.oder, Number, 1);
        Checker.must('name', body.name, String);
        Checker.option('des', body.des, String);
        Checker.must('options', body.options, Object);
        body.created_at = new Date();
        body.updated_at = new Date();
    }, false)
    static async insertManual(body: Chart, validate?: Function): Promise<Chart> {
        validate(body); // Customize call validate
        const rs: Chart = await ChartService.mongo.insert<Chart>(Chart, body);
        return rs;
    }
}
```

---
_Source: https://npm.io/package/hinos-validation · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
