Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/src/modules/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class EmailService {
});

async sendResetPasswordEmail(email: string, token: string) {
const resetLink = `myapp://reset-password?token=${token}`;
const resetLink = `frontend://resetPassword?token=${token}`;

await this.transporter.sendMail({
to: email,
Expand Down
38 changes: 37 additions & 1 deletion backend/src/modules/file/application/file.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { FileDocument } from '../infra/schemas/file.schema';
Expand Down Expand Up @@ -127,6 +127,24 @@ async uploadProfileImage(
return user.profileImage;
}

async deleteUserProfileImage(userId: string): Promise<void> {
const user = await this.userModel.findById(userId);

if (!user) {
throw new NotFoundException('User not found');
}

if (!user.profileImage) {
throw new BadRequestException('User does not have a profile image');
}

this.storage.delete(user.profileImage);

await this.userModel.findByIdAndUpdate(userId, {
profileImage: null,
});
}

async uploadCompanyLogo(
file: Express.Multer.File,
companyId: string
Expand Down Expand Up @@ -179,4 +197,22 @@ async uploadProfileImage(

return company.logo;
}

async deleteCompanyImage(companyId: string): Promise<void> {
const company = await this.companyModel.findById(companyId);

if (!company) {
throw new NotFoundException('Company not found');
}

if (!company.logo) {
throw new BadRequestException('Company does not have an image');
}

this.storage.delete(company.logo);

await this.companyModel.findByIdAndUpdate(companyId, {
image: null,
});
}
}
37 changes: 35 additions & 2 deletions backend/src/modules/file/presentation/file.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Controller, Post, UploadedFile, UseInterceptors, UseGuards, Body, Req, Param, Get, Res, BadRequestException } from '@nestjs/common';
import { ApiBearerAuth, ApiConsumes, ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
import { Controller, Post, UploadedFile, UseInterceptors, UseGuards, Body, Req, Param, Get, Res, BadRequestException, Delete } from '@nestjs/common';
import { ApiBearerAuth, ApiConsumes, ApiBody, ApiOperation, ApiTags, ApiResponse, ApiParam } from '@nestjs/swagger';
import { FileInterceptor } from '@nestjs/platform-express';
import { JwtGuard } from '../../auth/guards/jwt.guard';
import { RolesGuard } from '../../auth/guards/roles.guard';
Expand Down Expand Up @@ -163,6 +163,23 @@ export class FileController {
return this.fileService.uploadCompanyLogo(file, companyId);
}

@Delete('profile')
@UseGuards(JwtGuard, RolesGuard)
@Roles(UserRole.ADMIN, UserRole.SUPPORT, UserRole.CLIENT)
@ApiOperation({ summary: 'Remover foto de perfil do usuário' })
@ApiResponse({ status: 200, description: 'Imagem removida com sucesso' })
@ApiResponse({ status: 400, description: 'Usuário não possui imagem' })
@ApiResponse({ status: 404, description: 'Usuário não encontrado' })
async deleteProfileImage(
@Req() req: Request & { user: { id: string } },
) {
const userId = req.user.id;

await this.fileService.deleteUserProfileImage(userId);

return { message: 'Image removed successfully' };
}

@Get('company/:companyId')
async getCompanyLogo(
@Param('companyId') companyId: string,
Expand All @@ -179,4 +196,20 @@ export class FileController {

return res.sendFile(filePath, { root: './' });
}

@Delete('company/:companyId')
@UseGuards(JwtGuard, RolesGuard)
@Roles(UserRole.ADMIN)
@ApiOperation({ summary: 'Remover imagem da empresa' })
@ApiParam({ name: 'companyId' })
@ApiResponse({ status: 200, description: 'Imagem removida com sucesso' })
@ApiResponse({ status: 400, description: 'Empresa não possui imagem' })
@ApiResponse({ status: 404, description: 'Empresa não encontrada' })
async deleteCompanyImage(
@Param('companyId') companyId: string,
) {
await this.fileService.deleteCompanyImage(companyId);

return { message: 'Image removed successfully' };
}
}
Loading