import { ValidateDeviceOwnershipQuery } from '@energyweb/origin-backend-core' ; import { IQueryHandler , QueryHandler } from '@nestjs/cqrs' ; import { DeviceService } from '../device.service' ; @ QueryHandler ( ValidateDeviceOwnershipQuery ) export class ValidateDeviceOwnershipCommandHandler implements IQueryHandler < ValidateDeviceOwnershipQuery > { constructor ( private readonly deviceService ) { } public async execute ( { ownerId , externalRegistryId } ) { const device = await this . deviceService . findAll ( { where : { ownerId , id : externalRegistryId } } ) ; return device ?. length === 1 ; } }