Skip to content

Commit

Permalink
Merge pull request #65 from PatrickOtero/main
Browse files Browse the repository at this point in the history
Fixes and refactoring
  • Loading branch information
PatrickOtero authored Feb 1, 2024
2 parents 852ea43 + 6ae5b79 commit f39c4dd
Show file tree
Hide file tree
Showing 45 changed files with 939 additions and 589 deletions.
2 changes: 1 addition & 1 deletion src/modules/mails/mail.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { MailService } from './mail.service';
from: `no-reply <[email protected]>`,
},
template: {
dir: join(__dirname, '../../../templates'),
dir: join(__dirname, 'templates'),
adapter: new HandlebarsAdapter(),
options: {
strict: true,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@
</td>
</tr>
</table>
</body>
</body>
</html>
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';

export class ActiveMentorDto {
export class ActivateMentorDto {
@IsNotEmpty()
@IsString()
@ApiProperty({
Expand Down
64 changes: 47 additions & 17 deletions src/modules/mentors/mentor.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import { Response } from 'express';
import { SwaggerConfirmEmail } from '../../shared/Swagger/decorators/confirm-email.swagger.decorator';
import { SwaggerCreateMentor } from '../../shared/Swagger/decorators/mentor/create-mentor.swagger.decorator';
import { SwaggerGetMentor } from '../../shared/Swagger/decorators/mentor/get-mentor.swagger.decorator';
import { ActiveMentorDto } from './dtos/active-mentor.dto';
import { ActivateMentorDto } from './dtos/activate-mentor.dto';
import { CreateMentorDto } from './dtos/create-mentor.dto';
import { SearchMentorDto } from './dtos/search-mentor.dto';
import { UpdateMentorDto } from './dtos/update-mentor.dto';
import { MentorService } from './mentor.service';
import { SearchByEmailDto } from './dtos/search-by-email.dto';
import { MentorPassConfirmationDto } from './dtos/mentor-pass-confirmation.dto';
import { SwaggerRestoreAccountEmail } from 'src/shared/Swagger/decorators/mentor/classes/restoreAccountEmail.swagger';
Expand All @@ -34,22 +33,50 @@ import { SwaggerUpdateMentorById } from 'src/shared/Swagger/decorators/mentor/up
import { GetByIdDto } from './dtos/get-by-id.dto copy';
import { SwaggerRestoreAccount } from 'src/shared/Swagger/decorators/restore-account.swagger.decorator';
import { MentorChangePassDto } from './dtos/mentor-change-pass.dto';
import { ActivateMentorService } from './services/activateMentor.service';
import { ChangeMentorPasswordService } from './services/changeMentorPassword.service';
import { CreateMentorService } from './services/createMentor.service';
import { DesactivateLoggedMentorService } from './services/deactivateLoggedMentor.service';
import { GetMentorByIdService } from './services/getMentorById.service';
import { GetMentorByNameAndRoleService } from './services/getMentorByNameAndRole.service';
import { ListAllMentorsService } from './services/listAllMentors.service';
import { RedefineMentorPasswordService } from './services/redefineMentorPassword.service';
import { SendRestorationEmailService } from './services/sendRestorationEmail.service';
import { UpdateMentorService } from './services/updateMentor.service';
import { UploadProfileImageService } from './services/uploadProfileImage.service';
import { FinishMentorRegisterService } from './services/finishMentorRegisterService.service';
import { SwaggerCompleteRegister } from 'src/shared/Swagger/decorators/complete-register.swagger';
import { SwaggerChangePassword } from 'src/shared/Swagger/decorators/change-password.swagger';
import { SwaggerUploadProfileImage } from 'src/shared/Swagger/decorators/uploadProfileImage.swagger';

@ApiTags('mentor')
@Controller('mentor')
export class MentorController {
constructor(private mentorService: MentorService) {}
constructor(
private activateMentorService: ActivateMentorService,
private changeMentorPasswordService: ChangeMentorPasswordService,
private createMentorService: CreateMentorService,
private deactivateLoggedMentorService: DesactivateLoggedMentorService,
private getMentorByIdService: GetMentorByIdService,
private getMentorByNameAndRoleService: GetMentorByNameAndRoleService,
private listAllMentorsService: ListAllMentorsService,
private redefineMentorPasswordService: RedefineMentorPasswordService,
private sendRestorationEmailService: SendRestorationEmailService,
private updateMentorService: UpdateMentorService,
private uploadProfileImageService: UploadProfileImageService,
private finishMentorRegisterService: FinishMentorRegisterService
) {}

@Post()
@SwaggerCreateMentor()
async createMentor(@Body() createMentorDto: CreateMentorDto) {
return this.mentorService.createMentor(createMentorDto);
return this.createMentorService.execute(createMentorDto);
}

@ApiExcludeEndpoint()
@Get()
async getAllMentors() {
return this.mentorService.getAllMentors();
return this.listAllMentorsService.execute();
}

@Get('search')
Expand All @@ -58,7 +85,7 @@ export class MentorController {
@Res() res: Response,
@Query() { fullName, specialty }: SearchMentorDto
) {
const data = await this.mentorService.findMentorByNameAndRole(
const data = await this.getMentorByNameAndRoleService.execute(
fullName,
specialty,
);
Expand All @@ -72,7 +99,7 @@ export class MentorController {
@Param() { id }: GetByIdDto,
@Res() res: Response,
) {
const { status, data } = await this.mentorService.findMentorById(id);
const { status, data } = await this.getMentorByIdService.execute(id);

return res.status(status).send(data);
}
Expand All @@ -85,62 +112,65 @@ export class MentorController {
@LoggedEntity() mentor: MentorEntity,
@Body() data: UpdateMentorDto,
) {
return await this.mentorService.updateMentor(mentor.id, data);
return await this.updateMentorService.execute(mentor.id, data);
}

@ApiBearerAuth()
@UseGuards(AuthGuard())
@SwaggerChangePassword()
@Put('change_password')
async changeMentorPassword(
@LoggedEntity() mentor: MentorEntity,
@Body() data: MentorChangePassDto,
) {
return await this.mentorService.changeMentorPassword(mentor, data);
return await this.changeMentorPasswordService.execute(mentor, data);
}

@ApiBearerAuth()
@UseGuards(AuthGuard())
@UseInterceptors(FileInterceptor("file"))
@SwaggerUploadProfileImage()
@Post("uploadProfileImage")
async uploadProfileImage(@LoggedEntity() mentor: MentorEntity, @UploadedFile("file") file) {

return await this.mentorService.uploadProfileImage(mentor.id, mentor, file )
return await this.uploadProfileImageService.execute(mentor.id, mentor, file )
}

@Patch('active')
@SwaggerConfirmEmail()
async activeMentor(@Query() queryData: ActiveMentorDto, @Res() res: Response) {
const { data, status } = await this.mentorService.activeMentor(queryData);
async activeMentor(@Query() queryData: ActivateMentorDto, @Res() res: Response) {
const { data, status } = await this.activateMentorService.execute(queryData);
return res.status(status).send(data);
}

@ApiExcludeEndpoint()
@Patch(':id')
async desactivateLoggedEntity(@Param() { id }: GetByIdDto) {
return this.mentorService.desactivateLoggedMentor(id);
return this.deactivateLoggedMentorService.execute(id);
}

@SwaggerRestoreAccountEmail()
@Post('restoreAccount/:email')
async restoreAccount(@Param() { email }: SearchByEmailDto) {
return this.mentorService.sendRestorationEmail(email);
return this.sendRestorationEmailService.execute(email);
}

@Patch('restoreAccount/redefinePass')
@SwaggerRestoreAccount()
async redefineMentorPassword(
@Query() queryData: ActiveMentorDto,
@Query() queryData: ActivateMentorDto,
@Body() passData: MentorPassConfirmationDto,
) {
return this.mentorService.redefineMentorPassword(queryData, passData);
return this.redefineMentorPasswordService.execute(queryData, passData);
}

@ApiBearerAuth()
@UseGuards(AuthGuard())
@SwaggerCompleteRegister()
@Post('completeRegister')
async finishMentorRegister(@LoggedEntity() mentor: MentorEntity) {
try {
return this.mentorService.finishMentorRegister(mentor.id)
return this.finishMentorRegisterService.execute(mentor.id)
} catch (error) {
console.log(error.message)
}
Expand Down
15 changes: 13 additions & 2 deletions src/modules/mentors/mentor.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@ import { PassportModule } from '@nestjs/passport';
import { GenerateCodeUtil } from '../../shared/utils/generate-code.util';
import { MailModule } from '../mails/mail.module';
import { MentorController } from './mentor.controller';
import { MentorService } from './mentor.service';
import { MentorRepository } from './repository/mentor.repository';
import { FileUploadService } from '../upload/upload.service';
import { CreateMentorService } from './services/createMentor.service';
import { UpdateMentorService } from './services/updateMentor.service';
import { ListAllMentorsService } from './services/listAllMentors.service';
import { GetMentorByIdService } from './services/getMentorById.service';
import { GetMentorByNameAndRoleService } from './services/getMentorByNameAndRole.service';
import { ActivateMentorService } from './services/activateMentor.service';
import { ChangeMentorPasswordService } from './services/changeMentorPassword.service';
import { DesactivateLoggedMentorService } from './services/deactivateLoggedMentor.service';
import { FinishMentorRegisterService } from './services/finishMentorRegisterService.service';
import { RedefineMentorPasswordService } from './services/redefineMentorPassword.service';
import { SendRestorationEmailService } from './services/sendRestorationEmail.service';
import { UploadProfileImageService } from './services/uploadProfileImage.service';

@Module({
imports: [MailModule, PassportModule.register({ defaultStrategy: 'jwt' })],
controllers: [MentorController],
providers: [MentorService, MentorRepository, GenerateCodeUtil, FileUploadService],
providers: [CreateMentorService, UpdateMentorService, ListAllMentorsService, GetMentorByIdService, GetMentorByNameAndRoleService, ActivateMentorService, ChangeMentorPasswordService, DesactivateLoggedMentorService, FinishMentorRegisterService, RedefineMentorPasswordService, SendRestorationEmailService, UploadProfileImageService, MentorRepository, GenerateCodeUtil, FileUploadService],
exports: [MentorRepository],
})
export class MentorModule {}
Loading

0 comments on commit f39c4dd

Please sign in to comment.