Skip to content

Commit fa306ab

Browse files
Merge branch 'main' into custom-domain-notification
2 parents 9f0b679 + 6bed413 commit fa306ab

File tree

6 files changed

+67
-0
lines changed

6 files changed

+67
-0
lines changed

backend/src/common/data-injection.tokens.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export enum UseCaseType {
152152
TOGGLE_TEST_CONNECTIONS_DISPLAY_MODE_IN_COMPANY = 'TOGGLE_TEST_CONNECTIONS_DISPLAY_MODE_IN_COMPANY',
153153
UPLOAD_COMPANY_LOGO = 'UPLOAD_COMPANY_LOGO',
154154
FIND_COMPANY_LOGO = 'FIND_COMPANY_LOGO',
155+
DELETE_COMPANY_LOGO = 'DELETE_COMPANY_LOGO',
155156

156157
FIND_ACTION_RULES = 'FIND_ACTION_RULES',
157158
FIND_ACTION_RULE = 'FIND_ACTION_RULE',

backend/src/entities/company-info/company-info.controller.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { VerifyCompanyInvitationRequestDto } from './application/dto/verify-comp
5656
import {
5757
ICheckVerificationLinkAvailable,
5858
IDeleteCompany,
59+
IDeleteCompanyLogo,
5960
IFindCompanyLogo,
6061
IGetCompanyName,
6162
IGetUserCompany,
@@ -120,6 +121,8 @@ export class CompanyInfoController {
120121
private readonly uploadCompanyLogoUseCase: IUploadCompanyLogo,
121122
@Inject(UseCaseType.FIND_COMPANY_LOGO)
122123
private readonly findCompanyLogoUseCase: IFindCompanyLogo,
124+
@Inject(UseCaseType.DELETE_COMPANY_LOGO)
125+
private readonly deleteCompanyLogoUseCase: IDeleteCompanyLogo,
123126
) {}
124127

125128
@ApiOperation({ summary: 'Get user company' })
@@ -501,4 +504,17 @@ export class CompanyInfoController {
501504
async findCompanyLogo(@SlugUuid('companyId') companyId: string): Promise<FoundCompanyLogoRO> {
502505
return await this.findCompanyLogoUseCase.execute(companyId, InTransactionEnum.OFF);
503506
}
507+
508+
@ApiOperation({ summary: 'Delete company logo' })
509+
@ApiResponse({
510+
status: 200,
511+
description: 'Company logo deleted.',
512+
type: SuccessResponse,
513+
})
514+
@ApiQuery({ name: 'companyId', required: true })
515+
@UseGuards(CompanyAdminGuard)
516+
@Delete('/logo/:companyId')
517+
async deleteCompanyLogo(@SlugUuid('companyId') companyId: string): Promise<SuccessResponse> {
518+
return await this.deleteCompanyLogoUseCase.execute(companyId, InTransactionEnum.OFF);
519+
}
504520
}

backend/src/entities/company-info/company-info.module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { ToggleCompanyTestConnectionsDisplayModeUseCase } from './use-cases/togg
3434
import { CompanyLogoEntity } from '../company-logo/company-logo.entity.js';
3535
import { UploadCompanyLogoUseCase } from './use-cases/upload-company-logo-use-case.js';
3636
import { FindCompanyLogoUseCase } from './use-cases/find-company-logo.use.case.js';
37+
import { DeleteCompanyLogoUseCase } from './use-cases/delete-company-logo.use.case.js';
3738

3839
@Module({
3940
imports: [
@@ -132,6 +133,10 @@ import { FindCompanyLogoUseCase } from './use-cases/find-company-logo.use.case.j
132133
provide: UseCaseType.FIND_COMPANY_LOGO,
133134
useClass: FindCompanyLogoUseCase,
134135
},
136+
{
137+
provide: UseCaseType.DELETE_COMPANY_LOGO,
138+
useClass: DeleteCompanyLogoUseCase,
139+
},
135140
],
136141
controllers: [CompanyInfoController],
137142
})
@@ -155,6 +160,7 @@ export class CompanyInfoModule implements NestModule {
155160
{ path: '/company/connections/display/', method: RequestMethod.PUT },
156161
{ path: '/company/logo/:companyId', method: RequestMethod.POST },
157162
{ path: '/company/logo/:companyId', method: RequestMethod.GET },
163+
{ path: '/company/logo/:companyId', method: RequestMethod.DELETE },
158164
);
159165
}
160166
}

backend/src/entities/company-info/use-cases/company-info-use-cases.interface.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,7 @@ export interface IUploadCompanyLogo {
9292
export interface IFindCompanyLogo {
9393
execute(companyId: string, inTransaction: InTransactionEnum): Promise<FoundCompanyLogoRO>;
9494
}
95+
96+
export interface IDeleteCompanyLogo {
97+
execute(companyId: string, inTransaction: InTransactionEnum): Promise<SuccessResponse>;
98+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Inject, Injectable, NotFoundException } from '@nestjs/common';
2+
import AbstractUseCase from '../../../common/abstract-use.case.js';
3+
import { SuccessResponse } from '../../../microservices/saas-microservice/data-structures/common-responce.ds.js';
4+
import { IDeleteCompanyLogo } from './company-info-use-cases.interface.js';
5+
import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js';
6+
import { BaseType } from '../../../common/data-injection.tokens.js';
7+
import { Messages } from '../../../exceptions/text/messages.js';
8+
9+
@Injectable()
10+
export class DeleteCompanyLogoUseCase extends AbstractUseCase<string, SuccessResponse> implements IDeleteCompanyLogo {
11+
constructor(
12+
@Inject(BaseType.GLOBAL_DB_CONTEXT)
13+
protected _dbContext: IGlobalDatabaseContext,
14+
) {
15+
super();
16+
}
17+
18+
protected async implementation(companyId: string): Promise<SuccessResponse> {
19+
const company = await this._dbContext.companyInfoRepository.findCompanyWithLogo(companyId);
20+
if (!company) {
21+
throw new NotFoundException(Messages.COMPANY_NOT_FOUND);
22+
}
23+
24+
const logoForDeletion = await this._dbContext.companyLogoRepository.findOne({
25+
where: {
26+
company: {
27+
id: companyId,
28+
},
29+
},
30+
});
31+
32+
if (!logoForDeletion) {
33+
throw new NotFoundException(Messages.COMPANY_LOGO_NOT_FOUND);
34+
}
35+
36+
await this._dbContext.companyLogoRepository.remove(logoForDeletion);
37+
return { success: true };
38+
}
39+
}

backend/src/exceptions/text/messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const Messages = {
6868
COMPANY_ALREADY_EXISTS: 'Company already exists',
6969
COMPANY_NOT_EXISTS_IN_CONNECTION: `Connection does not attached to company. Please contact our support team`,
7070
COMPANY_NOT_FOUND: 'Company not found. Please contact our support team',
71+
COMPANY_LOGO_NOT_FOUND: 'Company logo not found',
7172
COMPANY_NAME_UPDATE_FAILED_UNHANDLED_ERROR: `Failed to update company name. Please contact our support team.`,
7273
COMPANY_ID_MISSING: `Company id is missing`,
7374
COMPANIES_USER_EMAIL_NOT_FOUND: (email: string) => `No companies found for user ${email}`,

0 commit comments

Comments
 (0)