@constructorfleet/ultimate-govee
Version:
Library for interacting with Govee devices written in Typescript.
61 lines • 3.29 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var AuthenticateCommandHandler_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthenticateCommandHandler = void 0;
const cqrs_1 = require("@nestjs/cqrs");
const _ultimate_govee_data_1 = require("../../../data");
const iot_channel_config_received_event_1 = require("../../channels/iot/events/iot-channel-config-received.event");
const rest_channel_config_received_event_1 = require("../../channels/rest/events/rest-channel-config-received.event");
const auth_service_1 = require("../auth.service");
const authenticate_command_1 = require("../commands/authenticate.command");
const common_1 = require("@nestjs/common");
let AuthenticateCommandHandler = AuthenticateCommandHandler_1 = class AuthenticateCommandHandler {
constructor(goveeApi, authService, eventBus) {
this.goveeApi = goveeApi;
this.authService = authService;
this.eventBus = eventBus;
this.logger = new common_1.Logger(AuthenticateCommandHandler_1.name);
}
async execute(command) {
const events = [];
const authResult = await this.goveeApi.authenticate(command);
if (authResult.oauth !== undefined) {
const accountAuthData = {
accountId: authResult.accountId,
clientId: authResult.clientId,
oauth: authResult.oauth,
};
this.authService.setAuthData(accountAuthData);
events.push(new rest_channel_config_received_event_1.RestChannelConfigReceivedEvent(authResult));
}
if (authResult.bffOAuth !== undefined) {
const bffAuthData = {
accountId: authResult.accountId,
clientId: authResult.clientId,
oauth: authResult.bffOAuth,
};
this.authService.setCommunityData(bffAuthData);
}
if (authResult.iot !== undefined) {
events.push(new iot_channel_config_received_event_1.IoTChannelConfigReceivedEvent(authResult.iot));
}
this.eventBus.publishAll(events);
}
};
exports.AuthenticateCommandHandler = AuthenticateCommandHandler;
exports.AuthenticateCommandHandler = AuthenticateCommandHandler = AuthenticateCommandHandler_1 = __decorate([
(0, cqrs_1.CommandHandler)(authenticate_command_1.AuthenticateCommand),
__metadata("design:paramtypes", [_ultimate_govee_data_1.GoveeAccountService,
auth_service_1.AuthService,
cqrs_1.EventBus])
], AuthenticateCommandHandler);
//# sourceMappingURL=authenticate.handler.js.map