te2ys
v0.0.4
Published
Typeorm entity to Yup schema
Downloads
2
Readme
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: '[email protected]'
} )
.then( result => userRepository.insert( result ) )
.catch( ( yupValidateError ) => {} )
userInsertSchema.validate( [ {
name: 'Some another name',
email: '[email protected]'
}, {
name: 'Another some',
email: '[email protected]'
} ] )
.then( result => userRepository.insert( result ) )
.catch( ( yupValidateError ) => {} )