import { getRepository } from 'typeorm' ; import { User } from '../../entity' ; export function uniqueEmail ( data , field , message , args , get ) { return new Promise ( ( resolve , reject ) => { const email = get ( data , field ) ; getRepository ( User ) . findOne ( { where : { email } } ) . then ( u => { return u ? reject ( `Email address already exists.` ) : resolve ( ) ; } , e => { reject ( e . message ) ; } ) ; } ) ; }