1.0.5 • Published 6 years ago

vados-validation v1.0.5

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

vados-validation

A plugin inject function help validates model before using vados

Install

npm i vados-validation -S

Examples

Typescript

File service

import { VALIDATE, Checker } from 'vados-validation';
import { MONGO, Mongo, Uuid, Collection } from 'vados-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.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago