38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { CommandHandler } from '@nestjs/cqrs';
|
|
import { TerritoriesRepository } from '../../adapters/secondaries/territories.repository';
|
|
import { Messager } from '../../adapters/secondaries/messager';
|
|
import { DeleteTerritoryCommand } from '../../commands/delete-territory.command';
|
|
import { Territory } from '../entities/territory';
|
|
|
|
@CommandHandler(DeleteTerritoryCommand)
|
|
export class DeleteTerritoryUseCase {
|
|
constructor(
|
|
private readonly _repository: TerritoriesRepository,
|
|
private readonly _messager: Messager,
|
|
) {}
|
|
|
|
async execute(command: DeleteTerritoryCommand): Promise<Territory> {
|
|
try {
|
|
const territory = await this._repository.delete(command.uuid);
|
|
this._messager.publish(
|
|
'territory.delete',
|
|
JSON.stringify({ uuid: territory.uuid }),
|
|
);
|
|
this._messager.publish(
|
|
'logging.territory.delete.info',
|
|
JSON.stringify({ uuid: territory.uuid }),
|
|
);
|
|
return territory;
|
|
} catch (error) {
|
|
this._messager.publish(
|
|
'logging.territory.delete.crit',
|
|
JSON.stringify({
|
|
command,
|
|
error,
|
|
}),
|
|
);
|
|
throw error;
|
|
}
|
|
}
|
|
}
|