Skip to content
This repository was archived by the owner on Jul 14, 2024. It is now read-only.

Commit

Permalink
feat: add many update and delete many in entities
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielGuedess committed May 1, 2024
1 parent d977f6b commit 99da6cb
Show file tree
Hide file tree
Showing 62 changed files with 2,116 additions and 64 deletions.
12 changes: 12 additions & 0 deletions src/app/dtos/OwnDriverDto/UpdateManyOwnDriversDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { type UpdateNaturalPersonDTO } from '../NaturalPersonDto/UpdateNaturalPersonDto';

export abstract class UpdateManyOwnDriversDto {
id: string;
cnh?: string;
cnh_category?: string;
cnh_expiration?: Date;
company_vehicle?: boolean;
course_mopp?: boolean;
NaturalPerson?: UpdateNaturalPersonDTO;
updated_by?: string;
}
12 changes: 12 additions & 0 deletions src/app/dtos/RecipientDto/UpdateManyRecipientsDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { type UpdateLegalPersonDTO } from '../LegalPerson/UpdateLegalPersonDto';
import { type UpdateNaturalPersonDTO } from '../NaturalPersonDto/UpdateNaturalPersonDto';

export abstract class UpdateManyRecipientsDto {
id: string;
NaturalPerson?: UpdateNaturalPersonDTO;
LegalPerson?: UpdateLegalPersonDTO;
updated_by?: string;
legal_person_id?: string;
natural_person_id?: string;
created_by?: string;
}
12 changes: 12 additions & 0 deletions src/app/dtos/SenderDto/UpdateManySendersDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { type UpdateLegalPersonDTO } from '../LegalPerson/UpdateLegalPersonDto';
import { type UpdateNaturalPersonDTO } from '../NaturalPersonDto/UpdateNaturalPersonDto';

export abstract class UpdateManySendersDto {
id: string;
NaturalPerson?: UpdateNaturalPersonDTO;
LegalPerson?: UpdateLegalPersonDTO;
updated_by?: string;
legal_person_id?: string;
natural_person_id?: string;
created_by?: string;
}
30 changes: 30 additions & 0 deletions src/app/useCases/LegalClientUseCases/LegalClientUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { HttpStatus, Injectable } from '@nestjs/common';
import { GraphQLError } from 'graphql';

import { type GetLegalClientDTO } from 'domain/dto/repositories/getDataDtos/GetLegalClientDto';
import {
type CountAllLegalClientsWhereRequestDTO,
type UpdateManyLegalClientsDTO,
} from 'domain/dto/repositories/whereDtos/LegalClientRepositoryDto';
import { LegalClient } from 'domain/entities/LegalClientEntities/LegalClient/LegalClient';
import { LegalClientRepository } from 'domain/repositories/LegalClientRepositoy';

Expand All @@ -19,6 +23,32 @@ export class LegalClientUseCases {
private legalClientRepository: LegalClientRepository,
private legalPersonUseCase: LegalPersonUseCases,
) {}
async count(
parameters: CountAllLegalClientsWhereRequestDTO,
): Promise<number> {
return await this.legalClientRepository.count(parameters);
}

async updateManyLegalClients(
LegalClients: UpdateManyLegalClientsDTO[],
): Promise<LegalClient[]> {
const updateLegalClients = await this.legalClientRepository.updateMany(
LegalClients,
);

return updateLegalClients;
}

async deleteLegalClient(id: string): Promise<LegalClient> {
return await this.legalClientRepository.delete(id);
}

async deleteManyLegalClients(ids: string[]): Promise<LegalClient[]> {
const deleteLegalClients = await this.legalClientRepository.deleteMany(ids);

return deleteLegalClients;
}

