0.0.4 • Published 3 years ago
te2ys v0.0.4
te2ys
TypeORM Entity 2 Yup Schema
Usage
import te2ys from 'te2ys'
import { User } from 'User.entity.ts'
import { getRepository } from 'typeorm'
const userRepository = getRepository( User, 'default' )
const userSchemas = te2ys( User, { connectionName: 'default' } )
const userInsertSchema = userSchemas.insert()
userInsertSchema.validate( {
name: 'Some name',
email: 'some-email@some.com'
} )
.then( result => userRepository.insert( result ) )
.catch( ( yupValidateError ) => {} )
userInsertSchema.validate( [ {
name: 'Some another name',
email: 'some-another-email@some.com'
}, {
name: 'Another some',
email: 'another-some@some.com'
} ] )
.then( result => userRepository.insert( result ) )
.catch( ( yupValidateError ) => {} )