import { Injectable } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { UserData } from '../../user/entity/user.entity'; import { ReflectionHelper } from '../../../utils/service/reflection-helper.service'; @Injectable() export class AuthService { constructor( private jwtService: JwtService, private reflectionHelper: ReflectionHelper, ) {} // async validateUser(email: string, password: string): Promise { // const user = await this.userService.findByEmailId(email); // if (!user) { // throw new BadRequestException('User not found'); // } // const isMatch: boolean = password === user.password; // if (!isMatch) { // throw new BadRequestException('Password does not match'); // } // return user; // } async login(user: UserData) { const payload = { email: user.email_id, id: user.id }; return { access_token: this.jwtService.sign(payload) }; } async fcmtoken( fcmtoken: string, loggedInUser: any, ip: string, browser: string, os: string, ) { const { id: userId, sessionToken } = loggedInUser; const userSessionRepo = this.reflectionHelper.getRepoService('UserSession'); let userSessions = await userSessionRepo.find({ where: { session_key: sessionToken, user_id: userId } }); for( let session of userSessions ) { session.fcm_token = fcmtoken; session.ip = ip; session.browser = browser; session.os = os; await userSessionRepo.save(session); } return { message: 'FCM token updated successfully' }; } }