1.1.3 • Published 6 years ago

hinos-validation v1.1.3

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

hinos-validation

A plugin inject function help validates bean before using hinos

Install

npm i hinos-validation -S

Examples

Typescript

File service

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;
    }
}
1.1.3

6 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago