import { OrganizationData } from './../../enterprise/entity/organization.entity'; import { Repository } from 'typeorm'; import { UserData } from '../entity/user.entity'; import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; @Injectable() export class UserRepository { constructor( @InjectRepository(UserData) private userRepository: Repository, ) {} async findById(userId: number): Promise { return this.userRepository.findOne({ where: { id: userId } }); } async findByEmailId( email: string, organization_id?: number, ): Promise { if (!email) return null; const where: any = { email_id: email }; if (organization_id !== undefined) { where.organization_id = organization_id; } return this.userRepository.findOne({ where }); } async findByMobile( mobile: string, organization_id?: number, appCode?: string, ): Promise { if (!mobile) return null; const where: any = { mobile }; if (organization_id !== undefined) { where.organization_id = organization_id; } if (appCode !== undefined) { where.appcode = appCode; } return this.userRepository.findOne({ where }); } async saveUser(user: UserData): Promise { return this.userRepository.save(user); } }