diff --git a/src/app/dtos/OwnDriverDto/UpdateManyOwnDriversDto.ts b/src/app/dtos/OwnDriverDto/UpdateManyOwnDriversDto.ts new file mode 100644 index 00000000..3f3d9264 --- /dev/null +++ b/src/app/dtos/OwnDriverDto/UpdateManyOwnDriversDto.ts @@ -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; +} diff --git a/src/app/dtos/RecipientDto/UpdateManyRecipientsDto.ts b/src/app/dtos/RecipientDto/UpdateManyRecipientsDto.ts new file mode 100644 index 00000000..bb37464f --- /dev/null +++ b/src/app/dtos/RecipientDto/UpdateManyRecipientsDto.ts @@ -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; +} diff --git a/src/app/dtos/SenderDto/UpdateManySendersDto.ts b/src/app/dtos/SenderDto/UpdateManySendersDto.ts new file mode 100644 index 00000000..cfaadaab --- /dev/null +++ b/src/app/dtos/SenderDto/UpdateManySendersDto.ts @@ -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; +} diff --git a/src/app/useCases/LegalClientUseCases/LegalClientUseCase.ts b/src/app/useCases/LegalClientUseCases/LegalClientUseCase.ts index eb36d4f3..af1c3a89 100644 --- a/src/app/useCases/LegalClientUseCases/LegalClientUseCase.ts +++ b/src/app/useCases/LegalClientUseCases/LegalClientUseCase.ts @@ -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'; @@ -19,6 +23,32 @@ export class LegalClientUseCases { private legalClientRepository: LegalClientRepository, private legalPersonUseCase: LegalPersonUseCases, ) {} + async count( + parameters: CountAllLegalClientsWhereRequestDTO, + ): Promise { + return await this.legalClientRepository.count(parameters); + } + + async updateManyLegalClients( + LegalClients: UpdateManyLegalClientsDTO[], + ): Promise { + const updateLegalClients = await this.legalClientRepository.updateMany( + LegalClients, + ); + + return updateLegalClients; + } + + async deleteLegalClient(id: string): Promise { + return await this.legalClientRepository.delete(id); + } + + async deleteManyLegalClients(ids: string[]): Promise { + const deleteLegalClients = await this.legalClientRepository.deleteMany(ids); + + return deleteLegalClients; + } + async getClient(request: GetLegalClientDTO) { if ( !request.cnpj && diff --git a/src/app/useCases/OwnDriverUseCases/OwnDriverUseCases.ts b/src/app/useCases/OwnDriverUseCases/OwnDriverUseCases.ts index 77978f96..a04b7982 100644 --- a/src/app/useCases/OwnDriverUseCases/OwnDriverUseCases.ts +++ b/src/app/useCases/OwnDriverUseCases/OwnDriverUseCases.ts @@ -2,6 +2,7 @@ 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'; @@ -9,6 +10,7 @@ import { NaturalPersonEntityDto } from 'app/dtos/NaturalPersonDto/NaturalPersonE 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'; @@ -19,6 +21,31 @@ export class OwnDriverUseCases { private ownDriverRepository: OwnDriverRepository, private naturalPersonUseCase: NaturalPersonUseCases, ) {} + + async count(parameters: CountAllOwnDriversWhereRequestDTO): Promise { + return await this.ownDriverRepository.count(parameters); + } + + async updateManyOwnDrivers( + ownDrivers: UpdateManyOwnDriversDto[], + ): Promise { + const updateOwnDrivers = await this.ownDriverRepository.updateMany( + ownDrivers, + ); + + return updateOwnDrivers; + } + + async deleteOwnDriver(id: string): Promise { + return await this.ownDriverRepository.delete(id); + } + + async deleteManyOwnDrivers(ids: string[]): Promise { + const deleteOwnDrivers = await this.ownDriverRepository.deleteMany(ids); + + return deleteOwnDrivers; + } + async getOwnDriver(request: GetOwnDriverDTO) { if ( !request.cnh && @@ -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; } diff --git a/src/app/useCases/PhysicalCustomerUseCases/PhysicalCustomerUseCases.ts b/src/app/useCases/PhysicalCustomerUseCases/PhysicalCustomerUseCases.ts index 4f5a452e..f9f23bd2 100644 --- a/src/app/useCases/PhysicalCustomerUseCases/PhysicalCustomerUseCases.ts +++ b/src/app/useCases/PhysicalCustomerUseCases/PhysicalCustomerUseCases.ts @@ -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'; @@ -19,6 +23,34 @@ export class PhysicalCustomerUseCases { private physicalCustomerRepository: PhysicalCustomerRepository, private naturalPersonUseCase: NaturalPersonUseCases, ) {} + async count( + parameters: CountAllPhysicalCustomersWhereRequestDTO, + ): Promise { + return await this.physicalCustomerRepository.count(parameters); + } + + async updateManyPhysicalCustomers( + PhysicalCustomers: UpdateManyPhysicalCustomersDTO[], + ): Promise { + const updatePhysicalCustomers = + await this.physicalCustomerRepository.updateMany(PhysicalCustomers); + + return updatePhysicalCustomers; + } + + async deletePhysicalCustomer(id: string): Promise { + return await this.physicalCustomerRepository.delete(id); + } + + async deleteManyPhysicalCustomers( + ids: string[], + ): Promise { + 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( diff --git a/src/app/useCases/RecipientUseCase /RecipientUseCases.ts b/src/app/useCases/RecipientUseCase /RecipientUseCases.ts index fb5b5b69..a4314487 100644 --- a/src/app/useCases/RecipientUseCase /RecipientUseCases.ts +++ b/src/app/useCases/RecipientUseCase /RecipientUseCases.ts @@ -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'; @@ -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'; @@ -24,6 +28,14 @@ export class RecipientUseCases { private legalPersonUseCase: LegalPersonUseCases, private naturalPersonUseCase: NaturalPersonUseCases, ) {} + async count(parameters: CountAllRecipientsWhereRequestDTO): Promise { + return await this.recipientRepository.count(parameters); + } + + async deleteRecipient(id: string): Promise { + return await this.recipientRepository.delete(id); + } + async getRecipient(request: GetRecipientDTO) { if (!request.legalPerson && !request.id && !request.naturalPerson) { throw new GraphQLError( @@ -187,4 +199,20 @@ export class RecipientUseCases { ); } } + + async updateManyRecipients( + Recipient: UpdateManyRecipientsDto[], + ): Promise { + const updateRecipients = await this.recipientRepository.updateMany( + Recipient, + ); + + return updateRecipients; + } + + async deleteManyRecipients(ids: string[]): Promise { + const deleteRecipients = await this.recipientRepository.deleteMany(ids); + + return deleteRecipients; + } } diff --git a/src/app/useCases/SenderUseCase /SenderUseCases.ts b/src/app/useCases/SenderUseCase /SenderUseCases.ts index 49b91d47..6e14e366 100644 --- a/src/app/useCases/SenderUseCase /SenderUseCases.ts +++ b/src/app/useCases/SenderUseCase /SenderUseCases.ts @@ -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'; @@ -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'; @@ -24,6 +28,26 @@ export class SenderUseCases { private legalPersonUseCase: LegalPersonUseCases, private naturalPersonUseCase: NaturalPersonUseCases, ) {} + async count(parameters: CountAllSendersWhereRequestDTO): Promise { + return await this.senderRepository.count(parameters); + } + + async updateManySenders(senders: UpdateManySendersDto[]): Promise { + const updateSenders = await this.senderRepository.updateMany(senders); + + return updateSenders; + } + + async deleteSender(id: string): Promise { + return await this.senderRepository.delete(id); + } + + async deleteManySenders(ids: string[]): Promise { + const deleteSenders = await this.senderRepository.deleteMany(ids); + + return deleteSenders; + } + async getSender(request: GetSenderDTO) { if (!request.legalPerson && !request.id && !request.naturalPerson) { throw new GraphQLError( diff --git a/src/app/useCases/VehicleBrandCases/VehicleBrandUseCases.ts b/src/app/useCases/VehicleBrandCases/VehicleBrandUseCases.ts index fe0ffe6d..92d1608e 100644 --- a/src/app/useCases/VehicleBrandCases/VehicleBrandUseCases.ts +++ b/src/app/useCases/VehicleBrandCases/VehicleBrandUseCases.ts @@ -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'; @@ -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 { + return await this.vehicleBrandRepository.count(parameters); + } + + async updateManyVehicleBrands( + VehicleBrands: UpdateManyVehicleBrandsDTO[], + ): Promise { + const updateVehicleBrands = await this.vehicleBrandRepository.updateMany( + VehicleBrands, + ); + + return updateVehicleBrands; + } + + async deleteVehicleBrand(id: string): Promise { + return await this.vehicleBrandRepository.delete(id); + } + + async deleteManyVehicleBrands(ids: string[]): Promise { + 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', { @@ -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); diff --git a/src/app/useCases/VehicleModelUseCases/VehihicleModelUseCases.ts b/src/app/useCases/VehicleModelUseCases/VehihicleModelUseCases.ts index 425e45c7..b92ee583 100644 --- a/src/app/useCases/VehicleModelUseCases/VehihicleModelUseCases.ts +++ b/src/app/useCases/VehicleModelUseCases/VehihicleModelUseCases.ts @@ -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'; @@ -20,6 +24,34 @@ export class VehicleModelUseCases { private vehicleBrandUseCase: VehicleBrandUseCases, private vehicleTypeUseCase: VehicleTypeUseCases, ) {} + async count( + parameters: CountAllVehicleModelsWhereRequestDTO, + ): Promise { + return await this.vehicleModelRepository.count(parameters); + } + + async updateManyVehicleModels( + VehicleModels: UpdateManyVehicleModelsDTO[], + ): Promise { + const updateVehicleModels = await this.vehicleModelRepository.updateMany( + VehicleModels, + ); + + return updateVehicleModels; + } + + async deleteVehicleModel(id: string): Promise { + return await this.vehicleModelRepository.delete(id); + } + + async deleteManyVehicleModels(ids: string[]): Promise { + 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', { diff --git a/src/app/useCases/VehicleTypeUseCases/VehicleTypeUseCases.ts b/src/app/useCases/VehicleTypeUseCases/VehicleTypeUseCases.ts index ec64c005..7285e7d6 100644 --- a/src/app/useCases/VehicleTypeUseCases/VehicleTypeUseCases.ts +++ b/src/app/useCases/VehicleTypeUseCases/VehicleTypeUseCases.ts @@ -3,7 +3,11 @@ import { HttpStatus, Injectable } from '@nestjs/common'; import { GraphQLError } from 'graphql'; import { type GetVehicleTypeDTO } from 'domain/dto/repositories/getDataDtos/GetVehicleTypeDto'; -import { type FindAllVehicleTypeWhereRequestDTO } from 'domain/dto/repositories/whereDtos/VehicleTypeRepositoryDto'; +import { + type CountAllVehicleTypesWhereRequestDTO, + type UpdateManyVehicleTypesDTO, + type FindAllVehicleTypeWhereRequestDTO, +} from 'domain/dto/repositories/whereDtos/VehicleTypeRepositoryDto'; import { VehicleType } from 'domain/entities/VehicleEntities/vehicleTypes/VehicleTypes'; import { VehicleTypeRepository } from 'domain/repositories/VehicleTypeRepository'; @@ -18,6 +22,32 @@ export class VehicleTypeUseCases { private vehicleTypeRepository: VehicleTypeRepository, private vehicleBodyWorkUseCase: VehicleBodyworkUseCases, ) {} + async count( + parameters: CountAllVehicleTypesWhereRequestDTO, + ): Promise { + return await this.vehicleTypeRepository.count(parameters); + } + + async updateManyVehicleTypes( + VehicleTypes: UpdateManyVehicleTypesDTO[], + ): Promise { + const updateVehicleTypes = await this.vehicleTypeRepository.updateMany( + VehicleTypes, + ); + + return updateVehicleTypes; + } + + async deleteVehicleType(id: string): Promise { + return await this.vehicleTypeRepository.delete(id); + } + + async deleteManyVehicleTypes(ids: string[]): Promise { + const deleteVehicleTypes = await this.vehicleTypeRepository.deleteMany(ids); + + return deleteVehicleTypes; + } + async getVehicleType(request: GetVehicleTypeDTO) { if (!request.id && !request.name) throw new GraphQLError('IS NECESSARY AN ID OR NAME', { diff --git a/src/domain/dto/repositories/whereDtos/LegalClientRepositoryDto.ts b/src/domain/dto/repositories/whereDtos/LegalClientRepositoryDto.ts index cf16ceb0..f8cf515d 100644 --- a/src/domain/dto/repositories/whereDtos/LegalClientRepositoryDto.ts +++ b/src/domain/dto/repositories/whereDtos/LegalClientRepositoryDto.ts @@ -35,3 +35,17 @@ export abstract class getLegalClientData { fantasyName?: string; corporateName?: string; } + +export abstract class CountAllLegalClientsWhereRequestDTO { + where?: WhereLegalClientTypeDTO; +} + +export abstract class UpdateManyLegalClientsDTO { + id: string; + branch?: string; + legal_person_id?: string; + updated_at?: Date; + created_at?: Date; + updated_by?: string; + created_by?: string; +} diff --git a/src/domain/dto/repositories/whereDtos/OwnDriverRepositoryDto.ts b/src/domain/dto/repositories/whereDtos/OwnDriverRepositoryDto.ts index 1d268287..388c049c 100644 --- a/src/domain/dto/repositories/whereDtos/OwnDriverRepositoryDto.ts +++ b/src/domain/dto/repositories/whereDtos/OwnDriverRepositoryDto.ts @@ -34,3 +34,20 @@ export class FindAllOwnDriverWhereRequestDTO { sort?: SortByOwnDriverTypeDTO; where?: WhereOwnDriverTypeDTO; } + +export abstract class CountAllOwnDriversWhereRequestDTO { + where?: WhereOwnDriverTypeDTO; +} + +export abstract class UpdateManyOwnDriversDTO { + id: string; + natural_person_id?: string; + cnh?: string; + cnh_category?: string; + company_vehicle?: boolean; + course_mopp?: boolean; + created_at?: Date; + updated_at?: Date; + updated_by?: string; + created_by?: string; +} diff --git a/src/domain/dto/repositories/whereDtos/PhysicalCustomerRepositoryDto.ts b/src/domain/dto/repositories/whereDtos/PhysicalCustomerRepositoryDto.ts index d341ebf1..f1ef6662 100644 --- a/src/domain/dto/repositories/whereDtos/PhysicalCustomerRepositoryDto.ts +++ b/src/domain/dto/repositories/whereDtos/PhysicalCustomerRepositoryDto.ts @@ -28,3 +28,17 @@ export class FindAllPhysicalCustomerWhereRequestDTO { sort?: SortByPhysicalCustomerTypeDTO; where?: WherePhysicalCustomerTypeDTO; } + +export abstract class CountAllPhysicalCustomersWhereRequestDTO { + where?: WherePhysicalCustomerTypeDTO; +} + +export abstract class UpdateManyPhysicalCustomersDTO { + id: string; + branch?: string; + natural_person_id?: string; + updated_at?: Date; + created_at?: Date; + created_by?: string; + updated_by?: string; +} diff --git a/src/domain/dto/repositories/whereDtos/RecipientRepositoryDto.ts b/src/domain/dto/repositories/whereDtos/RecipientRepositoryDto.ts index ade2dc78..9e195821 100644 --- a/src/domain/dto/repositories/whereDtos/RecipientRepositoryDto.ts +++ b/src/domain/dto/repositories/whereDtos/RecipientRepositoryDto.ts @@ -22,6 +22,10 @@ export abstract class SortByRecipientTypeDTO { updated_by?: 'asc' | 'desc'; } +export abstract class CountAllRecipientsWhereRequestDTO { + where?: WhereRecipientTypeDTO; +} + export class FindAllRecipientWhereRequestDTO { limit: number; offset: number; diff --git a/src/domain/dto/repositories/whereDtos/SenderRepositoryDto.ts b/src/domain/dto/repositories/whereDtos/SenderRepositoryDto.ts index 052888f7..be88f0b8 100644 --- a/src/domain/dto/repositories/whereDtos/SenderRepositoryDto.ts +++ b/src/domain/dto/repositories/whereDtos/SenderRepositoryDto.ts @@ -28,3 +28,17 @@ export class FindAllSenderWhereRequestDTO { sort?: SortBySenderTypeDTO; where?: WhereSenderTypeDTO; } + +export abstract class CountAllSendersWhereRequestDTO { + where?: WhereSenderTypeDTO; +} + +export abstract class UpdateManySendersDTO { + id: string; + legal_person_id?: string; + natural_person_id?: string; + created_at?: Date; + updated_at?: Date; + created_by?: string; + updated_by?: string; +} diff --git a/src/domain/dto/repositories/whereDtos/VehicleBrandRepositoryDto.ts b/src/domain/dto/repositories/whereDtos/VehicleBrandRepositoryDto.ts index 1fdda75e..d391ad4e 100644 --- a/src/domain/dto/repositories/whereDtos/VehicleBrandRepositoryDto.ts +++ b/src/domain/dto/repositories/whereDtos/VehicleBrandRepositoryDto.ts @@ -26,3 +26,16 @@ export class FindAllVehicleBrandWhereRequestDTO { sort?: SortByVehicleBrandTypeDTO; where?: WhereVehicleBrandTypeDTO; } + +export abstract class CountAllVehicleBrandsWhereRequestDTO { + where?: WhereVehicleBrandTypeDTO; +} + +export abstract class UpdateManyVehicleBrandsDTO { + id: string; + name?: string; + created_at?: Date; + updated_at?: Date; + updated_by?: string; + created_by?: string; +} diff --git a/src/domain/dto/repositories/whereDtos/VehicleModelRepositoryDto.ts b/src/domain/dto/repositories/whereDtos/VehicleModelRepositoryDto.ts index b1b03b19..f74b095a 100644 --- a/src/domain/dto/repositories/whereDtos/VehicleModelRepositoryDto.ts +++ b/src/domain/dto/repositories/whereDtos/VehicleModelRepositoryDto.ts @@ -39,3 +39,22 @@ export class FindAllVehicleModelWhereRequestDTO { sort?: SortByVehicleModelTypeDTO; where?: WhereVehicleModelTypeDTO; } + +export abstract class CountAllVehicleModelsWhereRequestDTO { + where?: WhereVehicleModelTypeDTO; +} + +export abstract class UpdateManyVehicleModelsDTO { + id: string; + name?: string; + weight?: number; + capacity_max?: number; + axles?: number; + capacity_per_axle?: number; + brand_id?: string; + type_id?: string; + created_at?: Date; + created_by?: string; + updated_at?: Date; + updated_by?: string; +} diff --git a/src/domain/dto/repositories/whereDtos/VehicleTypeRepositoryDto.ts b/src/domain/dto/repositories/whereDtos/VehicleTypeRepositoryDto.ts index 81c49c14..e62ab120 100644 --- a/src/domain/dto/repositories/whereDtos/VehicleTypeRepositoryDto.ts +++ b/src/domain/dto/repositories/whereDtos/VehicleTypeRepositoryDto.ts @@ -33,3 +33,18 @@ export class FindAllVehicleTypeWhereRequestDTO { sort?: SortByVehicleTypeDTO; where?: WhereVehicleTypeDTO; } + +export abstract class CountAllVehicleTypesWhereRequestDTO { + where?: WhereVehicleTypeDTO; +} + +export abstract class UpdateManyVehicleTypesDTO { + id: string; + name?: string; + bodyWork?: boolean; + body_work_id?: string[]; + created_at?: Date; + updated_at?: Date; + created_by?: string; + updated_by?: string; +} diff --git a/src/domain/repositories/LegalClientRepositoy.ts b/src/domain/repositories/LegalClientRepositoy.ts index 299147b6..38cfa3ad 100644 --- a/src/domain/repositories/LegalClientRepositoy.ts +++ b/src/domain/repositories/LegalClientRepositoy.ts @@ -1,4 +1,6 @@ import { + type UpdateManyLegalClientsDTO, + type CountAllLegalClientsWhereRequestDTO, type getLegalClientData, type FindAllLegalClientWhereRequestDTO, } from 'domain/dto/repositories/whereDtos/LegalClientRepositoryDto'; @@ -6,6 +8,14 @@ import { type LegalClient } from 'domain/entities/LegalClientEntities/LegalClien import { type LegalPerson } from 'domain/entities/LegalPerson/LegalPerson'; export abstract class LegalClientRepository { + abstract count( + parameters: CountAllLegalClientsWhereRequestDTO, + ): Promise; + abstract delete(id: string): Promise; + abstract updateMany( + legalClient: UpdateManyLegalClientsDTO[], + ): Promise; + abstract deleteMany(ids: string[]): Promise; abstract findLegalClient(request: getLegalClientData): Promise; abstract createLegalClient( legalClient: LegalClient, diff --git a/src/domain/repositories/OwnDriverRepository.ts b/src/domain/repositories/OwnDriverRepository.ts index 96cd8169..fbdf27e9 100644 --- a/src/domain/repositories/OwnDriverRepository.ts +++ b/src/domain/repositories/OwnDriverRepository.ts @@ -1,9 +1,21 @@ import { type GetOwnDriverDTO } from 'domain/dto/repositories/getDataDtos/GetOwnDriverDto'; -import { type FindAllOwnDriverWhereRequestDTO } from 'domain/dto/repositories/whereDtos/OwnDriverRepositoryDto'; +import { + type CountAllOwnDriversWhereRequestDTO, + type UpdateManyOwnDriversDTO, + type FindAllOwnDriverWhereRequestDTO, +} from 'domain/dto/repositories/whereDtos/OwnDriverRepositoryDto'; import { type OwnDriver } from 'domain/entities/CompanyEntities/ownDriver/OwnDriver'; import { type NaturalPerson } from 'domain/entities/NaturalPerson/NaturalPerson'; export abstract class OwnDriverRepository { + abstract count( + parameters: CountAllOwnDriversWhereRequestDTO, + ): Promise; + abstract delete(id: string): Promise; + abstract updateMany( + ownDriver: UpdateManyOwnDriversDTO[], + ): Promise; + abstract deleteMany(ids: string[]): Promise; abstract findOwnDriver(request: GetOwnDriverDTO): Promise; abstract createOwnDriver( OwnDriver: OwnDriver, diff --git a/src/domain/repositories/PhysicalCustomerRepository.ts b/src/domain/repositories/PhysicalCustomerRepository.ts index 2d649520..a861d117 100644 --- a/src/domain/repositories/PhysicalCustomerRepository.ts +++ b/src/domain/repositories/PhysicalCustomerRepository.ts @@ -1,9 +1,21 @@ import { type GetPhysicalCustomerDTO } from 'domain/dto/repositories/getDataDtos/GetPhysicalCustomerDto'; -import { type FindAllPhysicalCustomerWhereRequestDTO } from 'domain/dto/repositories/whereDtos/PhysicalCustomerRepositoryDto'; +import { + type UpdateManyPhysicalCustomersDTO, + type CountAllPhysicalCustomersWhereRequestDTO, + type FindAllPhysicalCustomerWhereRequestDTO, +} from 'domain/dto/repositories/whereDtos/PhysicalCustomerRepositoryDto'; import { type NaturalPerson } from 'domain/entities/NaturalPerson/NaturalPerson'; import { type PhysicalCustomer } from 'domain/entities/PhysicalClientEntities/physicalCustomer/PhysicalCustomer'; export abstract class PhysicalCustomerRepository { + abstract count( + parameters: CountAllPhysicalCustomersWhereRequestDTO, + ): Promise; + abstract delete(id: string): Promise; + abstract updateMany( + physicalCustomer: UpdateManyPhysicalCustomersDTO[], + ): Promise; + abstract deleteMany(ids: string[]): Promise; abstract findPhysicalCustomer( request: GetPhysicalCustomerDTO, ): Promise; diff --git a/src/domain/repositories/RecipientRepository .ts b/src/domain/repositories/RecipientRepository .ts index 18c0083b..dcfb47b8 100644 --- a/src/domain/repositories/RecipientRepository .ts +++ b/src/domain/repositories/RecipientRepository .ts @@ -1,10 +1,16 @@ import { type GetRecipientDTO } from 'domain/dto/repositories/getDataDtos/GetRecipientDto'; import { type FindAllRecipientWhereRequestDTO } from 'domain/dto/repositories/whereDtos/RecipientRepositoryDto'; +import { + type CountAllUserWhereRequestDTO, + type UpdateManyUsersDTO, +} from 'domain/dto/repositories/whereDtos/UserRepositoryDto'; import { type LegalPerson } from 'domain/entities/LegalPerson/LegalPerson'; import { type NaturalPerson } from 'domain/entities/NaturalPerson/NaturalPerson'; import { type Recipient } from 'domain/entities/Recipient/Recipient'; export abstract class RecipientRepository { + abstract count(parameters: CountAllUserWhereRequestDTO): Promise; + abstract delete(id: string): Promise; abstract findRecipient(request: GetRecipientDTO): Promise; abstract findAllRecipient( parameters: FindAllRecipientWhereRequestDTO, @@ -14,6 +20,8 @@ export abstract class RecipientRepository { legalPerson?: LegalPerson, naturalPerson?: NaturalPerson, ): Promise; + abstract updateMany(recipient: UpdateManyUsersDTO[]): Promise; + abstract deleteMany(ids: string[]): Promise; abstract updateRecipient( id: string, recipient: Recipient, diff --git a/src/domain/repositories/SenderRepository.ts b/src/domain/repositories/SenderRepository.ts index bc3869ff..38e2c5d7 100644 --- a/src/domain/repositories/SenderRepository.ts +++ b/src/domain/repositories/SenderRepository.ts @@ -1,10 +1,18 @@ import { type GetSenderDTO } from 'domain/dto/repositories/getDataDtos/GetSendertDto'; -import { type FindAllSenderWhereRequestDTO } from 'domain/dto/repositories/whereDtos/SenderRepositoryDto'; +import { + type UpdateManySendersDTO, + 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 { type Sender } from 'domain/entities/Sender/Sender'; export abstract class SenderRepository { + abstract count(parameters: CountAllSendersWhereRequestDTO): Promise; + abstract delete(id: string): Promise; + abstract updateMany(sender: UpdateManySendersDTO[]): Promise; + abstract deleteMany(ids: string[]): Promise; abstract findSender(request: GetSenderDTO): Promise; abstract findAllSender( parameters: FindAllSenderWhereRequestDTO, diff --git a/src/domain/repositories/VehicleBrandRepository.ts b/src/domain/repositories/VehicleBrandRepository.ts index 6e1c53ab..f989b677 100644 --- a/src/domain/repositories/VehicleBrandRepository.ts +++ b/src/domain/repositories/VehicleBrandRepository.ts @@ -1,8 +1,20 @@ 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 { type VehicleBrand } from 'domain/entities/VehicleEntities/vehicleBrand/VehicleBrand'; export abstract class VehicleBrandRepository { + abstract count( + parameters: CountAllVehicleBrandsWhereRequestDTO, + ): Promise; + abstract delete(id: string): Promise; + abstract updateMany( + vehicleBrand: UpdateManyVehicleBrandsDTO[], + ): Promise; + abstract deleteMany(ids: string[]): Promise; abstract findVehicleBrand(request: GetVehicleBrandDTO): Promise; abstract createVehicleBrand( vehicleBrand: VehicleBrand, diff --git a/src/domain/repositories/VehicleModelRepository.ts b/src/domain/repositories/VehicleModelRepository.ts index 1888ad91..99252f2b 100644 --- a/src/domain/repositories/VehicleModelRepository.ts +++ b/src/domain/repositories/VehicleModelRepository.ts @@ -1,9 +1,21 @@ 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 { type VehicleModel } from 'domain/entities/VehicleEntities/vehicleModel/VehicleModel'; import { type VehicleType } from 'domain/entities/VehicleEntities/vehicleTypes/VehicleTypes'; export abstract class VehicleModelRepository { + abstract count( + parameters: CountAllVehicleModelsWhereRequestDTO, + ): Promise; + abstract delete(id: string): Promise; + abstract updateMany( + vehicleModel: UpdateManyVehicleModelsDTO[], + ): Promise; + abstract deleteMany(ids: string[]): Promise; abstract findVehicleModel(request: GetVehicleModelDTO): Promise; abstract createVehicleModel( vehicleModel: VehicleModel, diff --git a/src/domain/repositories/VehicleTypeRepository.ts b/src/domain/repositories/VehicleTypeRepository.ts index 5ec394cf..8080609b 100644 --- a/src/domain/repositories/VehicleTypeRepository.ts +++ b/src/domain/repositories/VehicleTypeRepository.ts @@ -1,8 +1,20 @@ import { type GetVehicleTypeDTO } from 'domain/dto/repositories/getDataDtos/GetVehicleTypeDto'; -import { type FindAllVehicleTypeWhereRequestDTO } from 'domain/dto/repositories/whereDtos/VehicleTypeRepositoryDto'; +import { + type CountAllVehicleTypesWhereRequestDTO, + type UpdateManyVehicleTypesDTO, + type FindAllVehicleTypeWhereRequestDTO, +} from 'domain/dto/repositories/whereDtos/VehicleTypeRepositoryDto'; import { type VehicleType } from 'domain/entities/VehicleEntities/vehicleTypes/VehicleTypes'; export abstract class VehicleTypeRepository { + abstract count( + parameters: CountAllVehicleTypesWhereRequestDTO, + ): Promise; + abstract delete(id: string): Promise; + abstract updateMany( + vehicleType: UpdateManyVehicleTypesDTO[], + ): Promise; + abstract deleteMany(ids: string[]): Promise; abstract findVehicleType(request: GetVehicleTypeDTO): Promise; abstract createVehicleType(vehicleBrand: VehicleType): Promise; abstract updateVehicleType( diff --git a/src/infra/database/prisma/services/PhysicalCustomer.service.ts b/src/infra/database/prisma/services/PhysicalCustomer.service.ts index ebd07580..780a50f0 100644 --- a/src/infra/database/prisma/services/PhysicalCustomer.service.ts +++ b/src/infra/database/prisma/services/PhysicalCustomer.service.ts @@ -1,7 +1,13 @@ -import { Injectable } from '@nestjs/common'; +import { HttpStatus, Injectable } from '@nestjs/common'; + +import { GraphQLError } from 'graphql'; import { type GetPhysicalCustomerDTO } from 'domain/dto/repositories/getDataDtos/GetPhysicalCustomerDto'; -import { type FindAllPhysicalCustomerWhereRequestDTO } from 'domain/dto/repositories/whereDtos/PhysicalCustomerRepositoryDto'; +import { + type CountAllPhysicalCustomersWhereRequestDTO, + type UpdateManyPhysicalCustomersDTO, + type FindAllPhysicalCustomerWhereRequestDTO, +} from 'domain/dto/repositories/whereDtos/PhysicalCustomerRepositoryDto'; import { type NaturalPerson } from 'domain/entities/NaturalPerson/NaturalPerson'; import { type PhysicalCustomer } from 'domain/entities/PhysicalClientEntities/physicalCustomer/PhysicalCustomer'; import { type PhysicalCustomerRepository } from 'domain/repositories/PhysicalCustomerRepository'; @@ -14,6 +20,131 @@ export class PhysicalCustomerPrismaService implements PhysicalCustomerRepository { constructor(private prisma: PrismaService) {} + + async count( + parameters: CountAllPhysicalCustomersWhereRequestDTO, + ): Promise { + const count = this.prisma.physicalCustomer.count({ + where: parameters.where, + }); + + return count; + } + + async delete(id: string): Promise { + const physicalCustomer = await this.prisma.physicalCustomer.findUnique({ + where: { id }, + }); + + if (!physicalCustomer) { + throw new GraphQLError('Physical Customer not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + const physicalCustomerPrisma = await this.prisma.physicalCustomer.delete({ + where: { id }, + }); + + if (!physicalCustomerPrisma) { + throw new GraphQLError('Physical Customer not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const physicalCustomerDomain = PhysicalCustomerPrismaDTO.PrismaToEntity( + physicalCustomerPrisma, + ); + + return physicalCustomerDomain; + } + + async updateMany( + physicalCustomer: UpdateManyPhysicalCustomersDTO[], + ): Promise { + const physicalCustomers: PhysicalCustomer[] = []; + + await Promise.all( + physicalCustomer.map(async item => { + const physicalCustomer = await this.prisma.physicalCustomer.findUnique({ + where: { id: item.id }, + }); + + if (!physicalCustomer) { + throw new GraphQLError( + `Physical Customer with id "${item.id}" not found!`, + { + extensions: { code: HttpStatus.NOT_FOUND }, + }, + ); + } + + await this.prisma.$transaction(async tx => { + const physicalCustomerPrisma = await tx.physicalCustomer.update({ + where: { id: item.id }, + data: { + ...item, + updated_at: new Date(), + }, + }); + + if (!physicalCustomerPrisma) { + throw new GraphQLError( + `Physical Customer with id "${item.id}" not updated!`, + { + extensions: { code: HttpStatus.BAD_REQUEST }, + }, + ); + } + + const physicalCustomerDomain = + PhysicalCustomerPrismaDTO.PrismaToEntity(physicalCustomerPrisma); + + physicalCustomers.push(physicalCustomerDomain); + }); + }), + ); + + return physicalCustomers; + } + + async deleteMany(ids: string[]): Promise { + const physicalCustomers: PhysicalCustomer[] = []; + + await Promise.all( + ids.map(async id => { + const physicalCustomer = await this.prisma.physicalCustomer.findUnique({ + where: { id }, + }); + + if (!physicalCustomer) { + throw new GraphQLError('Physical Customer not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + await this.prisma.$transaction(async tx => { + const physicalCustomerPrisma = await tx.physicalCustomer.delete({ + where: { id }, + }); + + if (!physicalCustomerPrisma) { + throw new GraphQLError('Physical Customer not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const physicalCustomerDomain = + PhysicalCustomerPrismaDTO.PrismaToEntity(physicalCustomerPrisma); + + physicalCustomers.push(physicalCustomerDomain); + }); + }), + ); + + return physicalCustomers; + } + async findPhysicalCustomer( request: GetPhysicalCustomerDTO, ): Promise { diff --git a/src/infra/database/prisma/services/Sender.service.ts b/src/infra/database/prisma/services/Sender.service.ts index 34f20919..606112ce 100644 --- a/src/infra/database/prisma/services/Sender.service.ts +++ b/src/infra/database/prisma/services/Sender.service.ts @@ -1,7 +1,13 @@ -import { Injectable } from '@nestjs/common'; +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 UpdateManySendersDTO, + 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 { type Sender } from 'domain/entities/Sender/Sender'; @@ -14,6 +20,114 @@ import { SenderPrismaDTO } from './prismaDTO/SenderPrismaDto'; export class SenderPrismaService implements SenderRepository { constructor(private prisma: PrismaService) {} + async count(parameters: CountAllSendersWhereRequestDTO): Promise { + const count = this.prisma.sender.count({ where: parameters.where }); + + return count; + } + + async delete(id: string): Promise { + const sender = await this.prisma.sender.findUnique({ + where: { id }, + }); + + if (!sender) { + throw new GraphQLError('Sender not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + const senderPrisma = await this.prisma.sender.delete({ + where: { id }, + }); + + if (!senderPrisma) { + throw new GraphQLError('Sender not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const senderDomain = SenderPrismaDTO.PrismaToEntity(senderPrisma); + + return senderDomain; + } + + async updateMany(sender: UpdateManySendersDTO[]): Promise { + const senders: Sender[] = []; + + await Promise.all( + sender.map(async item => { + const sender = await this.prisma.sender.findUnique({ + where: { id: item.id }, + }); + + if (!sender) { + throw new GraphQLError(`Sender with id "${item.id}" not found!`, { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + await this.prisma.$transaction(async tx => { + const senderPrisma = await tx.sender.update({ + where: { id: item.id }, + data: { + ...item, + updated_at: new Date(), + }, + }); + + if (!senderPrisma) { + throw new GraphQLError(`Sender with id "${item.id}" not updated!`, { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const senderDomain = SenderPrismaDTO.PrismaToEntity(senderPrisma); + + senders.push(senderDomain); + }); + }), + ); + + return senders; + } + + async deleteMany(ids: string[]): Promise { + const senders: Sender[] = []; + + await Promise.all( + ids.map(async id => { + const sender = await this.prisma.sender.findUnique({ + where: { id }, + }); + + if (!sender) { + throw new GraphQLError('Sender not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + await this.prisma.$transaction(async tx => { + const senderPrisma = await tx.sender.delete({ + where: { id }, + }); + + if (!senderPrisma) { + throw new GraphQLError('Sender not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const senderDomain = SenderPrismaDTO.PrismaToEntity(senderPrisma); + + senders.push(senderDomain); + }); + }), + ); + + return senders; + } + async findSender(data: GetSenderDTO): Promise { const sender = await this.prisma.sender.findFirst({ where: { diff --git a/src/infra/database/prisma/services/legal-client.service.ts b/src/infra/database/prisma/services/legal-client.service.ts index df669622..8b32d9e6 100644 --- a/src/infra/database/prisma/services/legal-client.service.ts +++ b/src/infra/database/prisma/services/legal-client.service.ts @@ -1,6 +1,10 @@ -import { Injectable } from '@nestjs/common'; +import { HttpStatus, Injectable } from '@nestjs/common'; + +import { GraphQLError } from 'graphql'; import { + type CountAllLegalClientsWhereRequestDTO, + type UpdateManyLegalClientsDTO, type getLegalClientData, type FindAllLegalClientWhereRequestDTO, } from 'domain/dto/repositories/whereDtos/LegalClientRepositoryDto'; @@ -14,6 +18,128 @@ import { LegalClientPrismaDTO } from './prismaDTO/LegalClientPrismaDto'; @Injectable() export class LegalClientPrismaService implements LegalClientRepository { constructor(private prisma: PrismaService) {} + async count( + parameters: CountAllLegalClientsWhereRequestDTO, + ): Promise { + const count = this.prisma.legalClient.count({ + where: parameters.where, + }); + + return count; + } + + async delete(id: string): Promise { + const legalClient = await this.prisma.legalClient.findUnique({ + where: { id }, + }); + + if (!legalClient) { + throw new GraphQLError('Legal Client not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + const legalClientPrisma = await this.prisma.legalClient.delete({ + where: { id }, + }); + + if (!legalClientPrisma) { + throw new GraphQLError('Legal Client not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const legalClientDomain = + LegalClientPrismaDTO.PrismaToEntity(legalClientPrisma); + + return legalClientDomain; + } + + async updateMany( + legalClient: UpdateManyLegalClientsDTO[], + ): Promise { + const legalClients: LegalClient[] = []; + + await Promise.all( + legalClient.map(async item => { + const legalClient = await this.prisma.legalClient.findUnique({ + where: { id: item.id }, + }); + + if (!legalClient) { + throw new GraphQLError( + `Physical Customer with id "${item.id}" not found!`, + { + extensions: { code: HttpStatus.NOT_FOUND }, + }, + ); + } + + await this.prisma.$transaction(async tx => { + const legalClientPrisma = await tx.legalClient.update({ + where: { id: item.id }, + data: { + ...item, + }, + }); + + if (!legalClientPrisma) { + throw new GraphQLError( + `Legal Client with id "${item.id}" not updated!`, + { + extensions: { code: HttpStatus.BAD_REQUEST }, + }, + ); + } + + const legalClientDomain = + LegalClientPrismaDTO.PrismaToEntity(legalClientPrisma); + + legalClients.push(legalClientDomain); + }); + }), + ); + + return legalClients; + } + + async deleteMany(ids: string[]): Promise { + const legalClients: LegalClient[] = []; + + await Promise.all( + ids.map(async id => { + const legalClient = await this.prisma.legalClient.findUnique({ + where: { id }, + }); + + if (!legalClient) { + throw new GraphQLError('Legal Client not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + await this.prisma.$transaction(async tx => { + const legalClientPrisma = await tx.legalClient.delete({ + where: { id }, + }); + + if (!legalClientPrisma) { + throw new GraphQLError('Legal Client not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const legalClientDomain = + LegalClientPrismaDTO.PrismaToEntity(legalClientPrisma); + + legalClients.push(legalClientDomain); + }); + }), + ); + + return legalClients; + } + async findLegalClient(request: getLegalClientData): Promise { const legalClient = await this.prisma.legalClient.findFirst({ where: { diff --git a/src/infra/database/prisma/services/own-driver.service.ts b/src/infra/database/prisma/services/own-driver.service.ts index 1051373a..d9fd0f12 100644 --- a/src/infra/database/prisma/services/own-driver.service.ts +++ b/src/infra/database/prisma/services/own-driver.service.ts @@ -1,7 +1,13 @@ -import { Injectable } from '@nestjs/common'; +import { HttpStatus, Injectable } from '@nestjs/common'; + +import { GraphQLError } from 'graphql'; import { type GetOwnDriverDTO } from 'domain/dto/repositories/getDataDtos/GetOwnDriverDto'; -import { type FindAllOwnDriverWhereRequestDTO } from 'domain/dto/repositories/whereDtos/OwnDriverRepositoryDto'; +import { + type CountAllOwnDriversWhereRequestDTO, + type UpdateManyOwnDriversDTO, + type FindAllOwnDriverWhereRequestDTO, +} from 'domain/dto/repositories/whereDtos/OwnDriverRepositoryDto'; import { type OwnDriver } from 'domain/entities/CompanyEntities/ownDriver/OwnDriver'; import { type NaturalPerson } from 'domain/entities/NaturalPerson/NaturalPerson'; import { type OwnDriverRepository } from 'domain/repositories/OwnDriverRepository'; @@ -12,6 +18,120 @@ import { OwnDriverPrismaDTO } from './prismaDTO/OwnDriverPrismaDto'; @Injectable() export class OwnDriverService implements OwnDriverRepository { constructor(private prisma: PrismaService) {} + + async count(parameters: CountAllOwnDriversWhereRequestDTO): Promise { + const count = this.prisma.ownDriver.count({ where: parameters.where }); + + return count; + } + + async delete(id: string): Promise { + const ownDriver = await this.prisma.ownDriver.findUnique({ + where: { id }, + }); + + if (!ownDriver) { + throw new GraphQLError('OwnDriver not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + const ownDriverPrisma = await this.prisma.ownDriver.delete({ + where: { id }, + }); + + if (!ownDriverPrisma) { + throw new GraphQLError('OwnDriver not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const ownDriverDomain = OwnDriverPrismaDTO.PrismaToEntity(ownDriverPrisma); + + return ownDriverDomain; + } + + async updateMany(ownDriver: UpdateManyOwnDriversDTO[]): Promise { + const ownDrivers: OwnDriver[] = []; + + await Promise.all( + ownDriver.map(async item => { + const ownDriver = await this.prisma.ownDriver.findUnique({ + where: { id: item.id }, + }); + + if (!ownDriver) { + throw new GraphQLError(`OwnDriver with id "${item.id}" not found!`, { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + await this.prisma.$transaction(async tx => { + const ownDriverPrisma = await tx.ownDriver.update({ + where: { id: item.id }, + data: { + ...item, + updated_at: new Date(), + }, + }); + + if (!ownDriverPrisma) { + throw new GraphQLError( + `OwnDriver with id "${item.id}" not updated!`, + { + extensions: { code: HttpStatus.BAD_REQUEST }, + }, + ); + } + + const ownDriverDomain = + OwnDriverPrismaDTO.PrismaToEntity(ownDriverPrisma); + + ownDrivers.push(ownDriverDomain); + }); + }), + ); + + return ownDrivers; + } + + async deleteMany(ids: string[]): Promise { + const ownDrivers: OwnDriver[] = []; + + await Promise.all( + ids.map(async id => { + const ownDriver = await this.prisma.ownDriver.findUnique({ + where: { id }, + }); + + if (!ownDriver) { + throw new GraphQLError('OwnDriver not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + await this.prisma.$transaction(async tx => { + const ownDriverPrisma = await tx.ownDriver.delete({ + where: { id }, + }); + + if (!ownDriverPrisma) { + throw new GraphQLError('OwnDriver not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const ownDriverDomain = + OwnDriverPrismaDTO.PrismaToEntity(ownDriverPrisma); + + ownDrivers.push(ownDriverDomain); + }); + }), + ); + + return ownDrivers; + } + async findOwnDriver(request: GetOwnDriverDTO): Promise { return OwnDriverPrismaDTO.PrismaToEntity( await this.prisma.ownDriver.findFirst({ diff --git a/src/infra/database/prisma/services/recipient.service.ts b/src/infra/database/prisma/services/recipient.service.ts index efde7f6b..7fe57842 100644 --- a/src/infra/database/prisma/services/recipient.service.ts +++ b/src/infra/database/prisma/services/recipient.service.ts @@ -1,7 +1,13 @@ -import { Injectable } from '@nestjs/common'; +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 CountAllUserWhereRequestDTO, + type UpdateManyUsersDTO, +} from 'domain/dto/repositories/whereDtos/UserRepositoryDto'; import { type LegalPerson } from 'domain/entities/LegalPerson/LegalPerson'; import { type NaturalPerson } from 'domain/entities/NaturalPerson/NaturalPerson'; import { type Recipient } from 'domain/entities/Recipient/Recipient'; @@ -14,6 +20,119 @@ import { RecipientPrismaDTO } from './prismaDTO/RecipientPrismaDto'; export class RecipientPrismaService implements RecipientRepository { constructor(private prisma: PrismaService) {} + async count(parameters: CountAllUserWhereRequestDTO): Promise { + const count = this.prisma.recipient.count({ where: parameters.where }); + + return count; + } + + async delete(id: string): Promise { + const recipient = await this.prisma.recipient.findUnique({ + where: { id }, + }); + + if (!recipient) { + throw new GraphQLError('Recipient not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + const recipientPrisma = await this.prisma.recipient.delete({ + where: { id }, + }); + + if (!recipientPrisma) { + throw new GraphQLError('Recipient not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const recipientDomain = RecipientPrismaDTO.PrismaToEntity(recipientPrisma); + + return recipientDomain; + } + + async updateMany(recipient: UpdateManyUsersDTO[]): Promise { + const recipients: Recipient[] = []; + + await Promise.all( + recipient.map(async item => { + const recipient = await this.prisma.recipient.findUnique({ + where: { id: item.id }, + }); + + if (!recipient) { + throw new GraphQLError(`Recipient with id "${item.id}" not found!`, { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + await this.prisma.$transaction(async tx => { + const recipientPrisma = await tx.recipient.update({ + where: { id: item.id }, + data: { + ...item, + updated_at: new Date(), + }, + }); + + if (!recipientPrisma) { + throw new GraphQLError( + `Recipient with id "${item.id}" not updated!`, + { + extensions: { code: HttpStatus.BAD_REQUEST }, + }, + ); + } + + const recipientDomain = + RecipientPrismaDTO.PrismaToEntity(recipientPrisma); + + recipients.push(recipientDomain); + }); + }), + ); + + return recipients; + } + + async deleteMany(ids: string[]): Promise { + const recipients: Recipient[] = []; + + await Promise.all( + ids.map(async id => { + const recipient = await this.prisma.recipient.findUnique({ + where: { id }, + }); + + if (!recipient) { + throw new GraphQLError('Recipient not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + await this.prisma.$transaction(async tx => { + const recipientPrisma = await tx.recipient.delete({ + where: { id }, + }); + + if (!recipientPrisma) { + throw new GraphQLError('Recipient not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const recipientDomain = + RecipientPrismaDTO.PrismaToEntity(recipientPrisma); + + recipients.push(recipientDomain); + }); + }), + ); + + return recipients; + } + async findRecipient(data: GetRecipientDTO): Promise { const recipient = await this.prisma.recipient.findFirst({ where: { diff --git a/src/infra/database/prisma/services/vehicle-brand.service.ts b/src/infra/database/prisma/services/vehicle-brand.service.ts index 541cd66c..5071c38e 100644 --- a/src/infra/database/prisma/services/vehicle-brand.service.ts +++ b/src/infra/database/prisma/services/vehicle-brand.service.ts @@ -1,7 +1,13 @@ -import { Injectable } from '@nestjs/common'; +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 UpdateManyVehicleBrandsDTO, + type CountAllVehicleBrandsWhereRequestDTO, + type FindAllVehicleBrandWhereRequestDTO, +} from 'domain/dto/repositories/whereDtos/VehicleBrandRepositoryDto'; import { type VehicleBrand } from 'domain/entities/VehicleEntities/vehicleBrand/VehicleBrand'; import { type VehicleBrandRepository } from 'domain/repositories/VehicleBrandRepository'; @@ -10,6 +16,127 @@ import { VehicleBrandPrismaDTO } from './prismaDTO/VehicleBrandPrismaDto'; @Injectable() export class VehicleBrandService implements VehicleBrandRepository { + async count( + parameters: CountAllVehicleBrandsWhereRequestDTO, + ): Promise { + const count = this.prisma.vehicleBrand.count({ where: parameters.where }); + + return count; + } + + async delete(id: string): Promise { + const vehicleBrand = await this.prisma.vehicleBrand.findUnique({ + where: { id }, + }); + + if (!vehicleBrand) { + throw new GraphQLError('vehicleBrand not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + const vehicleBrandPrisma = await this.prisma.vehicleBrand.delete({ + where: { id }, + }); + + if (!vehicleBrandPrisma) { + throw new GraphQLError('vehicleBrand not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const vehicleBrandDomain = + VehicleBrandPrismaDTO.PrismaToEntity(vehicleBrandPrisma); + + return vehicleBrandDomain; + } + + async updateMany( + vehicleBrand: UpdateManyVehicleBrandsDTO[], + ): Promise { + const vehicleBrands: VehicleBrand[] = []; + + await Promise.all( + vehicleBrand.map(async item => { + const vehicleBrand = await this.prisma.vehicleBrand.findUnique({ + where: { id: item.id }, + }); + + if (!vehicleBrand) { + throw new GraphQLError( + `Vehicle Brand with id "${item.id}" not found!`, + { + extensions: { code: HttpStatus.NOT_FOUND }, + }, + ); + } + + await this.prisma.$transaction(async tx => { + const vehicleBrandPrisma = await tx.vehicleBrand.update({ + where: { id: item.id }, + data: { + ...item, + updated_at: new Date(), + }, + }); + + if (!vehicleBrandPrisma) { + throw new GraphQLError( + `Vehicle Brand with id "${item.id}" not updated!`, + { + extensions: { code: HttpStatus.BAD_REQUEST }, + }, + ); + } + + const vehicleBrandDomain = + VehicleBrandPrismaDTO.PrismaToEntity(vehicleBrandPrisma); + + vehicleBrands.push(vehicleBrandDomain); + }); + }), + ); + + return vehicleBrands; + } + + async deleteMany(ids: string[]): Promise { + const vehicleBrands: VehicleBrand[] = []; + + await Promise.all( + ids.map(async id => { + const vehicleBrand = await this.prisma.vehicleBrand.findUnique({ + where: { id }, + }); + + if (!vehicleBrand) { + throw new GraphQLError('Vehicle Brand not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + await this.prisma.$transaction(async tx => { + const vehicleBrandPrisma = await tx.vehicleBrand.delete({ + where: { id }, + }); + + if (!vehicleBrandPrisma) { + throw new GraphQLError('Vehicle Brand not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const vehicleBrandDomain = + VehicleBrandPrismaDTO.PrismaToEntity(vehicleBrandPrisma); + + vehicleBrands.push(vehicleBrandDomain); + }); + }), + ); + + return vehicleBrands; + } + constructor(private prisma: PrismaService) {} async findVehicleBrand(request: GetVehicleBrandDTO): Promise { const brand = await this.prisma.vehicleBrand.findFirst({ diff --git a/src/infra/database/prisma/services/vehicle-model.service.ts b/src/infra/database/prisma/services/vehicle-model.service.ts index e86ae06e..fa4caa3b 100644 --- a/src/infra/database/prisma/services/vehicle-model.service.ts +++ b/src/infra/database/prisma/services/vehicle-model.service.ts @@ -1,7 +1,13 @@ -import { Injectable } from '@nestjs/common'; +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 { type VehicleBrand } from 'domain/entities/VehicleEntities/vehicleBrand/VehicleBrand'; import { type VehicleModel } from 'domain/entities/VehicleEntities/vehicleModel/VehicleModel'; import { type VehicleType } from 'domain/entities/VehicleEntities/vehicleTypes/VehicleTypes'; @@ -16,6 +22,127 @@ import { VehicleTypePrismaDTO } from './prismaDTO/VehicleTypePrismaDto.ts'; export class VehicleModelService implements VehicleModelRepository { constructor(private prisma: PrismaService) {} + async count( + parameters: CountAllVehicleModelsWhereRequestDTO, + ): Promise { + const count = this.prisma.vehicleModel.count({ where: parameters.where }); + + return count; + } + + async delete(id: string): Promise { + const vehicleModel = await this.prisma.vehicleModel.findUnique({ + where: { id }, + }); + + if (!vehicleModel) { + throw new GraphQLError('vehicleModel not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + const vehicleModelPrisma = await this.prisma.vehicleModel.delete({ + where: { id }, + }); + + if (!vehicleModelPrisma) { + throw new GraphQLError('vehicleModel not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const vehicleModelDomain = + VehicleModelPrismaDTO.PrismaToEntity(vehicleModelPrisma); + + return vehicleModelDomain; + } + + async updateMany( + vehicleModel: UpdateManyVehicleModelsDTO[], + ): Promise { + const vehicleModels: VehicleModel[] = []; + + await Promise.all( + vehicleModel.map(async item => { + const vehicleModel = await this.prisma.vehicleModel.findUnique({ + where: { id: item.id }, + }); + + if (!vehicleModel) { + throw new GraphQLError( + `Vehicle Model with id "${item.id}" not found!`, + { + extensions: { code: HttpStatus.NOT_FOUND }, + }, + ); + } + + await this.prisma.$transaction(async tx => { + const vehicleModelPrisma = await tx.vehicleModel.update({ + where: { id: item.id }, + data: { + ...item, + updated_at: new Date(), + }, + }); + + if (!vehicleModelPrisma) { + throw new GraphQLError( + `Vehicle Model with id "${item.id}" not updated!`, + { + extensions: { code: HttpStatus.BAD_REQUEST }, + }, + ); + } + + const vehicleModelDomain = + VehicleModelPrismaDTO.PrismaToEntity(vehicleModelPrisma); + + vehicleModels.push(vehicleModelDomain); + }); + }), + ); + + return vehicleModels; + } + + async deleteMany(ids: string[]): Promise { + const vehicleModels: VehicleModel[] = []; + + await Promise.all( + ids.map(async id => { + const vehicleModel = await this.prisma.vehicleModel.findUnique({ + where: { id }, + }); + + if (!vehicleModel) { + throw new GraphQLError('Vehicle Model not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + await this.prisma.$transaction(async tx => { + const vehicleModelPrisma = await tx.vehicleModel.delete({ + where: { id }, + }); + + if (!vehicleModelPrisma) { + throw new GraphQLError('Vehicle Model not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const vehicleModelDomain = + VehicleModelPrismaDTO.PrismaToEntity(vehicleModelPrisma); + + vehicleModels.push(vehicleModelDomain); + }); + }), + ); + + return vehicleModels; + } + async findVehicleModel(request: GetVehicleModelDTO): Promise { const vehicleModelPrisma = await this.prisma.vehicleModel.findFirst({ where: { OR: [{ id: request.id }, { name: request.name }] }, diff --git a/src/infra/database/prisma/services/vehicle-type.service.ts b/src/infra/database/prisma/services/vehicle-type.service.ts index e5e6ffcf..988e8244 100644 --- a/src/infra/database/prisma/services/vehicle-type.service.ts +++ b/src/infra/database/prisma/services/vehicle-type.service.ts @@ -1,7 +1,13 @@ -import { Injectable } from '@nestjs/common'; +import { HttpStatus, Injectable } from '@nestjs/common'; + +import { GraphQLError } from 'graphql'; import { type GetVehicleTypeDTO } from 'domain/dto/repositories/getDataDtos/GetVehicleTypeDto'; -import { type FindAllVehicleTypeWhereRequestDTO } from 'domain/dto/repositories/whereDtos/VehicleTypeRepositoryDto'; +import { + type CountAllVehicleTypesWhereRequestDTO, + type UpdateManyVehicleTypesDTO, + type FindAllVehicleTypeWhereRequestDTO, +} from 'domain/dto/repositories/whereDtos/VehicleTypeRepositoryDto'; import { type VehicleType } from 'domain/entities/VehicleEntities/vehicleTypes/VehicleTypes'; import { type VehicleTypeRepository } from 'domain/repositories/VehicleTypeRepository'; @@ -12,6 +18,127 @@ import { VehicleTypePrismaDTO } from './prismaDTO/VehicleTypePrismaDto.ts'; export class VehicleTypeService implements VehicleTypeRepository { constructor(private prisma: PrismaService) {} + async count( + parameters: CountAllVehicleTypesWhereRequestDTO, + ): Promise { + const count = this.prisma.vehicleType.count({ where: parameters.where }); + + return count; + } + + async delete(id: string): Promise { + const vehicleType = await this.prisma.vehicleType.findUnique({ + where: { id }, + }); + + if (!vehicleType) { + throw new GraphQLError('vehicleType not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + const vehicleTypePrisma = await this.prisma.vehicleType.delete({ + where: { id }, + }); + + if (!vehicleTypePrisma) { + throw new GraphQLError('vehicleType not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const vehicleTypeDomain = + VehicleTypePrismaDTO.PrismaToEntity(vehicleTypePrisma); + + return vehicleTypeDomain; + } + + async updateMany( + vehicleType: UpdateManyVehicleTypesDTO[], + ): Promise { + const vehicleTypes: VehicleType[] = []; + + await Promise.all( + vehicleType.map(async item => { + const vehicleType = await this.prisma.vehicleType.findUnique({ + where: { id: item.id }, + }); + + if (!vehicleType) { + throw new GraphQLError( + `Vehicle Type with id "${item.id}" not found!`, + { + extensions: { code: HttpStatus.NOT_FOUND }, + }, + ); + } + + await this.prisma.$transaction(async tx => { + const vehicleTypePrisma = await tx.vehicleType.update({ + where: { id: item.id }, + data: { + ...item, + updated_at: new Date(), + }, + }); + + if (!vehicleTypePrisma) { + throw new GraphQLError( + `Vehicle Type with id "${item.id}" not updated!`, + { + extensions: { code: HttpStatus.BAD_REQUEST }, + }, + ); + } + + const vehicleTypeDomain = + VehicleTypePrismaDTO.PrismaToEntity(vehicleTypePrisma); + + vehicleTypes.push(vehicleTypeDomain); + }); + }), + ); + + return vehicleTypes; + } + + async deleteMany(ids: string[]): Promise { + const vehicleTypes: VehicleType[] = []; + + await Promise.all( + ids.map(async id => { + const vehicleType = await this.prisma.vehicleType.findUnique({ + where: { id }, + }); + + if (!vehicleType) { + throw new GraphQLError('Vehicle Type not found!', { + extensions: { code: HttpStatus.NOT_FOUND }, + }); + } + + await this.prisma.$transaction(async tx => { + const vehicleTypePrisma = await tx.vehicleType.delete({ + where: { id }, + }); + + if (!vehicleTypePrisma) { + throw new GraphQLError('Vehicle Type not deleted!', { + extensions: { code: HttpStatus.BAD_REQUEST }, + }); + } + + const vehicleTypeDomain = + VehicleTypePrismaDTO.PrismaToEntity(vehicleTypePrisma); + + vehicleTypes.push(vehicleTypeDomain); + }); + }), + ); + + return vehicleTypes; + } + async findVehicleType(request: GetVehicleTypeDTO): Promise { const vehicleTypePrisma = await this.prisma.vehicleType.findFirst({ where: { OR: [{ id: request.id }, { name: request.name }] }, diff --git a/src/infra/graphql/entities/CarrierCompanyGraphql/Args/WhereCarrierCompanyArgs.ts b/src/infra/graphql/entities/CarrierCompanyGraphql/Args/WhereCarrierCompanyArgs.ts index 7925b907..1acd0a46 100644 --- a/src/infra/graphql/entities/CarrierCompanyGraphql/Args/WhereCarrierCompanyArgs.ts +++ b/src/infra/graphql/entities/CarrierCompanyGraphql/Args/WhereCarrierCompanyArgs.ts @@ -31,3 +31,11 @@ export class CarrierCompanyWhereArgs { @IsOptional() sort?: CarrierCompanyOrderByWithRelationInput; } + +@ArgsType() +export class CarrierCompanyCountArgs { + @Field(() => CarrierCompanyWhereInput, { nullable: true }) + @Type(() => CarrierCompanyWhereInput) + @IsOptional() + where?: CarrierCompanyWhereInput; +} diff --git a/src/infra/graphql/entities/CarrierCompanyGraphql/CarrierCompany.resolver.ts b/src/infra/graphql/entities/CarrierCompanyGraphql/CarrierCompany.resolver.ts index 6e7c5a28..0ea914b7 100644 --- a/src/infra/graphql/entities/CarrierCompanyGraphql/CarrierCompany.resolver.ts +++ b/src/infra/graphql/entities/CarrierCompanyGraphql/CarrierCompany.resolver.ts @@ -15,7 +15,10 @@ import { LegalPersonUseCases } from 'app/useCases/LegalPersonUseCases/LegalPerso import { UserUseCases } from 'app/useCases/user/UserCases'; import { LegalPersonGraphqlDTO } from 'infra/graphql/DTO/LegalPersonGraphqlDto'; -import { CarrierCompanyWhereArgs } from 'infra/graphql/entities/CarrierCompanyGraphql/Args/WhereCarrierCompanyArgs'; +import { + CarrierCompanyCountArgs, + CarrierCompanyWhereArgs, +} from 'infra/graphql/entities/CarrierCompanyGraphql/Args/WhereCarrierCompanyArgs'; import { AcessAllowed } from 'infra/graphql/utilities/decorators/AcessAllowed'; import { CurrentUser } from 'infra/graphql/utilities/decorators/CurrentUser'; import { RoleInterceptor } from 'infra/graphql/utilities/interceptors/RoleInterceptor'; @@ -41,12 +44,14 @@ export class CarrierCompanyResolver { private userCase: UserUseCases, private legalPersonUseCase: LegalPersonUseCases, ) {} + @Query(() => CarrierCompanyModel) async getCarrierCompanyModel( @Args() carrierCompanySearch: GetCarrierCompanyArgs, ) { return this.carrierCompanyUseCase.getCarrierCompany(carrierCompanySearch); } + @Query(() => [CarrierCompanyModel], { nullable: true }) async getAllCarrierCompany(@Args() args: CarrierCompanyWhereArgs) { const carrierCompany = @@ -82,6 +87,14 @@ export class CarrierCompanyResolver { carrierCompanyInput, ); } + + @Query(() => Number) + async totalCarrierCompanies(@Args() request: CarrierCompanyCountArgs) { + const carrierCompanies = await this.carrierCompanyUseCase.count(request); + + return carrierCompanies; + } + @ResolveField(() => LegalPersonModel) async LegalPerson( @Parent() legalClient: CarrierCompanyInput | CarrierCompanyUpdateInput, diff --git a/src/infra/graphql/entities/LegalClientGraphql/Args/WhereLegalClientArgs.ts b/src/infra/graphql/entities/LegalClientGraphql/Args/WhereLegalClientArgs.ts index ec169f06..cecc6a2b 100644 --- a/src/infra/graphql/entities/LegalClientGraphql/Args/WhereLegalClientArgs.ts +++ b/src/infra/graphql/entities/LegalClientGraphql/Args/WhereLegalClientArgs.ts @@ -31,3 +31,11 @@ export class LegalClientWhereArgs { @IsOptional() sort?: LegalClientOrderByWithRelationInput; } + +@ArgsType() +export class LegalClientCountArgs { + @Field(() => LegalClientWhereInput, { nullable: true }) + @Type(() => LegalClientWhereInput) + @IsOptional() + where?: LegalClientWhereInput; +} diff --git a/src/infra/graphql/entities/LegalClientGraphql/LegalClient.input.ts b/src/infra/graphql/entities/LegalClientGraphql/LegalClient.input.ts index fb77874d..d565b314 100644 --- a/src/infra/graphql/entities/LegalClientGraphql/LegalClient.input.ts +++ b/src/infra/graphql/entities/LegalClientGraphql/LegalClient.input.ts @@ -12,6 +12,7 @@ import { IsObject, IsOptional, IsString, + IsUUID, } from 'class-validator'; import { type ILegalClient } from 'domain/entities/LegalClientEntities/LegalClient/LegalClient'; @@ -53,3 +54,11 @@ export class LegalClientUpdateInput extends PartialType( @Field(() => LegalPersonUpdateInput) LegalPerson: LegalPersonUpdateInput; } + +@InputType() +export class LegalClientUpdateManyInput extends PartialType(LegalClientInput) { + @Field() + @IsUUID() + @IsNotEmpty() + id: string; +} diff --git a/src/infra/graphql/entities/LegalClientGraphql/LegalClient.resolver.ts b/src/infra/graphql/entities/LegalClientGraphql/LegalClient.resolver.ts index f5a7ff8c..f3c52ae8 100644 --- a/src/infra/graphql/entities/LegalClientGraphql/LegalClient.resolver.ts +++ b/src/infra/graphql/entities/LegalClientGraphql/LegalClient.resolver.ts @@ -16,7 +16,10 @@ import { LegalClientUseCases } from 'app/useCases/LegalClientUseCases/LegalClien import { UserUseCases } from 'app/useCases/user/UserCases'; import { GetLegalClientArgs } from 'infra/graphql/entities/LegalClientGraphql/Args/GetLegalClientArgs'; -import { LegalClientWhereArgs } from 'infra/graphql/entities/LegalClientGraphql/Args/WhereLegalClientArgs'; +import { + LegalClientCountArgs, + LegalClientWhereArgs, +} from 'infra/graphql/entities/LegalClientGraphql/Args/WhereLegalClientArgs'; import { AcessAllowed } from 'infra/graphql/utilities/decorators/AcessAllowed'; import { CurrentUser } from 'infra/graphql/utilities/decorators/CurrentUser'; import { RoleInterceptor } from 'infra/graphql/utilities/interceptors/RoleInterceptor'; @@ -25,7 +28,11 @@ import { GraphQLAuthGuard } from 'infra/guard/GraphQlAuthGuard'; import { LegalClientOrderModel } from '../LegalClientOrderGraphql/LegalClientOrder.model'; import { LegalPersonModel } from '../LegalPersonGraphql/LegalPerson.model'; import { UserModelRefereces } from '../UserGraphql/user.model'; -import { LegalClientInput, LegalClientUpdateInput } from './LegalClient.input'; +import { + LegalClientInput, + LegalClientUpdateInput, + LegalClientUpdateManyInput, +} from './LegalClient.input'; import { LegalClientModel } from './LegalClient.model'; @UseGuards(GraphQLAuthGuard) @@ -39,10 +46,18 @@ export class LegalClientResolver { private legalPersonRepository: LegalPersonRepository, private legalClientOrderRepository: LegalClientOrderRepository, ) {} + @Query(() => Number) + async totalLegalClients(@Args() request: LegalClientCountArgs) { + const legalClient = await this.legalClientUseCase.count(request); + + return legalClient; + } + @Query(() => LegalClientModel) async getLegalClientModel(@Args() legalClientSearch: GetLegalClientArgs) { return await this.legalClientUseCase.getClient(legalClientSearch); } + @Query(() => [LegalClientModel], { nullable: true }) async getAllLegalClient(@Args() args: LegalClientWhereArgs) { const legalclient = await this.legalClientUseCase.getAllClients({ @@ -54,6 +69,7 @@ export class LegalClientResolver { return legalclient.length > 0 ? legalclient : null; } + @Mutation(() => LegalClientModel) async createLegalClient( @Args('legalclientInput') legalclientInput: LegalClientInput, @@ -64,8 +80,9 @@ export class LegalClientResolver { return await this.legalClientUseCase.createLegalClient(legalclientInput); } + @Mutation(() => LegalClientModel) - async updatelegalclient( + async updateLegalClient( @Args('id') id: string, @Args('legalclientInput') legalclientInput: LegalClientUpdateInput, @CurrentUser() user: User, @@ -77,6 +94,33 @@ export class LegalClientResolver { legalclientInput, ); } + + @Mutation(() => [LegalClientModel]) + async updateManyLegalClients( + @Args({ + name: 'updateManyLegalClients', + type: () => [LegalClientUpdateManyInput], + }) + updateLegalClientInput: LegalClientUpdateManyInput[], + ) { + return await this.legalClientUseCase.updateManyLegalClients( + updateLegalClientInput, + ); + } + + @Mutation(() => LegalClientModel) + async deleteLegalClient(@Args('id', { type: () => String }) id: string) { + return await this.legalClientUseCase.deleteLegalClient(id); + } + + @Mutation(() => [LegalClientModel]) + async deleteManyLegalClients( + @Args({ name: 'deleteManyLegalClients', type: () => [String] }) + ids: string[], + ) { + return await this.legalClientUseCase.deleteManyLegalClients(ids); + } + @ResolveField(() => LegalPersonModel) async LegalPerson( @Parent() legalClient: LegalClientInput | LegalClientUpdateInput, @@ -88,18 +132,21 @@ export class LegalClientResolver { return legalPerson; } + @ResolveField(() => [LegalClientOrderModel]) async Orders(@Parent() legalClient: LegalClientModel) { const { id } = legalClient; return this.legalClientOrderRepository.findOrdersByLegalClient(id); } + @ResolveField(() => UserModelRefereces) async CreatedUser(@Parent() user: LegalClientInput) { const { created_by: createdBy } = user; return await this.userCase.getUser({ id: createdBy }); } + @ResolveField(() => UserModelRefereces) async UpdatedUser(@Parent() user: LegalClientInput) { const { updated_by: updatedBy } = user; diff --git a/src/infra/graphql/entities/OwnDriverGraphql/Args/WhereOwnDriverArgs.ts b/src/infra/graphql/entities/OwnDriverGraphql/Args/WhereOwnDriverArgs.ts index a22057b1..77ecec96 100644 --- a/src/infra/graphql/entities/OwnDriverGraphql/Args/WhereOwnDriverArgs.ts +++ b/src/infra/graphql/entities/OwnDriverGraphql/Args/WhereOwnDriverArgs.ts @@ -31,3 +31,11 @@ export class OwnDriverWhereArgs { @IsOptional() sort?: OwnDriverOrderByWithRelationInput; } + +@ArgsType() +export class OwnDriverCountArgs { + @Field(() => OwnDriverWhereInput, { nullable: true }) + @Type(() => OwnDriverWhereInput) + @IsOptional() + where?: OwnDriverWhereInput; +} diff --git a/src/infra/graphql/entities/OwnDriverGraphql/OwnDriver.input.ts b/src/infra/graphql/entities/OwnDriverGraphql/OwnDriver.input.ts index 4eb93230..9c0ced96 100644 --- a/src/infra/graphql/entities/OwnDriverGraphql/OwnDriver.input.ts +++ b/src/infra/graphql/entities/OwnDriverGraphql/OwnDriver.input.ts @@ -77,3 +77,11 @@ export class OwnDriverUpdate extends PartialType( @Field(() => NaturalPersonUpdate, { nullable: true }) NaturalPerson?: NaturalPersonUpdate; } + +@InputType() +export class OwnDriverUpdateManyInput extends PartialType(OwnDriverInput) { + @Field() + @IsUUID() + @IsNotEmpty() + id: string; +} diff --git a/src/infra/graphql/entities/OwnDriverGraphql/OwnDriver.resolver.ts b/src/infra/graphql/entities/OwnDriverGraphql/OwnDriver.resolver.ts index 6434bdbc..a00ec9a2 100644 --- a/src/infra/graphql/entities/OwnDriverGraphql/OwnDriver.resolver.ts +++ b/src/infra/graphql/entities/OwnDriverGraphql/OwnDriver.resolver.ts @@ -14,7 +14,10 @@ import { NaturalPersonUseCases } from 'app/useCases/NaturalPersoUseCases/Natural import { OwnDriverUseCases } from 'app/useCases/OwnDriverUseCases/OwnDriverUseCases'; import { UserUseCases } from 'app/useCases/user/UserCases'; -import { OwnDriverWhereArgs } from 'infra/graphql/entities/OwnDriverGraphql/Args/WhereOwnDriverArgs'; +import { + OwnDriverCountArgs, + OwnDriverWhereArgs, +} from 'infra/graphql/entities/OwnDriverGraphql/Args/WhereOwnDriverArgs'; import { AcessAllowed } from 'infra/graphql/utilities/decorators/AcessAllowed'; import { CurrentUser } from 'infra/graphql/utilities/decorators/CurrentUser'; import { RoleInterceptor } from 'infra/graphql/utilities/interceptors/RoleInterceptor'; @@ -23,7 +26,11 @@ import { GraphQLAuthGuard } from 'infra/guard/GraphQlAuthGuard'; import { NaturalPersonModel } from '../NaturalPersonGraphql/NaturalPerson.model'; import { UserModelRefereces } from '../UserGraphql/user.model'; import { GetOwnDriverArgs } from './Args/GetOwnDriverArgs'; -import { OwnDriverInput, OwnDriverUpdate } from './OwnDriver.input'; +import { + OwnDriverInput, + OwnDriverUpdate, + OwnDriverUpdateManyInput, +} from './OwnDriver.input'; import { OwnDriverModel } from './OwnDriver.model'; @UseGuards(GraphQLAuthGuard) @@ -36,14 +43,49 @@ export class OwnDriverResolver { private naturalPersonUseCase: NaturalPersonUseCases, private userCase: UserUseCases, ) {} + + @Query(() => Number) + async totalOwnDrivers(@Args() request: OwnDriverCountArgs) { + const ownDriver = await this.ownDriverUseCase.count(request); + + return ownDriver; + } + + @Mutation(() => [OwnDriverModel]) + async updateManyOwnDrivers( + @Args({ + name: 'updateManyOwnDrivers', + type: () => [OwnDriverUpdateManyInput], + }) + updateOwnDriverInput: OwnDriverUpdateManyInput[], + ) { + return await this.ownDriverUseCase.updateManyOwnDrivers( + updateOwnDriverInput, + ); + } + + @Mutation(() => OwnDriverModel) + async deleteOwnDriver(@Args('id', { type: () => String }) id: string) { + return await this.ownDriverUseCase.deleteOwnDriver(id); + } + + @Mutation(() => [OwnDriverModel]) + async deleteManyOwnDrivers( + @Args({ name: 'deleteManOwnDrivers', type: () => [String] }) ids: string[], + ) { + return await this.ownDriverUseCase.deleteManyOwnDrivers(ids); + } + @Query(() => OwnDriverModel, { nullable: true }) async getOwnDriver(@Args() request: GetOwnDriverArgs) { return await this.ownDriverUseCase.getOwnDriver(request); } + @Query(() => [OwnDriverModel]) async getAllOwnDriver(@Args() args: OwnDriverWhereArgs) { return this.ownDriverUseCase.getAllOwnDriver(args); } + @Mutation(() => OwnDriverModel) async createOwnDriver( @Args('ownDriverInput') ownDriverInput: OwnDriverInput, @@ -54,6 +96,7 @@ export class OwnDriverResolver { return await this.ownDriverUseCase.createOwnDriver(ownDriverInput); } + @Mutation(() => OwnDriverModel) async updateOwnDriver( @Args('id') id: string, @@ -64,12 +107,14 @@ export class OwnDriverResolver { return this.ownDriverUseCase.updateOwnDriver(id, ownDriverUpdate); } + @ResolveField(() => UserModelRefereces) async createdUser(@Parent() user: OwnDriverInput) { const { created_by: createdBy } = user; return await this.userCase.getUser({ id: createdBy }); } + @ResolveField(() => UserModelRefereces) async updatedUser(@Parent() user: OwnDriverInput) { const { updated_by: updatedBy } = user; diff --git a/src/infra/graphql/entities/PhysicalCustomerGraphql/Args/GetPhysicalCustomerWhereArgs.ts b/src/infra/graphql/entities/PhysicalCustomerGraphql/Args/GetPhysicalCustomerWhereArgs.ts index e7fcc1d0..e9d16a91 100644 --- a/src/infra/graphql/entities/PhysicalCustomerGraphql/Args/GetPhysicalCustomerWhereArgs.ts +++ b/src/infra/graphql/entities/PhysicalCustomerGraphql/Args/GetPhysicalCustomerWhereArgs.ts @@ -4,8 +4,7 @@ import { Type } from 'class-transformer'; import { Max, Min, IsOptional } from 'class-validator'; import { PhysicalCustomerOrderByWithRelationInput } from 'infra/graphql/prisma-generated/physical-customer/physical-customer-order-by-with-relation.input'; - -import { OwnDriverWhereInput } from '../../../prisma-generated/own-driver/own-driver-where.input'; +import { PhysicalCustomerWhereInput } from 'infra/graphql/prisma-generated/physical-customer/physical-customer-where.input'; @ArgsType() export class PhysicalCustomerWhereArgs { @@ -20,10 +19,10 @@ export class PhysicalCustomerWhereArgs { @Max(50) limit = 25; - @Field(() => OwnDriverWhereInput, { nullable: true }) - @Type(() => OwnDriverWhereInput) + @Field(() => PhysicalCustomerWhereInput, { nullable: true }) + @Type(() => PhysicalCustomerWhereInput) @IsOptional() - where?: OwnDriverWhereInput; + where?: PhysicalCustomerWhereInput; @Field(() => PhysicalCustomerOrderByWithRelationInput, { nullable: true, @@ -32,3 +31,11 @@ export class PhysicalCustomerWhereArgs { @IsOptional() sort?: PhysicalCustomerOrderByWithRelationInput; } + +@ArgsType() +export class PhysicalCustomerCountArgs { + @Field(() => PhysicalCustomerWhereInput, { nullable: true }) + @Type(() => PhysicalCustomerWhereInput) + @IsOptional() + where?: PhysicalCustomerWhereInput; +} diff --git a/src/infra/graphql/entities/PhysicalCustomerGraphql/PhysicalCustomer.input.ts b/src/infra/graphql/entities/PhysicalCustomerGraphql/PhysicalCustomer.input.ts index 96a6252e..d0112324 100644 --- a/src/infra/graphql/entities/PhysicalCustomerGraphql/PhysicalCustomer.input.ts +++ b/src/infra/graphql/entities/PhysicalCustomerGraphql/PhysicalCustomer.input.ts @@ -6,6 +6,8 @@ import { PartialType, } from '@nestjs/graphql'; +import { IsNotEmpty, IsUUID } from 'class-validator'; + import { type IPhysicalCustomer } from 'domain/entities/PhysicalClientEntities/physicalCustomer/PhysicalCustomer'; import { @@ -41,3 +43,13 @@ export class PhysicalCustomerUpdateInput extends PartialType( NaturalPerson?: NaturalPersonUpdate; updated_by: string; } + +@InputType() +export class PhysicalCustomerUpdateManyInput extends PartialType( + PhysicalCustomerInput, +) { + @Field() + @IsUUID() + @IsNotEmpty() + id: string; +} diff --git a/src/infra/graphql/entities/PhysicalCustomerGraphql/PhysicalCustomer.resolver.ts b/src/infra/graphql/entities/PhysicalCustomerGraphql/PhysicalCustomer.resolver.ts index f12d6701..a4189d62 100644 --- a/src/infra/graphql/entities/PhysicalCustomerGraphql/PhysicalCustomer.resolver.ts +++ b/src/infra/graphql/entities/PhysicalCustomerGraphql/PhysicalCustomer.resolver.ts @@ -22,10 +22,14 @@ import { GraphQLAuthGuard } from 'infra/guard/GraphQlAuthGuard'; import { NaturalPersonModel } from '../NaturalPersonGraphql/NaturalPerson.model'; import { UserModelRefereces } from '../UserGraphql/user.model'; import { GetPhysicalCustomerArgs } from './Args/GetPhysicalCustomerArgs'; -import { PhysicalCustomerWhereArgs } from './Args/GetPhysicalCustomerWhereArgs'; +import { + PhysicalCustomerCountArgs, + PhysicalCustomerWhereArgs, +} from './Args/GetPhysicalCustomerWhereArgs'; import { PhysicalCustomerInput, PhysicalCustomerUpdateInput, + PhysicalCustomerUpdateManyInput, } from './PhysicalCustomer.input'; import { PhysicalCustomerModel } from './PhysicalCustomer.model'; @@ -39,14 +43,23 @@ export class PhysicalCustomerResolver { private userCase: UserUseCases, private naturalPersonUseCase: NaturalPersonUseCases, ) {} + @Query(() => Number) + async totalPhysicalCustomers(@Args() request: PhysicalCustomerCountArgs) { + const physicalCustomer = await this.physicalCustomerUseCase.count(request); + + return physicalCustomer; + } + @Query(() => PhysicalCustomerModel, { nullable: true }) async getPhysicalCustomer(@Args() request: GetPhysicalCustomerArgs) { return await this.physicalCustomerUseCase.getPhysicalCustomer(request); } + @Query(() => [PhysicalCustomerModel]) async getAllPhysicalCustomer(@Args() args: PhysicalCustomerWhereArgs) { return await this.physicalCustomerUseCase.getAllPhysicalCustomer(args); } + @Mutation(() => PhysicalCustomerModel) async createPhysicalCustomer( @Args('data') physicalCustomerInput: PhysicalCustomerInput, @@ -59,6 +72,7 @@ export class PhysicalCustomerResolver { physicalCustomerInput, ); } + @Mutation(() => PhysicalCustomerModel) async updatePhysicalCustomer( @Args('id') id: string, @@ -72,18 +86,47 @@ export class PhysicalCustomerResolver { physicalCustomerInput, ); } + + @Mutation(() => [PhysicalCustomerModel]) + async updateManyPhysicalCustomers( + @Args({ + name: 'updateManyPhysicalCustomers', + type: () => [PhysicalCustomerUpdateManyInput], + }) + updatePhysicalCustomerInput: PhysicalCustomerUpdateManyInput[], + ) { + return await this.physicalCustomerUseCase.updateManyPhysicalCustomers( + updatePhysicalCustomerInput, + ); + } + + @Mutation(() => PhysicalCustomerModel) + async deletePhysicalCustomer(@Args('id', { type: () => String }) id: string) { + return await this.physicalCustomerUseCase.deletePhysicalCustomer(id); + } + + @Mutation(() => [PhysicalCustomerModel]) + async deleteManyPhysicalCustomers( + @Args({ name: 'deleteManyPhysicalCustomers', type: () => [String] }) + ids: string[], + ) { + return await this.physicalCustomerUseCase.deleteManyPhysicalCustomers(ids); + } + @ResolveField(() => UserModelRefereces) async createdUser(@Parent() user: PhysicalCustomerModel) { const { created_by: createdBy } = user; return await this.userCase.getUser({ id: createdBy }); } + @ResolveField(() => UserModelRefereces) async updatedUser(@Parent() user: PhysicalCustomerModel) { const { updated_by: updatedBy } = user; return await this.userCase.getUser({ id: updatedBy }); } + @ResolveField(() => NaturalPersonModel) async NaturalPerson(@Parent() physicalCustomerInput: PhysicalCustomerModel) { return await this.naturalPersonUseCase.getNaturalPerson({ diff --git a/src/infra/graphql/entities/RecipientGraphql/Args/WhereRecipientArgs.ts b/src/infra/graphql/entities/RecipientGraphql/Args/WhereRecipientArgs.ts index a6c96f6d..ae85b224 100644 --- a/src/infra/graphql/entities/RecipientGraphql/Args/WhereRecipientArgs.ts +++ b/src/infra/graphql/entities/RecipientGraphql/Args/WhereRecipientArgs.ts @@ -31,3 +31,11 @@ export class RecipientWhereArgs { @IsOptional() sort?: RecipientOrderByWithRelationInput; } + +@ArgsType() +export class RecipientCountArgs { + @Field(() => RecipientWhereInput, { nullable: true }) + @Type(() => RecipientWhereInput) + @IsOptional() + where?: RecipientWhereInput; +} diff --git a/src/infra/graphql/entities/RecipientGraphql/Recipient.input.ts b/src/infra/graphql/entities/RecipientGraphql/Recipient.input.ts index d5fb576d..5f778b2f 100644 --- a/src/infra/graphql/entities/RecipientGraphql/Recipient.input.ts +++ b/src/infra/graphql/entities/RecipientGraphql/Recipient.input.ts @@ -7,7 +7,14 @@ import { } from '@nestjs/graphql'; import { Type } from 'class-transformer'; -import { Allow, IsObject, IsOptional, IsString } from 'class-validator'; +import { + Allow, + IsNotEmpty, + IsObject, + IsOptional, + IsString, + IsUUID, +} from 'class-validator'; import { type IRecipient } from 'domain/entities/Recipient/Recipient'; @@ -68,3 +75,11 @@ export class RecipientUpdateInput extends PartialType( @Field(() => LegalPersonUpdateInput, { nullable: true }) LegalPerson: LegalPersonUpdateInput; } + +@InputType() +export class RecipientUpdateManyInput extends PartialType(RecipientInput) { + @Field() + @IsUUID() + @IsNotEmpty() + id: string; +} diff --git a/src/infra/graphql/entities/RecipientGraphql/Recipient.resolver.ts b/src/infra/graphql/entities/RecipientGraphql/Recipient.resolver.ts index 3566f7e7..a1a89b98 100644 --- a/src/infra/graphql/entities/RecipientGraphql/Recipient.resolver.ts +++ b/src/infra/graphql/entities/RecipientGraphql/Recipient.resolver.ts @@ -24,8 +24,15 @@ import { LegalPersonModel } from '../LegalPersonGraphql/LegalPerson.model'; import { NaturalPersonModel } from '../NaturalPersonGraphql/NaturalPerson.model'; import { GetRecipientArgs } from '../RecipientGraphql/Args/GetRecipientArgs'; import { UserModelRefereces } from '../UserGraphql/user.model'; -import { RecipientWhereArgs } from './Args/WhereRecipientArgs'; -import { RecipientInput, RecipientUpdateInput } from './Recipient.input'; +import { + RecipientCountArgs, + RecipientWhereArgs, +} from './Args/WhereRecipientArgs'; +import { + RecipientInput, + RecipientUpdateInput, + RecipientUpdateManyInput, +} from './Recipient.input'; import { RecipientModel } from './Recipient.model'; @UseGuards(GraphQLAuthGuard) @@ -39,16 +46,26 @@ export class RecipientResolver { private naturalPersonUseCase: NaturalPersonUseCases, private legalPersonUseCase: LegalPersonUseCases, ) {} + + @Query(() => Number) + async totalRecipients(@Args() request: RecipientCountArgs) { + const recipient = await this.RecipientUseCase.count(request); + + return recipient; + } + @Query(() => RecipientModel) - async getRecient(@Args() request: GetRecipientArgs) { + async getRecipient(@Args() request: GetRecipientArgs) { return this.RecipientUseCase.getRecipient(request); } + @Query(() => [RecipientModel], { nullable: true }) - async getAllRecient(@Args() args: RecipientWhereArgs) { + async getAllRecipient(@Args() args: RecipientWhereArgs) { const recipient = await this.RecipientUseCase.getAllRecipient(args); return recipient.length > 0 ? recipient : null; } + @Mutation(() => RecipientModel) async createRecipient( @Args('data') @@ -60,6 +77,7 @@ export class RecipientResolver { return this.RecipientUseCase.createRecipient(recipientInput); } + @Mutation(() => RecipientModel) async updateRecipient( @Args('id') id: string, @@ -72,6 +90,31 @@ export class RecipientResolver { return this.RecipientUseCase.updateRecipient(id, recipent); } + @Mutation(() => [RecipientModel]) + async updateManyRecipients( + @Args({ + name: 'updateManyRecipients', + type: () => [RecipientUpdateManyInput], + }) + updateRecipientInput: RecipientUpdateManyInput[], + ) { + return await this.RecipientUseCase.updateManyRecipients( + updateRecipientInput, + ); + } + + @Mutation(() => RecipientModel) + async deleteRecipient(@Args('id', { type: () => String }) id: string) { + return await this.RecipientUseCase.deleteRecipient(id); + } + + @Mutation(() => [RecipientModel]) + async deleteManyRecipients( + @Args({ name: 'deleteManyRecipients', type: () => [String] }) ids: string[], + ) { + return await this.RecipientUseCase.deleteManyRecipients(ids); + } + @ResolveField(() => NaturalPersonModel, { nullable: true }) async NaturalPerson(@Parent() recipient: RecipientModel) { if (recipient.natural_person_id) diff --git a/src/infra/graphql/entities/SenderGraphql/Args/WhereSenderArgs.ts b/src/infra/graphql/entities/SenderGraphql/Args/WhereSenderArgs.ts index 8a38f649..4b9fb4c6 100644 --- a/src/infra/graphql/entities/SenderGraphql/Args/WhereSenderArgs.ts +++ b/src/infra/graphql/entities/SenderGraphql/Args/WhereSenderArgs.ts @@ -31,3 +31,11 @@ export class SenderWhereArgs { @IsOptional() sort?: SenderOrderByWithRelationInput; } + +@ArgsType() +export class SenderCountArgs { + @Field(() => SenderWhereInput, { nullable: true }) + @Type(() => SenderWhereInput) + @IsOptional() + where?: SenderWhereInput; +} diff --git a/src/infra/graphql/entities/SenderGraphql/Sender.input.ts b/src/infra/graphql/entities/SenderGraphql/Sender.input.ts index 72e03524..6d99d6cf 100644 --- a/src/infra/graphql/entities/SenderGraphql/Sender.input.ts +++ b/src/infra/graphql/entities/SenderGraphql/Sender.input.ts @@ -7,7 +7,14 @@ import { } from '@nestjs/graphql'; import { Type } from 'class-transformer'; -import { Allow, IsObject, IsOptional, IsString } from 'class-validator'; +import { + Allow, + IsNotEmpty, + IsObject, + IsOptional, + IsString, + IsUUID, +} from 'class-validator'; import { type ISender } from 'domain/entities/Sender/Sender'; @@ -68,3 +75,11 @@ export class SenderUpdateInput extends PartialType( @Field(() => LegalPersonUpdateInput, { nullable: true }) LegalPerson: LegalPersonUpdateInput; } + +@InputType() +export class SenderUpdateManyInput extends PartialType(SenderInput) { + @Field() + @IsUUID() + @IsNotEmpty() + id: string; +} diff --git a/src/infra/graphql/entities/SenderGraphql/Sender.resolver.ts b/src/infra/graphql/entities/SenderGraphql/Sender.resolver.ts index 1e3e3abf..4b09be34 100644 --- a/src/infra/graphql/entities/SenderGraphql/Sender.resolver.ts +++ b/src/infra/graphql/entities/SenderGraphql/Sender.resolver.ts @@ -24,8 +24,12 @@ import { LegalPersonModel } from '../LegalPersonGraphql/LegalPerson.model'; import { NaturalPersonModel } from '../NaturalPersonGraphql/NaturalPerson.model'; import { GetSenderArgs } from '../SenderGraphql/Args/GetSenderArgs'; import { UserModelRefereces } from '../UserGraphql/user.model'; -import { SenderWhereArgs } from './Args/WhereSenderArgs'; -import { SenderInput, SenderUpdateInput } from './Sender.input'; +import { SenderCountArgs, SenderWhereArgs } from './Args/WhereSenderArgs'; +import { + SenderInput, + SenderUpdateInput, + SenderUpdateManyInput, +} from './Sender.input'; import { SenderModel } from './Sender.model'; @UseGuards(GraphQLAuthGuard) @@ -39,16 +43,26 @@ export class SenderResolver { private naturalPersonUseCase: NaturalPersonUseCases, private legalPersonUseCase: LegalPersonUseCases, ) {} + + @Query(() => Number) + async totalSenders(@Args() request: SenderCountArgs) { + const sender = await this.SenderUseCase.count(request); + + return sender; + } + @Query(() => SenderModel) async getSender(@Args() request: GetSenderArgs) { return this.SenderUseCase.getSender(request); } + @Query(() => [SenderModel], { nullable: true }) async getAllSender(@Args() args: SenderWhereArgs) { const sender = await this.SenderUseCase.getAllSender(args); return sender.length > 0 ? sender : null; } + @Mutation(() => SenderModel) async createSender( @Args('data') @@ -60,6 +74,7 @@ export class SenderResolver { return this.SenderUseCase.createSender(senderInput); } + @Mutation(() => SenderModel) async updateSender( @Args('id') id: string, @@ -72,6 +87,29 @@ export class SenderResolver { return this.SenderUseCase.updateSender(id, recipent); } + @Mutation(() => [SenderModel]) + async updateManySenders( + @Args({ + name: 'updateManySenders', + type: () => [SenderUpdateManyInput], + }) + updateSenderInput: SenderUpdateManyInput[], + ) { + return await this.SenderUseCase.updateManySenders(updateSenderInput); + } + + @Mutation(() => SenderModel) + async deleteSender(@Args('id', { type: () => String }) id: string) { + return await this.SenderUseCase.deleteSender(id); + } + + @Mutation(() => [SenderModel]) + async deleteManySenders( + @Args({ name: 'deleteManySenders', type: () => [String] }) ids: string[], + ) { + return await this.SenderUseCase.deleteManySenders(ids); + } + @ResolveField(() => NaturalPersonModel, { nullable: true }) async NaturalPerson(@Parent() sender: SenderModel) { if (sender.natural_person_id) @@ -94,6 +132,7 @@ export class SenderResolver { return await this.userCase.getUser({ id: createdBy }); } + @ResolveField(() => UserModelRefereces) async UpdatedUser(@Parent() user: SenderInput) { const { updated_by: updatedBy } = user; diff --git a/src/infra/graphql/entities/VehicleBrandGraphql/Args/WhereVehicleBrandArgs.ts b/src/infra/graphql/entities/VehicleBrandGraphql/Args/WhereVehicleBrandArgs.ts index 48ec27a2..41b9b539 100644 --- a/src/infra/graphql/entities/VehicleBrandGraphql/Args/WhereVehicleBrandArgs.ts +++ b/src/infra/graphql/entities/VehicleBrandGraphql/Args/WhereVehicleBrandArgs.ts @@ -31,3 +31,11 @@ export class VehicleBrandWhereArgs { @IsOptional() sort?: VehicleBrandOrderByWithRelationInput; } + +@ArgsType() +export class VehicleBrandCountArgs { + @Field(() => VehicleBrandWhereInput, { nullable: true }) + @Type(() => VehicleBrandWhereInput) + @IsOptional() + where?: VehicleBrandWhereInput; +} diff --git a/src/infra/graphql/entities/VehicleBrandGraphql/vehicle-brand.input.ts b/src/infra/graphql/entities/VehicleBrandGraphql/vehicle-brand.input.ts index a0df7a89..e6d08a5b 100644 --- a/src/infra/graphql/entities/VehicleBrandGraphql/vehicle-brand.input.ts +++ b/src/infra/graphql/entities/VehicleBrandGraphql/vehicle-brand.input.ts @@ -1,6 +1,6 @@ import { Field, HideField, InputType, PartialType } from '@nestjs/graphql'; -import { Allow, IsNotEmpty, IsString } from 'class-validator'; +import { Allow, IsNotEmpty, IsString, IsUUID } from 'class-validator'; import { type IVehicleBrand } from 'domain/entities/VehicleEntities/vehicleBrand/VehicleBrand'; @@ -24,3 +24,13 @@ export class VehicleBrandInput export class VehicleBrandUpdateInput extends PartialType(VehicleBrandInput) { updated_by: string; } + +@InputType() +export class VehicleBrandUpdateManyInput extends PartialType( + VehicleBrandInput, +) { + @Field() + @IsUUID() + @IsNotEmpty() + id: string; +} diff --git a/src/infra/graphql/entities/VehicleBrandGraphql/vehicle-brand.resolver.ts b/src/infra/graphql/entities/VehicleBrandGraphql/vehicle-brand.resolver.ts index 4587a6d1..d98719fe 100644 --- a/src/infra/graphql/entities/VehicleBrandGraphql/vehicle-brand.resolver.ts +++ b/src/infra/graphql/entities/VehicleBrandGraphql/vehicle-brand.resolver.ts @@ -13,7 +13,10 @@ import { ROLE, User } from 'domain/entities/User/User'; import { UserUseCases } from 'app/useCases/user/UserCases'; import { VehicleBrandUseCases } from 'app/useCases/VehicleBrandCases/VehicleBrandUseCases'; -import { VehicleBrandWhereArgs } from 'infra/graphql/entities/VehicleBrandGraphql/Args/WhereVehicleBrandArgs'; +import { + VehicleBrandCountArgs, + VehicleBrandWhereArgs, +} from 'infra/graphql/entities/VehicleBrandGraphql/Args/WhereVehicleBrandArgs'; import { AcessAllowed } from 'infra/graphql/utilities/decorators/AcessAllowed'; import { CurrentUser } from 'infra/graphql/utilities/decorators/CurrentUser'; import { RoleInterceptor } from 'infra/graphql/utilities/interceptors/RoleInterceptor'; @@ -23,6 +26,7 @@ import { GetVehicleBrandArgs } from './Args/GetVehicleBrandArgs'; import { VehicleBrandInput, VehicleBrandUpdateInput, + VehicleBrandUpdateManyInput, } from './vehicle-brand.input'; import { VehicleBrandModel } from './vehicle-brand.model'; @@ -36,16 +40,25 @@ export class VehicleBrandResolver { private userCase: UserUseCases, ) {} + @Query(() => Number) + async totalVehicleBrands(@Args() request: VehicleBrandCountArgs) { + const vehicleBrand = await this.vehicleBrandUseCase.count(request); + + return vehicleBrand; + } + @Query(() => VehicleBrandModel) async getVehicleBrand(@Args() request: GetVehicleBrandArgs) { return await this.vehicleBrandUseCase.getVehicleBrand(request); } + @Query(() => [VehicleBrandModel]) async getAllVehicleBrand(@Args() args: VehicleBrandWhereArgs) { const brands = await this.vehicleBrandUseCase.getAllVehicleBrand(args); - return brands.length > 0 ? brands : null; + return brands; } + @Mutation(() => VehicleBrandModel) async createVehicleBrand( @Args('vehicleBrandInput') vehicleBrandInput: VehicleBrandInput, @@ -67,12 +80,40 @@ export class VehicleBrandResolver { return this.vehicleBrandUseCase.updateBrand(id, vehicleBrandUpdate); } + + @Mutation(() => [VehicleBrandModel]) + async updateManyVehicleBrands( + @Args({ + name: 'updateManyVehicleBrands', + type: () => [VehicleBrandUpdateManyInput], + }) + updateVehicleBrandInput: VehicleBrandUpdateManyInput[], + ) { + return await this.vehicleBrandUseCase.updateManyVehicleBrands( + updateVehicleBrandInput, + ); + } + + @Mutation(() => VehicleBrandModel) + async deleteVehicleBrand(@Args('id', { type: () => String }) id: string) { + return await this.vehicleBrandUseCase.deleteVehicleBrand(id); + } + + @Mutation(() => [VehicleBrandModel]) + async deleteManyVehicleBrands( + @Args({ name: 'deleteManyVehicleBrands', type: () => [String] }) + ids: string[], + ) { + return await this.vehicleBrandUseCase.deleteManyVehicleBrands(ids); + } + @ResolveField() async createdUser(@Parent() user: VehicleBrandInput) { const { created_by: createdBy } = user; return await this.userCase.getUser({ id: createdBy }); } + @ResolveField() async updatedUser(@Parent() user: VehicleBrandInput) { const { updated_by: updatedBy } = user; diff --git a/src/infra/graphql/entities/VehicleTypeGraphql/Args/WhereVehicleTypeArgs.ts b/src/infra/graphql/entities/VehicleTypeGraphql/Args/WhereVehicleTypeArgs.ts index 2f86be56..3468a7b9 100644 --- a/src/infra/graphql/entities/VehicleTypeGraphql/Args/WhereVehicleTypeArgs.ts +++ b/src/infra/graphql/entities/VehicleTypeGraphql/Args/WhereVehicleTypeArgs.ts @@ -31,3 +31,11 @@ export class VehicleTypeWhereArgs { @IsOptional() sort?: VehicleTypeOrderByWithRelationInput; } + +@ArgsType() +export class VehicleTypeCountArgs { + @Field(() => VehicleTypeWhereInput, { nullable: true }) + @Type(() => VehicleTypeWhereInput) + @IsOptional() + where?: VehicleTypeWhereInput; +} diff --git a/src/infra/graphql/entities/VehicleTypeGraphql/vehicle-type.input.ts b/src/infra/graphql/entities/VehicleTypeGraphql/vehicle-type.input.ts index 9efb218f..993e3fee 100644 --- a/src/infra/graphql/entities/VehicleTypeGraphql/vehicle-type.input.ts +++ b/src/infra/graphql/entities/VehicleTypeGraphql/vehicle-type.input.ts @@ -13,6 +13,7 @@ import { IsNotEmpty, IsOptional, IsString, + IsUUID, } from 'class-validator'; import { type IVehicleType } from 'domain/entities/VehicleEntities/vehicleTypes/VehicleTypes'; @@ -50,3 +51,11 @@ export class VehicleTypeUpdateInput extends PartialType( @HideField() updated_by: string; } + +@InputType() +export class VehicleTypeUpdateManyInput extends PartialType(VehicleTypeInput) { + @Field() + @IsUUID() + @IsNotEmpty() + id: string; +} diff --git a/src/infra/graphql/entities/VehicleTypeGraphql/vehicle-type.resolver.ts b/src/infra/graphql/entities/VehicleTypeGraphql/vehicle-type.resolver.ts index bc2f9c5c..65c6ba92 100644 --- a/src/infra/graphql/entities/VehicleTypeGraphql/vehicle-type.resolver.ts +++ b/src/infra/graphql/entities/VehicleTypeGraphql/vehicle-type.resolver.ts @@ -15,7 +15,10 @@ import { VehicleBodyworkRepository } from 'domain/repositories/VehicleBodyWorkRe import { UserUseCases } from 'app/useCases/user/UserCases'; import { VehicleTypeUseCases } from 'app/useCases/VehicleTypeUseCases/VehicleTypeUseCases'; -import { VehicleTypeWhereArgs } from 'infra/graphql/entities/VehicleTypeGraphql/Args/WhereVehicleTypeArgs'; +import { + VehicleTypeCountArgs, + VehicleTypeWhereArgs, +} from 'infra/graphql/entities/VehicleTypeGraphql/Args/WhereVehicleTypeArgs'; import { AcessAllowed } from 'infra/graphql/utilities/decorators/AcessAllowed'; import { CurrentUser } from 'infra/graphql/utilities/decorators/CurrentUser'; import { RoleInterceptor } from 'infra/graphql/utilities/interceptors/RoleInterceptor'; @@ -24,7 +27,11 @@ import { GraphQLAuthGuard } from 'infra/guard/GraphQlAuthGuard'; import { UserModelRefereces } from '../UserGraphql/user.model'; import { VehicleBodyworkModel } from '../VehicleBodyworkGraphql/vehicle-bodywork.model'; import { GetVehicleTypeArgs } from './Args/GetVehicleTypeArgs'; -import { VehicleTypeInput, VehicleTypeUpdateInput } from './vehicle-type.input'; +import { + VehicleTypeInput, + VehicleTypeUpdateInput, + VehicleTypeUpdateManyInput, +} from './vehicle-type.input'; import { VehicleTypeModel } from './vehicle-type.model'; @UseGuards(GraphQLAuthGuard) @@ -37,17 +44,25 @@ export class VehicleTypeResolver { private vehicleBodyworkRepository: VehicleBodyworkRepository, private userCase: UserUseCases, ) {} + @Query(() => Number) + async totalVehicleTypes(@Args() request: VehicleTypeCountArgs) { + const vehicleType = await this.vehicleTypeUseCase.count(request); + + return vehicleType; + } @Query(() => VehicleTypeModel) async getVehicleType(@Args() request: GetVehicleTypeArgs) { return this.vehicleTypeUseCase.getVehicleType(request); } + @Query(() => [VehicleTypeModel], { nullable: true }) async getAllVehicleTypes(@Args() args: VehicleTypeWhereArgs) { const vehicleTypes = await this.vehicleTypeUseCase.getAllVehicleType(args); return vehicleTypes; } + @Mutation(() => VehicleTypeModel) async createVehicleType( @Args('vehicleTypeCreate') vehicleTypeInput: VehicleTypeInput, @@ -62,6 +77,7 @@ export class VehicleTypeResolver { return type; } + @Mutation(() => VehicleTypeModel) async updatedVehicleType( @Args('id') id: string, @@ -77,6 +93,32 @@ export class VehicleTypeResolver { return type; } + @Mutation(() => [VehicleTypeModel]) + async updateManyVehicleTypes( + @Args({ + name: 'updateManyVehicleTypes', + type: () => [VehicleTypeUpdateManyInput], + }) + updateVehicleTypeInput: VehicleTypeUpdateManyInput[], + ) { + return await this.vehicleTypeUseCase.updateManyVehicleTypes( + updateVehicleTypeInput, + ); + } + + @Mutation(() => VehicleTypeModel) + async deleteVehicleType(@Args('id', { type: () => String }) id: string) { + return await this.vehicleTypeUseCase.deleteVehicleType(id); + } + + @Mutation(() => [VehicleTypeModel]) + async deleteManyVehicleTypes( + @Args({ name: 'deleteManyVehicleTypes', type: () => [String] }) + ids: string[], + ) { + return await this.vehicleTypeUseCase.deleteManyVehicleTypes(ids); + } + @ResolveField(() => [VehicleBodyworkModel], { nullable: true }) async BodyWorks(@Parent() vehicleTypeInput: VehicleTypeInput) { return await this.vehicleBodyworkRepository.getAllVehicleBodyworkByType({ diff --git a/src/infra/graphql/entities/VeihicleModelGraphql/Args/WhereVeihicleModelArgs.ts b/src/infra/graphql/entities/VeihicleModelGraphql/Args/WhereVeihicleModelArgs.ts index 1b4e51db..903d6572 100644 --- a/src/infra/graphql/entities/VeihicleModelGraphql/Args/WhereVeihicleModelArgs.ts +++ b/src/infra/graphql/entities/VeihicleModelGraphql/Args/WhereVeihicleModelArgs.ts @@ -31,3 +31,10 @@ export class VehicleModelWhereArgs { @IsOptional() sort?: VehicleModelOrderByWithRelationInput; } +@ArgsType() +export class VehicleModelCountArgs { + @Field(() => VehicleModelWhereInput, { nullable: true }) + @Type(() => VehicleModelWhereInput) + @IsOptional() + where?: VehicleModelWhereInput; +} diff --git a/src/infra/graphql/entities/VeihicleModelGraphql/vehicle-model.input.ts b/src/infra/graphql/entities/VeihicleModelGraphql/vehicle-model.input.ts index 7e53f6c4..84b8c9e1 100644 --- a/src/infra/graphql/entities/VeihicleModelGraphql/vehicle-model.input.ts +++ b/src/infra/graphql/entities/VeihicleModelGraphql/vehicle-model.input.ts @@ -14,6 +14,7 @@ import { IsNumber, IsOptional, IsString, + IsUUID, } from 'class-validator'; import { type IVehicleModel } from 'domain/entities/VehicleEntities/vehicleModel/VehicleModel'; @@ -62,3 +63,13 @@ export class VehicleModelInput export class VehicleModelUpdateInput extends PartialType(VehicleModelInput) { updated_by: string; } + +@InputType() +export class VehicleModelUpdateManyInput extends PartialType( + VehicleModelInput, +) { + @Field() + @IsUUID() + @IsNotEmpty() + id: string; +} diff --git a/src/infra/graphql/entities/VeihicleModelGraphql/vehicle-model.resolver.ts b/src/infra/graphql/entities/VeihicleModelGraphql/vehicle-model.resolver.ts index a9ddbe28..90e8e1ae 100644 --- a/src/infra/graphql/entities/VeihicleModelGraphql/vehicle-model.resolver.ts +++ b/src/infra/graphql/entities/VeihicleModelGraphql/vehicle-model.resolver.ts @@ -15,7 +15,10 @@ import { VehicleBrandUseCases } from 'app/useCases/VehicleBrandCases/VehicleBran import { VehicleModelUseCases } from 'app/useCases/VehicleModelUseCases/VehihicleModelUseCases'; import { VehicleTypeUseCases } from 'app/useCases/VehicleTypeUseCases/VehicleTypeUseCases'; -import { VehicleModelWhereArgs } from 'infra/graphql/entities/VeihicleModelGraphql/Args/WhereVeihicleModelArgs'; +import { + VehicleModelCountArgs, + VehicleModelWhereArgs, +} from 'infra/graphql/entities/VeihicleModelGraphql/Args/WhereVeihicleModelArgs'; import { AcessAllowed } from 'infra/graphql/utilities/decorators/AcessAllowed'; import { CurrentUser } from 'infra/graphql/utilities/decorators/CurrentUser'; import { RoleInterceptor } from 'infra/graphql/utilities/interceptors/RoleInterceptor'; @@ -28,6 +31,7 @@ import { GetVehicleModelArgs } from './Args/GetVehicleModelArgs'; import { VehicleModelInput, VehicleModelUpdateInput, + VehicleModelUpdateManyInput, } from './vehicle-model.input'; import { VehicleModelGraphql } from './vehicle-model.model'; @@ -42,16 +46,25 @@ export class VehicleModelResolver { private vehicleTypeUseCase: VehicleTypeUseCases, private vehicleBrandUseCase: VehicleBrandUseCases, ) {} + @Query(() => Number) + async totalVehicleModels(@Args() request: VehicleModelCountArgs) { + const vehicleModel = await this.vehicleModelUseCase.count(request); + + return vehicleModel; + } + @Query(() => VehicleModelGraphql) async getVehicleModel(@Args() request: GetVehicleModelArgs) { return await this.vehicleModelUseCase.getModel(request); } + @Query(() => [VehicleModelGraphql], { nullable: true }) async getAllVehicleModel(@Args() args: VehicleModelWhereArgs) { const models = await this.vehicleModelUseCase.getAllModels(args); return models; } + @Mutation(() => VehicleModelGraphql) async createVehicleModel( @Args('vehicleModelInput') vehicleModelInput: VehicleModelInput, @@ -62,6 +75,7 @@ export class VehicleModelResolver { return await this.vehicleModelUseCase.createModel(vehicleModelInput); } + @Mutation(() => VehicleModelGraphql) async updatedVehicleModel( @Args('id') id: string, @@ -72,24 +86,54 @@ export class VehicleModelResolver { return await this.vehicleModelUseCase.updateModel(id, vehicleModelUpdate); } + + @Mutation(() => [VehicleModelGraphql]) + async updateManyVehicleModels( + @Args({ + name: 'updateManyVehicleModels', + type: () => [VehicleModelUpdateManyInput], + }) + updateVehicleModelInput: VehicleModelUpdateManyInput[], + ) { + return await this.vehicleModelUseCase.updateManyVehicleModels( + updateVehicleModelInput, + ); + } + + @Mutation(() => VehicleModelGraphql) + async deleteVehicleModel(@Args('id', { type: () => String }) id: string) { + return await this.vehicleModelUseCase.deleteVehicleModel(id); + } + + @Mutation(() => [VehicleModelGraphql]) + async deleteManyVehicleModels( + @Args({ name: 'deleteManyVehicleModels', type: () => [String] }) + ids: string[], + ) { + return await this.vehicleModelUseCase.deleteManyVehicleModels(ids); + } + @ResolveField(() => UserModelRefereces) async CreatedUser(@Parent() user: VehicleModelGraphql) { const { created_by: createdBy } = user; return await this.userCase.getUser({ id: createdBy }); } + @ResolveField(() => UserModelRefereces) async UpdatedUser(@Parent() user: VehicleModelInput) { const { updated_by: updatedBy } = user; return await this.userCase.getUser({ id: updatedBy }); } + @ResolveField(() => VehicleTypeModel) async VehicleType(@Parent() vehicleModel: VehicleModelInput) { const { type_id: typeID } = vehicleModel; return await this.vehicleTypeUseCase.getVehicleType({ id: typeID }); } + @ResolveField(() => VehicleBrandReferences) async VehicleBrand(@Parent() vehicleModel: VehicleModelInput) { const { brand_id: brandId } = vehicleModel; diff --git a/src/infra/graphql/generated/schema.gql b/src/infra/graphql/generated/schema.gql index fedafffa..497a3273 100644 --- a/src/infra/graphql/generated/schema.gql +++ b/src/infra/graphql/generated/schema.gql @@ -1047,6 +1047,13 @@ input LegalClientUpdateInput { legal_person_id: String } +input LegalClientUpdateManyInput { + LegalPerson: LegalPersonInput + branch: String + id: String! + legal_person_id: String +} + input LegalClientWhereInput { AND: [LegalClientWhereInput!] CreatedBy: UserWhereInput @@ -1462,6 +1469,7 @@ type Mutation { deleteIcms(id: String!): IcmsModel! deleteIncident(id: String!): IncidentModel! deleteLegalClientOrder(id: String!): LegalClientOrderModel! + deleteLegalClient(id: String!): LegalClientModel! deleteLegalClientQuoteTable(id: String!): LegalClientQuoteTableModel! deleteLegalContract(id: String!): LegalContractModel! deleteMaintenance(id: String!): MaintenanceModel! @@ -1477,15 +1485,24 @@ type Mutation { deleteManyMaintenance(ids: [String!]!): [MaintenanceModel!]! deleteManyMaintenanceCompany(ids: [String!]!): [MaintenanceCompanyModel!]! deleteManyOrderProcessing(ids: [String!]!): [OrderProcessingModel!]! + deleteManyLegalClients(deleteManyLegalClients: [String!]!): [LegalClientModel!]! + deleteManyOwnDrivers(deleteManOwnDrivers: [String!]!): [OwnDriverModel!]! + deleteManyPhysicalCustomers(deleteManyPhysicalCustomers: [String!]!): [PhysicalCustomerModel!]! + deleteManyRecipients(deleteManyRecipients: [String!]!): [RecipientModel!]! + deleteManySenders(deleteManySenders: [String!]!): [SenderModel!]! deleteManyUsers(deleteManyUsers: [String!]!): [UserModel!]! deleteOrderProcessing(id: String!): OrderProcessingModel! deleteUser(id: String!): UserModel! + deleteVehicleBrand(id: String!): VehicleBrandModel! + deleteVehicleModel(id: String!): VehicleModelGraphql! + deleteVehicleType(id: String!): VehicleTypeModel! login(loginData: AuthInput!): AuthModel! updateCarriercompany(data: CarrierCompanyUpdateInput!, id: String!): CarrierCompanyModel! updateCompletedOrders(data: CompletedOrdersUpdateInput!, id: String!): CompletedOrdersModel! updateFreightExpense(id: String!, upData: FreightExpenseUpdateInput!): FreightExpenseModel! updateIcms(id: String!, invoiceForLegalClientInput: IcmsUpdateInput!): IcmsModel! updateIncident(id: String!, upData: IncidentUpdateInput!): IncidentModel! + updateLegalClient(id: String!, legalclientInput: LegalClientUpdateInput!): LegalClientModel! updateLegalClientCte(id: String!, ownDriverUpdate: LegalClientCteUpdateInput!): LegalClientCteModel! updateLegalClientQuoteTable(id: String!, legalClientQuoteTableUpdate: LegalClientQuoteTableUpdate!): LegalClientQuoteTableModel! updateMaintenance(data: MaintenanceUpdateInput!, id: String!): MaintenanceModel! @@ -1501,6 +1518,9 @@ type Mutation { updateManyMaintenanceCompany(data: [MaintenanceCompanyUpdateManyInput!]!): [MaintenanceCompanyModel!]! updateManyOrderProcessing(data: [OrderProcessingUpdateManyInput!]!): [OrderProcessingModel!]! updateManyUsers(updateManyUsers: [UserUpdateManyInput!]!): [UserModel!]! + updateManyVehicleBrands(updateManyVehicleBrands: [VehicleBrandUpdateManyInput!]!): [VehicleBrandModel!]! + updateManyVehicleModels(updateManyVehicleModels: [VehicleModelUpdateManyInput!]!): [VehicleModelGraphql!]! + updateManyVehicleTypes(updateManyVehicleTypes: [VehicleTypeUpdateManyInput!]!): [VehicleTypeModel!]! updateOrderProcessing(data: OrderProcessingUpdateInput!, id: String!): OrderProcessingModel! updateOutsourcedDriver(id: String!, outsourcedDriver: OutsourcedDriverUpdateInput!): OutsourcedDriverModel! updateOwnDriver(id: String!, ownDriverUpdate: OwnDriverUpdate!): OwnDriverModel! @@ -1522,7 +1542,6 @@ type Mutation { updatedVehicleType(id: String!, vehicleTypeInput: VehicleTypeUpdateInput!): VehicleTypeModel! updatelegalClientOrder(id: String!, legalClientOrderInput: LegalClientOrderUpdateInput!): LegalClientOrderModel! updatelegalContract(id: String!, legalContractInput: LegalContractUpdateInput!): LegalContractModel! - updatelegalclient(id: String!, legalclientInput: LegalClientUpdateInput!): LegalClientModel! updateoutsourcedTransportCompany(data: OutsourcedTransportCompanyUpdateInput!, id: String!): OutsourcedTransportCompanyModel! updateoutsourcedTransportCompanyContract(id: String!, outsourcedTransportCompanyContractInput: OutsourcedTransportCompanyContractUpdateInput!): OutsourcedTransportCompanyContractModel! updateoutsourcedTransportCompanyDriver(data: OutsourcedTransportCompanyDriverUpdateInput!, id: String!): OutsourcedTransportCompanyDriverModel! @@ -2355,6 +2374,17 @@ input OwnDriverUpdate { course_mopp: Boolean } +input OwnDriverUpdateManyInput { + NaturalPerson: NaturalPersonInput + cnh: String + cnh_category: String + cnh_expiration: Timestamp + company_vehicle: Boolean + course_mopp: Boolean + id: String! + natural_person_id: String +} + input OwnDriverWhereInput { AND: [OwnDriverWhereInput!] CreatedBy: UserWhereInput @@ -2670,6 +2700,13 @@ input PhysicalCustomerUpdateInput { natural_person_id: String } +input PhysicalCustomerUpdateManyInput { + NaturalPerson: NaturalPersonInput + branch: String + id: String! + natural_person_id: String +} + input PhysicalCustomerWhereInput { AND: [PhysicalCustomerWhereInput!] CreatedBy: UserWhereInput @@ -2722,11 +2759,11 @@ type Query { getAllOutsourcedTransportVehicle(limit: Int! = 25, offset: Int! = 0, sort: OutsourcedTransportVehicleOrderByWithRelationInput, where: OutsourcedTransportVehicleWhereInput): [OutsourcedTransportVehicleModel!] getAllOutsourcedVehicle(limit: Int! = 25, offset: Int! = 0, sort: OutsourcedTransportVehicleOrderByWithRelationInput, where: OutsourcedTransportVehicleWhereInput): [OutsourcedVehicleIModel!]! getAllOwnDriver(limit: Int! = 25, offset: Int! = 0, sort: OwnDriverOrderByWithRelationInput, where: OwnDriverWhereInput): [OwnDriverModel!]! - getAllPhysicalCustomer(limit: Int! = 25, offset: Int! = 0, sort: PhysicalCustomerOrderByWithRelationInput, where: OwnDriverWhereInput): [PhysicalCustomerModel!]! + getAllPhysicalCustomer(limit: Int! = 25, offset: Int! = 0, sort: PhysicalCustomerOrderByWithRelationInput, where: PhysicalCustomerWhereInput): [PhysicalCustomerModel!]! getAllPhysicalCustomerCte(limit: Int! = 25, offset: Int! = 0, sort: PhysicalCustomerCteOrderByWithRelationInput, where: OwnDriverWhereInput): [PhysicalCustomerCteModel!]! getAllPhysicalCustomerOrder(limit: Int! = 25, offset: Int! = 0, sort: PhysicalCustomerOrderOrderByWithRelationInput, where: PhysicalCustomerOrderWhereInput): [PhysicalCustomerOrderModel!] getAllPhysicalCustomerQuoteTable(limit: Int! = 25, offset: Int! = 0, sort: PhysicalCustomerQuoteTableOrderByWithRelationInput, where: PhysicalCustomerQuoteTableWhereInput): [PhysicalCustomerQuoteTableModel!]! - getAllRecient(limit: Int! = 25, offset: Int! = 0, sort: RecipientOrderByWithRelationInput, where: RecipientWhereInput): [RecipientModel!] + getAllRecipient(limit: Int! = 25, offset: Int! = 0, sort: RecipientOrderByWithRelationInput, where: RecipientWhereInput): [RecipientModel!] getAllSender(limit: Int! = 25, offset: Int! = 0, sort: SenderOrderByWithRelationInput, where: SenderWhereInput): [SenderModel!] getAllTypeOfMaintenance(limit: Int! = 25, offset: Int! = 0, sort: TypeOfMaintenanceOrderByWithRelationInput, where: TypeOfMaintenanceWhereInput): [TypeOfMaintenanceModel!] getAllVehicleBodywork(limit: Int! = 25, offset: Int! = 0, sort: VehicleBodyworkOrderByWithRelationInput, where: VehicleBodyworkWhereInput): [VehicleBodyworkModel!] @@ -2760,15 +2797,24 @@ type Query { getPhysicalCustomerCte(acessKey: String, cteNumber: String, id: String): PhysicalCustomerCteModel getPhysicalCustomerOrderModel(id: String, order: String): PhysicalCustomerOrderModel getPhysicalCustomerQuoteTable(cod_quote: String, id: String): PhysicalCustomerQuoteTableModel - getRecient(id: String, legalPerson: GetLegalPersonInput, naturalPerson: GetNaturalPersonInput): RecipientModel! + getRecipient(id: String, legalPerson: GetLegalPersonInput, naturalPerson: GetNaturalPersonInput): RecipientModel! getSender(id: String, legalPerson: GetLegalPersonInput, naturalPerson: GetNaturalPersonInput): SenderModel! getTypeOfMaintenance(id: String): TypeOfMaintenanceModel! getVehicleBodyworkModel(id: String, name: String): VehicleBodyworkModel! getVehicleBrand(id: String, name: String): VehicleBrandModel! getVehicleModel(id: String, name: String): VehicleModelGraphql! getVehicleType(id: String, name: String): VehicleTypeModel! + totalCarrierCompanies(where: CarrierCompanyWhereInput): Float! totalContractOutsourcedDriver(where: ContractOutsourcedDriverWhereInput): Float! + totalLegalClients(where: LegalClientWhereInput): Float! + totalOwnDrivers(where: OwnDriverWhereInput): Float! + totalPhysicalCustomers(where: PhysicalCustomerWhereInput): Float! + totalRecipients(where: RecipientWhereInput): Float! + totalSenders(where: SenderWhereInput): Float! totalUsers(where: UserWhereInput): Float! + totalVehicleBrands(where: VehicleBrandWhereInput): Float! + totalVehicleModels(where: VehicleModelWhereInput): Float! + totalVehicleTypes(where: VehicleTypeWhereInput): Float! user(email: String, id: String, username: String): UserModel! users(limit: Int! = 25, offset: Int! = 0, sort: UserOrderByWithRelationInput, where: UserWhereInput): [UserModel!]! } @@ -2828,6 +2874,14 @@ input RecipientUpdateInput { NaturalPerson: NaturalPersonUpdate } +input RecipientUpdateManyInput { + LegalPerson: LegalPersonInput + NaturalPerson: NaturalPersonInput + id: String! + legal_person_id: String + natural_person_id: String +} + input RecipientWhereInput { AND: [RecipientWhereInput!] CreatedBy: UserWhereInput @@ -2897,6 +2951,14 @@ input SenderUpdateInput { NaturalPerson: NaturalPersonUpdate } +input SenderUpdateManyInput { + LegalPerson: LegalPersonInput + NaturalPerson: NaturalPersonInput + id: String! + legal_person_id: String + natural_person_id: String +} + input SenderWhereInput { AND: [SenderWhereInput!] CreatedBy: UserWhereInput @@ -3345,6 +3407,11 @@ input VehicleBrandUpdateInput { name: String } +input VehicleBrandUpdateManyInput { + id: String! + name: String +} + input VehicleBrandWhereInput { AND: [VehicleBrandWhereInput!] CreatedBy: UserWhereInput @@ -3474,6 +3541,17 @@ input VehicleModelUpdateInput { weight: Float } +input VehicleModelUpdateManyInput { + axles: Float + brand_id: String + capacity_max: Float + capacity_per_axle: Int + id: String! + name: String + type_id: String + weight: Float +} + input VehicleModelWhereInput { AND: [VehicleModelWhereInput!] Brand: VehicleBrandWhereInput @@ -3572,6 +3650,13 @@ input VehicleTypeUpdateInput { name: String } +input VehicleTypeUpdateManyInput { + bodyWork: Boolean + body_work_id: [String!] + id: String! + name: String +} + input VehicleTypeWhereInput { AND: [VehicleTypeWhereInput!] CreatedBy: UserWhereInput @@ -3620,4 +3705,4 @@ input VehicleWhereInput { registration: DateTimeFilter renavam: StringFilter year: StringFilter -} \ No newline at end of file +}