async getClient(request: GetLegalClientDTO) {
if (
!request.cnpj &&
Expand Down
31 changes: 27 additions & 4 deletions src/app/useCases/OwnDriverUseCases/OwnDriverUseCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { HttpStatus, Injectable } from '@nestjs/common';

import { GraphQLError } from 'graphql';

import { type CountAllOwnDriversWhereRequestDTO } from 'domain/dto/repositories/whereDtos/OwnDriverRepositoryDto';
import { OwnDriver } from 'domain/entities/CompanyEntities/ownDriver/OwnDriver';
import { OwnDriverRepository } from 'domain/repositories/OwnDriverRepository';

import { NaturalPersonEntityDto } from 'app/dtos/NaturalPersonDto/NaturalPersonEntityDto';
import { type CreateOwnDriverDTO } from 'app/dtos/OwnDriverDto/CreateOwnDriverDto';
import { type GetAllOwnDriverDTO } from 'app/dtos/OwnDriverDto/GetAllOwnDriverDto';
import { type GetOwnDriverDTO } from 'app/dtos/OwnDriverDto/GetOwnDriverDto';
import { type UpdateManyOwnDriversDto } from 'app/dtos/OwnDriverDto/UpdateManyOwnDriversDto';
import { type UpdateOwnDriverDTO } from 'app/dtos/OwnDriverDto/UpdateOwnDriverDto';

import { NaturalPersonUseCases } from '../NaturalPersoUseCases/NaturalPersonUseCases';
Expand All @@ -19,6 +21,31 @@ export class OwnDriverUseCases {
private ownDriverRepository: OwnDriverRepository,
private naturalPersonUseCase: NaturalPersonUseCases,
) {}

async count(parameters: CountAllOwnDriversWhereRequestDTO): Promise<number> {
return await this.ownDriverRepository.count(parameters);
}

async updateManyOwnDrivers(
ownDrivers: UpdateManyOwnDriversDto[],
): Promise<OwnDriver[]> {
const updateOwnDrivers = await this.ownDriverRepository.updateMany(
ownDrivers,
);

return updateOwnDrivers;
}

async deleteOwnDriver(id: string): Promise<OwnDriver> {
return await this.ownDriverRepository.delete(id);
}

async deleteManyOwnDrivers(ids: string[]): Promise<OwnDriver[]> {
const deleteOwnDrivers = await this.ownDriverRepository.deleteMany(ids);

return deleteOwnDrivers;
}

async getOwnDriver(request: GetOwnDriverDTO) {
if (
!request.cnh &&
Expand All @@ -41,10 +68,6 @@ export class OwnDriverUseCases {
const ownDrivers = await this.ownDriverRepository.findAllOwnDrivers(
request,
);
if (ownDrivers.length === 0)
throw new GraphQLError('ANY OWN DRIVER FOUND', {
extensions: { code: HttpStatus.NOT_FOUND },
});

return ownDrivers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { HttpStatus, Injectable } from '@nestjs/common';
import { GraphQLError } from 'graphql';

import { type GetPhysicalCustomerDTO } from 'domain/dto/repositories/getDataDtos/GetPhysicalCustomerDto';
import {
type CountAllPhysicalCustomersWhereRequestDTO,
type UpdateManyPhysicalCustomersDTO,
} from 'domain/dto/repositories/whereDtos/PhysicalCustomerRepositoryDto';
import { PhysicalCustomer } from 'domain/entities/PhysicalClientEntities/physicalCustomer/PhysicalCustomer';
import { PhysicalCustomerRepository } from 'domain/repositories/PhysicalCustomerRepository';

Expand All @@ -19,6 +23,34 @@ export class PhysicalCustomerUseCases {
private physicalCustomerRepository: PhysicalCustomerRepository,
private naturalPersonUseCase: NaturalPersonUseCases,
) {}
async count(
parameters: CountAllPhysicalCustomersWhereRequestDTO,
): Promise<number> {
return await this.physicalCustomerRepository.count(parameters);
}

async updateManyPhysicalCustomers(
PhysicalCustomers: UpdateManyPhysicalCustomersDTO[],
): Promise<PhysicalCustomer[]> {
const updatePhysicalCustomers =
await this.physicalCustomerRepository.updateMany(PhysicalCustomers);

return updatePhysicalCustomers;
}

async deletePhysicalCustomer(id: string): Promise<PhysicalCustomer> {
return await this.physicalCustomerRepository.delete(id);
}

async deleteManyPhysicalCustomers(
ids: string[],
): Promise<PhysicalCustomer[]> {
const deletePhysicalCustomers =
await this.physicalCustomerRepository.deleteMany(ids);

return deletePhysicalCustomers;
}

async getPhysicalCustomer(request: GetPhysicalCustomerDTO) {
if (!request.cpf && !request.id && !request.naturalPersonId && !request.rg)
throw new GraphQLError(
Expand Down
30 changes: 29 additions & 1 deletion src/app/useCases/RecipientUseCase /RecipientUseCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { HttpStatus, Injectable } from '@nestjs/common';
import { GraphQLError } from 'graphql';

import { type GetRecipientDTO } from 'domain/dto/repositories/getDataDtos/GetRecipientDto';
import { type FindAllRecipientWhereRequestDTO } from 'domain/dto/repositories/whereDtos/RecipientRepositoryDto';
import {
type CountAllRecipientsWhereRequestDTO,
type FindAllRecipientWhereRequestDTO,
} from 'domain/dto/repositories/whereDtos/RecipientRepositoryDto';
import { type LegalPerson } from 'domain/entities/LegalPerson/LegalPerson';
import { type NaturalPerson } from 'domain/entities/NaturalPerson/NaturalPerson';
import { Recipient } from 'domain/entities/Recipient/Recipient';
Expand All @@ -12,6 +15,7 @@ import { RecipientRepository } from 'domain/repositories/RecipientRepository ';
import { LegalPersonEntityDto } from 'app/dtos/LegalPerson/LegalPersonEntityDto';
import { NaturalPersonEntityDto } from 'app/dtos/NaturalPersonDto/NaturalPersonEntityDto';
import { type CreateRecipientDTO } from 'app/dtos/RecipientDto/CreateRecipientDto';
import { type UpdateManyRecipientsDto } from 'app/dtos/RecipientDto/UpdateManyRecipientsDto';
import { type UpdateRecipientDTO } from 'app/dtos/RecipientDto/UpdateRecipientDto';

import { LegalPersonUseCases } from '../LegalPersonUseCases/LegalPersonUseCases';
Expand All @@ -24,6 +28,14 @@ export class RecipientUseCases {
private legalPersonUseCase: LegalPersonUseCases,
private naturalPersonUseCase: NaturalPersonUseCases,
) {}
async count(parameters: CountAllRecipientsWhereRequestDTO): Promise<number> {
return await this.recipientRepository.count(parameters);
}

async deleteRecipient(id: string): Promise<Recipient> {
return await this.recipientRepository.delete(id);
}

async getRecipient(request: GetRecipientDTO) {
if (!request.legalPerson && !request.id && !request.naturalPerson) {
throw new GraphQLError(
Expand Down Expand Up @@ -187,4 +199,20 @@ export class RecipientUseCases {
);
}
}

async updateManyRecipients(
Recipient: UpdateManyRecipientsDto[],
): Promise<Recipient[]> {
const updateRecipients = await this.recipientRepository.updateMany(
Recipient,
);

return updateRecipients;
}

async deleteManyRecipients(ids: string[]): Promise<Recipient[]> {
const deleteRecipients = await this.recipientRepository.deleteMany(ids);

return deleteRecipients;
}
}
26 changes: 25 additions & 1 deletion src/app/useCases/SenderUseCase /SenderUseCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { HttpStatus, Injectable } from '@nestjs/common';
import { GraphQLError } from 'graphql';

import { type GetSenderDTO } from 'domain/dto/repositories/getDataDtos/GetSendertDto';
import { type FindAllSenderWhereRequestDTO } from 'domain/dto/repositories/whereDtos/SenderRepositoryDto';
import {
type CountAllSendersWhereRequestDTO,
type FindAllSenderWhereRequestDTO,
} from 'domain/dto/repositories/whereDtos/SenderRepositoryDto';
import { type LegalPerson } from 'domain/entities/LegalPerson/LegalPerson';
import { type NaturalPerson } from 'domain/entities/NaturalPerson/NaturalPerson';
import { Sender } from 'domain/entities/Sender/Sender';
Expand All @@ -12,6 +15,7 @@ import { SenderRepository } from 'domain/repositories/SenderRepository';
import { LegalPersonEntityDto } from 'app/dtos/LegalPerson/LegalPersonEntityDto';
import { NaturalPersonEntityDto } from 'app/dtos/NaturalPersonDto/NaturalPersonEntityDto';
import { type CreateSenderDTO } from 'app/dtos/SenderDto/CreateSenderDto';
import { type UpdateManySendersDto } from 'app/dtos/SenderDto/UpdateManySendersDto';
import { type UpdateSenderDTO } from 'app/dtos/SenderDto/UpdateSenderDto';

import { LegalPersonUseCases } from '../LegalPersonUseCases/LegalPersonUseCases';
Expand All @@ -24,6 +28,26 @@ export class SenderUseCases {
private legalPersonUseCase: LegalPersonUseCases,
private naturalPersonUseCase: NaturalPersonUseCases,
) {}
async count(parameters: CountAllSendersWhereRequestDTO): Promise<number> {
return await this.senderRepository.count(parameters);
}

async updateManySenders(senders: UpdateManySendersDto[]): Promise<Sender[]> {
const updateSenders = await this.senderRepository.updateMany(senders);

return updateSenders;
}

async deleteSender(id: string): Promise<Sender> {
return await this.senderRepository.delete(id);
}

async deleteManySenders(ids: string[]): Promise<Sender[]> {
const deleteSenders = await this.senderRepository.deleteMany(ids);

return deleteSenders;
}

async getSender(request: GetSenderDTO) {
if (!request.legalPerson && !request.id && !request.naturalPerson) {
throw new GraphQLError(
Expand Down
39 changes: 34 additions & 5 deletions src/app/useCases/VehicleBrandCases/VehicleBrandUseCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { HttpStatus, Injectable } from '@nestjs/common';
import { GraphQLError } from 'graphql';

import { type GetVehicleBrandDTO } from 'domain/dto/repositories/getDataDtos/GetVehicleBrandDto';
import { type FindAllVehicleBrandWhereRequestDTO } from 'domain/dto/repositories/whereDtos/VehicleBrandRepositoryDto';
import {
type CountAllVehicleBrandsWhereRequestDTO,
type UpdateManyVehicleBrandsDTO,
type FindAllVehicleBrandWhereRequestDTO,
} from 'domain/dto/repositories/whereDtos/VehicleBrandRepositoryDto';
import { VehicleBrand } from 'domain/entities/VehicleEntities/vehicleBrand/VehicleBrand';
import { VehicleBrandRepository } from 'domain/repositories/VehicleBrandRepository';

Expand All @@ -13,6 +17,34 @@ import { type UpdateVehicleBrandDTO } from 'app/dtos/VehicleBrandDto/UpdateVehic
@Injectable()
export class VehicleBrandUseCases {
constructor(private vehicleBrandRepository: VehicleBrandRepository) {}
async count(
parameters: CountAllVehicleBrandsWhereRequestDTO,
): Promise<number> {
return await this.vehicleBrandRepository.count(parameters);
}

async updateManyVehicleBrands(
VehicleBrands: UpdateManyVehicleBrandsDTO[],
): Promise<VehicleBrand[]> {
const updateVehicleBrands = await this.vehicleBrandRepository.updateMany(
VehicleBrands,
);

return updateVehicleBrands;
}

async deleteVehicleBrand(id: string): Promise<VehicleBrand> {
return await this.vehicleBrandRepository.delete(id);
}

async deleteManyVehicleBrands(ids: string[]): Promise<VehicleBrand[]> {
const deleteVehicleBrands = await this.vehicleBrandRepository.deleteMany(
ids,
);

return deleteVehicleBrands;
}

async getVehicleBrand(request: GetVehicleBrandDTO) {
if (!request.id && !request.name) {
throw new GraphQLError('IS NECESSARY AN ID OR BRAND NAME', {
Expand All @@ -32,11 +64,8 @@ export class VehicleBrandUseCases {
const brands = await this.vehicleBrandRepository.getAllVehicleBrand(
request,
);
if (brands.length > 0) return brands;

throw new GraphQLError('NO BRAND FOUND', {
extensions: { code: HttpStatus.NOT_FOUND },
});
return brands;
}
async createBrand(data: CreateVehicleBrandDTO) {
console.error('test', data);
Expand Down
34 changes: 33 additions & 1 deletion src/app/useCases/VehicleModelUseCases/VehihicleModelUseCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { HttpStatus, Injectable } from '@nestjs/common';
import { GraphQLError } from 'graphql';

import { type GetVehicleModelDTO } from 'domain/dto/repositories/getDataDtos/GetVehicleModelDto';
import { type FindAllVehicleModelWhereRequestDTO } from 'domain/dto/repositories/whereDtos/VehicleModelRepositoryDto';
import {
type CountAllVehicleModelsWhereRequestDTO,
type UpdateManyVehicleModelsDTO,
type FindAllVehicleModelWhereRequestDTO,
} from 'domain/dto/repositories/whereDtos/VehicleModelRepositoryDto';
import { VehicleModel } from 'domain/entities/VehicleEntities/vehicleModel/VehicleModel';
import { VehicleModelRepository } from 'domain/repositories/VehicleModelRepository';

Expand All @@ -20,6 +24,34 @@ export class VehicleModelUseCases {
private vehicleBrandUseCase: VehicleBrandUseCases,
private vehicleTypeUseCase: VehicleTypeUseCases,
) {}
async count(
parameters: CountAllVehicleModelsWhereRequestDTO,
): Promise<number> {
return await this.vehicleModelRepository.count(parameters);
}

async updateManyVehicleModels(
VehicleModels: UpdateManyVehicleModelsDTO[],
): Promise<VehicleModel[]> {
const updateVehicleModels = await this.vehicleModelRepository.updateMany(
VehicleModels,
);

return updateVehicleModels;
}

async deleteVehicleModel(id: string): Promise<VehicleModel> {
return await this.vehicleModelRepository.delete(id);
}

async deleteManyVehicleModels(ids: string[]): Promise<VehicleModel[]> {
const deleteVehicleModels = await this.vehicleModelRepository.deleteMany(
ids,
);

return deleteVehicleModels;
}

async getModel(request: GetVehicleModelDTO) {
if (!request.id && !request.name)
throw new GraphQLError('IS NECESSARY AN ID OR MODEL NAME', {
Expand Down
Loading

0 comments on commit 99da6cb

Please sign in to comment.