| 7 | import { FileManagerService } from '../utils/fileManager.service'; |
| 8 | import { promises as fs } from 'fs'; |
| 9 | export class AuthFileManager { |
| 10 | constructor(private readonly fileManagerService: FileManagerService) {} |
| 11 | |
| 12 | async createFile(name: string, content: string, path: string): Promise<void> { |
| 13 | const authFolderPath = join(process.cwd(), 'src', path); |
| 14 | |
| 15 | let moduleContent = content; |
| 16 | let filename = name; |
| 17 | |
| 18 | try { |
| 19 | const filePath = join(authFolderPath, filename); |
| 20 | await writeFile(filePath, moduleContent); |
| 21 | console.log(`${filename} created successfully `); |
| 22 | } catch (err) { |
| 23 | console.error(`Failed to create ${filename} in auth folder:`, err); |
| 24 | throw err; // Rethrow the error to handle it further if needed |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | async createServices(): Promise<void> { |
| 29 | let filename = ``; |
| 30 | let authServiceContent = ` |
| 31 | /* eslint-disable prettier/prettier */ |
| 32 | import { Injectable } from '@nestjs/common'; |
| 33 | import { UsersService } from '../users/users.service'; |
| 34 | import * as bcrypt from 'bcryptjs'; |
| 35 | import { MailerService } from '@nestjs-modules/mailer'; |
| 36 | import { CreateUserDto } from '../users/dto/create-user.dto'; |
| 37 | |
| 38 | @Injectable() |
| 39 | export class AuthService { |
| 40 | constructor( |
| 41 | private usersService: UsersService, |
| 42 | private readonly mailerService: MailerService, |
| 43 | ) {} |
| 44 | |
| 45 | async validateUserById( |
| 46 | id: number, |
| 47 | pass: string, |
| 48 | ): Promise<Omit<CreateUserDto, 'password'> | null> { |
| 49 | const user = await this.usersService.findOne(id); |
| 50 | if ( |
| 51 | user && |
| 52 | typeof user !== 'string' && |
| 53 | (await bcrypt.compare(pass, user.password)) |
| 54 | ) { |
| 55 | const { password, ...result } = user; |
| 56 | return result; |
| 57 | } |
| 58 | return null; |
| 59 | } |
| 60 | |
| 61 | async validateUserByEmail( |
| 62 | email: string, |
| 63 | pass: string, |
| 64 | ): Promise<Omit<CreateUserDto, 'password'> | null> { |
| 65 | const user = await this.usersService.findByEmail(email); |
| 66 | if ( |
nothing calls this directly
no outgoing calls
no test coverage detected