-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(origin-device-registry-irec-form-api): added validate device own…
…ership hander
- Loading branch information
1 parent
6d8a06d
commit e5f123e
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...in-device-registry-irec-form-api/src/device/handlers/validate-device-ownership.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { ValidateDeviceOwnershipQuery } from '@energyweb/origin-backend-core'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { IQueryHandler, QueryHandler } from '@nestjs/cqrs'; | ||
import { DeviceService } from '../device.service'; | ||
|
||
@QueryHandler(ValidateDeviceOwnershipQuery) | ||
export class ValidateDeviceOwnershipQueryHandler | ||
implements IQueryHandler<ValidateDeviceOwnershipQuery> { | ||
private issuerTypeId: string; | ||
|
||
constructor(private readonly deviceService: DeviceService, configService: ConfigService) { | ||
this.issuerTypeId = configService.get<string>('ISSUER_ID'); | ||
} | ||
|
||
public async execute({ | ||
ownerId, | ||
externalRegistryId | ||
}: ValidateDeviceOwnershipQuery): Promise<boolean> { | ||
const device = await this.deviceService.findByExternalId({ | ||
id: externalRegistryId, | ||
type: this.issuerTypeId | ||
}); | ||
|
||
return device?.organizationId === parseInt(ownerId, 10); | ||
} | ||
} |