This repository was archived by the owner on Jul 14, 2024. It is now read-only.
generated from GabrielGuedess/NestJs-Boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add maintenance company in graphql and application layer
- Loading branch information
1 parent
f7cfda4
commit 10469c9
Showing
25 changed files
with
700 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `maintenance_company_cnpj` on the `maintenance` table. All the data in the column will be lost. | ||
- You are about to drop the column `cnpj` on the `maintenance_companies` table. All the data in the column will be lost. | ||
- A unique constraint covering the columns `[legal_person_id]` on the table `maintenance_companies` will be added. If there are existing duplicate values, this will fail. | ||
- Added the required column `maintenance_company_id` to the `maintenance` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `legal_person_id` to the `maintenance_companies` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- DropForeignKey | ||
ALTER TABLE "maintenance" DROP CONSTRAINT "maintenance_maintenance_company_cnpj_fkey"; | ||
|
||
-- DropForeignKey | ||
ALTER TABLE "maintenance_companies" DROP CONSTRAINT "maintenance_companies_cnpj_fkey"; | ||
|
||
-- DropIndex | ||
DROP INDEX "maintenance_companies_cnpj_key"; | ||
|
||
-- AlterTable | ||
ALTER TABLE "maintenance" DROP COLUMN "maintenance_company_cnpj", | ||
ADD COLUMN "maintenance_company_id" TEXT NOT NULL; | ||
|
||
-- AlterTable | ||
ALTER TABLE "maintenance_companies" DROP COLUMN "cnpj", | ||
ADD COLUMN "legal_person_id" TEXT NOT NULL, | ||
ALTER COLUMN "specialty_maintenance" DROP NOT NULL; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "maintenance_companies_legal_person_id_key" ON "maintenance_companies"("legal_person_id"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "maintenance_companies" ADD CONSTRAINT "maintenance_companies_legal_person_id_fkey" FOREIGN KEY ("legal_person_id") REFERENCES "legal_people"("cnpj") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "maintenance" ADD CONSTRAINT "maintenance_maintenance_company_id_fkey" FOREIGN KEY ("maintenance_company_id") REFERENCES "maintenance_companies"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- DropForeignKey | ||
ALTER TABLE "maintenance_companies" DROP CONSTRAINT "maintenance_companies_legal_person_id_fkey"; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "maintenance_companies" ADD CONSTRAINT "maintenance_companies_legal_person_id_fkey" FOREIGN KEY ("legal_person_id") REFERENCES "legal_people"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/app/dtos/MaintenanceCompanyDto/CreateMaintenanceCompanyDto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { type CreateLegalPersonDTO } from '../LegalPerson/CreateLegalPersonDto'; | ||
|
||
export abstract class CreateMaintenanceCompanyDTO { | ||
legal_person_id?: string; | ||
|
||
specialty_maintenance: string; | ||
|
||
LegalPerson?: CreateLegalPersonDTO; | ||
|
||
updated_by: string; | ||
|
||
created_by?: string; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/app/dtos/MaintenanceCompanyDto/UpdateMaintenanceCompanyDto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { type UpdateLegalPersonDTO } from '../LegalPerson/UpdateLegalPersonDto'; | ||
|
||
export abstract class UpdateMaintenanceCompanyDTO { | ||
specialty_maintenance?: string; | ||
|
||
LegalPerson: UpdateLegalPersonDTO; | ||
|
||
updated_by?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/app/useCases/MaintenanceCompanyUseCases/MaintenanceCompanyUseCase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { HttpStatus, Injectable } from '@nestjs/common'; | ||
|
||
import { GraphQLError } from 'graphql'; | ||
|
||
import { type GetMaintenanceCompanyDTO } from 'domain/dto/repositories/getDataDtos/GetMaintenanceCompanyDto'; | ||
import { type FindAllMaintenanceCompanyWhereRequestDTO } from 'domain/dto/repositories/whereDtos/MaintenanceCompanyRepositoryDto'; | ||
import { MaintenanceCompany } from 'domain/entities/MaintenceEntities/MaintenanceCompany/MaintenanceCompany'; | ||
import { MaintenanceCompanyRepository } from 'domain/repositories/MaintenanceCompanyRepositoy'; | ||
|
||
import { LegalPersonEntityDto } from 'app/dtos/LegalPerson/LegalPersonEntityDto'; | ||
import { type CreateMaintenanceCompanyDTO } from 'app/dtos/MaintenanceCompanyDto/CreateMaintenanceCompanyDto'; | ||
import { type UpdateMaintenanceCompanyDTO } from 'app/dtos/MaintenanceCompanyDto/UpdateMaintenanceCompanyDto'; | ||
|
||
import { LegalPersonUseCases } from '../LegalPersonUseCases/LegalPersonUseCases'; | ||
|
||
@Injectable() | ||
export class MaintenanceCompanyUseCases { | ||
constructor( | ||
private maintenanceCompanyRepository: MaintenanceCompanyRepository, | ||
private legalPersonUseCase: LegalPersonUseCases, | ||
) {} | ||
async getMaintenanceCompany(request: GetMaintenanceCompanyDTO) { | ||
if ( | ||
!request.cnpj && | ||
!request.corporateName && | ||
!request.fantasyName && | ||
!request.id && | ||
!request.legalPersonId | ||
) | ||
throw new GraphQLError( | ||
'IS NECESSARY IN CNPJ, CORPORATENAME, FANTASYNAME, ID OR LEGALPERSONID', | ||
{ extensions: { code: HttpStatus.BAD_REQUEST } }, | ||
); | ||
const maintenancecompany = | ||
await this.maintenanceCompanyRepository.findMaintenanceCompany(request); | ||
if (maintenancecompany) return maintenancecompany; | ||
|
||
throw new GraphQLError('MaintenanceCompany Not Found', { | ||
extensions: { code: HttpStatus.NOT_FOUND }, | ||
}); | ||
} | ||
|
||
async getAllMaintenanceCompanys( | ||
request: FindAllMaintenanceCompanyWhereRequestDTO, | ||
) { | ||
const companies = | ||
await this.maintenanceCompanyRepository.getAllMaintenanceCompany(request); | ||
if (companies.length === 0) | ||
throw new GraphQLError('ANY MAINTENANCE COMPANY FOUND', { | ||
extensions: { code: HttpStatus.NOT_FOUND }, | ||
}); | ||
|
||
return companies; | ||
} | ||
|
||
async createMaintenanceCompany(data: CreateMaintenanceCompanyDTO) { | ||
if (data.LegalPerson) | ||
await this.legalPersonUseCase.validatePerson(data.LegalPerson); | ||
const maintenanceCompany = new MaintenanceCompany({ | ||
specialty_maintenance: data.specialty_maintenance, | ||
updated_by: data.updated_by, | ||
created_by: data.created_by, | ||
legal_person_id: data.legal_person_id, | ||
}); | ||
const legalPerson = LegalPersonEntityDto.createEntity(data.LegalPerson); | ||
|
||
return this.maintenanceCompanyRepository.createMaintenanceCompany( | ||
maintenanceCompany, | ||
legalPerson, | ||
data.legal_person_id, | ||
); | ||
} | ||
|
||
async updateMaintenanceCompany( | ||
id: string, | ||
data: UpdateMaintenanceCompanyDTO, | ||
) { | ||
const legalPerson = LegalPersonEntityDto.updateEntity(data.LegalPerson); | ||
const maintenanceCompany = new MaintenanceCompany({ | ||
specialty_maintenance: data.specialty_maintenance, | ||
updated_by: data.updated_by, | ||
created_by: null, | ||
legal_person_id: null, | ||
}); | ||
|
||
return this.maintenanceCompanyRepository.updateMaintenanceCompany( | ||
id, | ||
maintenanceCompany, | ||
legalPerson, | ||
); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/domain/dto/repositories/getDataDtos/GetMaintenanceCompanyDto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { GetLegalPersonDTO } from './GetLegalPersonDto'; | ||
|
||
export abstract class GetMaintenanceCompanyDTO extends GetLegalPersonDTO { | ||
id?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
src/domain/dto/repositories/whereDtos/MaintenceRepositoryDto.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.