use better constants
This commit is contained in:
parent
3819576c35
commit
3a8f76f251
|
@ -1,6 +1,10 @@
|
||||||
// service
|
// service
|
||||||
export const SERVICE_NAME = 'ad';
|
export const SERVICE_NAME = 'ad';
|
||||||
|
|
||||||
|
// grpc
|
||||||
|
export const GRPC_PACKAGE_NAME = 'ad';
|
||||||
|
export const GRPC_SERVICE_NAME = 'AdService';
|
||||||
|
|
||||||
// configuration
|
// configuration
|
||||||
export const SERVICE_CONFIGURATION_SET_QUEUE = 'ad-configuration-set';
|
export const SERVICE_CONFIGURATION_SET_QUEUE = 'ad-configuration-set';
|
||||||
export const SERVICE_CONFIGURATION_DELETE_QUEUE = 'ad-configuration-delete';
|
export const SERVICE_CONFIGURATION_DELETE_QUEUE = 'ad-configuration-delete';
|
||||||
|
@ -8,6 +12,6 @@ export const SERVICE_CONFIGURATION_PROPAGATE_QUEUE =
|
||||||
'ad-configuration-propagate';
|
'ad-configuration-propagate';
|
||||||
|
|
||||||
// health
|
// health
|
||||||
export const HEALTH_SERVICE_NAME = 'health';
|
export const GRPC_HEALTH_PACKAGE_NAME = 'health';
|
||||||
export const HEALTH_AD_REPOSITORY = 'AdRepository';
|
export const HEALTH_AD_REPOSITORY = 'AdRepository';
|
||||||
export const HEALTH_CRITICAL_LOGGING_KEY = 'logging.ad.health.crit';
|
export const HEALTH_CRITICAL_LOGGING_KEY = 'logging.ad.health.crit';
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { NestFactory } from '@nestjs/core';
|
||||||
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
import { HEALTH_SERVICE_NAME, SERVICE_NAME } from './app.constants';
|
import { GRPC_HEALTH_PACKAGE_NAME, GRPC_PACKAGE_NAME } from './app.constants';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
|
@ -12,7 +12,7 @@ async function bootstrap() {
|
||||||
app.connectMicroservice<MicroserviceOptions>({
|
app.connectMicroservice<MicroserviceOptions>({
|
||||||
transport: Transport.GRPC,
|
transport: Transport.GRPC,
|
||||||
options: {
|
options: {
|
||||||
package: [SERVICE_NAME, HEALTH_SERVICE_NAME],
|
package: [GRPC_PACKAGE_NAME, GRPC_HEALTH_PACKAGE_NAME],
|
||||||
protoPath: [
|
protoPath: [
|
||||||
join(__dirname, 'modules/ad/interface/grpc-controllers/ad.proto'),
|
join(__dirname, 'modules/ad/interface/grpc-controllers/ad.proto'),
|
||||||
join(__dirname, 'health.proto'),
|
join(__dirname, 'health.proto'),
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { RpcExceptionCode } from '@mobicoop/ddd-library';
|
||||||
import { RpcValidationPipe } from '@mobicoop/ddd-library';
|
import { RpcValidationPipe } from '@mobicoop/ddd-library';
|
||||||
import { CreateAdCommand } from '@modules/ad/core/application/commands/create-ad/create-ad.command';
|
import { CreateAdCommand } from '@modules/ad/core/application/commands/create-ad/create-ad.command';
|
||||||
import { AdAlreadyExistsException } from '@modules/ad/core/domain/ad.errors';
|
import { AdAlreadyExistsException } from '@modules/ad/core/domain/ad.errors';
|
||||||
|
import { GRPC_SERVICE_NAME } from '@src/app.constants';
|
||||||
|
|
||||||
@UsePipes(
|
@UsePipes(
|
||||||
new RpcValidationPipe({
|
new RpcValidationPipe({
|
||||||
|
@ -19,7 +20,7 @@ import { AdAlreadyExistsException } from '@modules/ad/core/domain/ad.errors';
|
||||||
export class CreateAdGrpcController {
|
export class CreateAdGrpcController {
|
||||||
constructor(private readonly commandBus: CommandBus) {}
|
constructor(private readonly commandBus: CommandBus) {}
|
||||||
|
|
||||||
@GrpcMethod('AdService', 'Create')
|
@GrpcMethod(GRPC_SERVICE_NAME, 'Create')
|
||||||
async create(data: CreateAdRequestDto): Promise<IdResponse> {
|
async create(data: CreateAdRequestDto): Promise<IdResponse> {
|
||||||
try {
|
try {
|
||||||
const aggregateID: AggregateID = await this.commandBus.execute(
|
const aggregateID: AggregateID = await this.commandBus.execute(
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { AdMapper } from '@modules/ad/ad.mapper';
|
||||||
import { NotFoundException } from '@mobicoop/ddd-library';
|
import { NotFoundException } from '@mobicoop/ddd-library';
|
||||||
import { RpcExceptionCode } from '@mobicoop/ddd-library';
|
import { RpcExceptionCode } from '@mobicoop/ddd-library';
|
||||||
import { RpcValidationPipe } from '@mobicoop/ddd-library';
|
import { RpcValidationPipe } from '@mobicoop/ddd-library';
|
||||||
|
import { GRPC_SERVICE_NAME } from '@src/app.constants';
|
||||||
|
|
||||||
@UsePipes(
|
@UsePipes(
|
||||||
new RpcValidationPipe({
|
new RpcValidationPipe({
|
||||||
|
@ -23,7 +24,7 @@ export class FindAdByIdGrpcController {
|
||||||
private readonly queryBus: QueryBus,
|
private readonly queryBus: QueryBus,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@GrpcMethod('AdService', 'FindOneById')
|
@GrpcMethod(GRPC_SERVICE_NAME, 'FindOneById')
|
||||||
async findOnebyId(data: FindAdByIdRequestDto): Promise<AdResponseDto> {
|
async findOnebyId(data: FindAdByIdRequestDto): Promise<AdResponseDto> {
|
||||||
try {
|
try {
|
||||||
const ad: AdEntity = await this.queryBus.execute(
|
const ad: AdEntity = await this.queryBus.execute(
|
||||||
|
|
Loading…
Reference in New Issue