import { BaseRepository } from '../base-repository' ; import { SubscriberEntity } from './subscriber.entity' ; import { Subscriber } from './subscriber.schema' ; export class SubscriberRepository extends BaseRepository < SubscriberEntity > { constructor ( ) { super ( Subscriber , SubscriberEntity ) ; } async findBySubscriberId ( applicationId , subscriberId ) { return await this . findOne ( { _applicationId : applicationId , subscriberId , } ) ; } async searchSubscriber ( applicationId , search ) { return await this . findOne ( { _applicationId : applicationId , $or : [ { email : { $regex : regExpEscape ( search ) , $options : 'i' , } , } , { subscriberId : search , } , ] , } ) ; } } function regExpEscape ( literal_string ) { return literal_string . replace ( /[-[\]{}()*+!<=:?./\\^$|#\s,]/g , '\\$&' ) ; }