mirror of
https://gitlab.com/mobicoop/v3/service/configuration.git
synced 2026-01-09 16:32:40 +00:00
switch to redis
This commit is contained in:
@@ -5,12 +5,6 @@ export const SERVICE_NAME = 'configuration';
|
||||
export const GRPC_PACKAGE_NAME = 'configuration';
|
||||
export const GRPC_SERVICE_NAME = 'ConfigurationService';
|
||||
|
||||
// messaging
|
||||
export const CONFIGURATION_SET_ROUTING_KEY = 'configuration.set';
|
||||
export const CONFIGURATION_DELETED_ROUTING_KEY = 'configuration.deleted';
|
||||
export const CONFIGURATION_PROPAGATED_ROUTING_KEY = 'configuration.propagated';
|
||||
|
||||
// health
|
||||
export const GRPC_HEALTH_PACKAGE_NAME = 'health';
|
||||
export const HEALTH_CONFIGURATION_REPOSITORY = 'ConfigurationRepository';
|
||||
export const HEALTH_CRITICAL_LOGGING_KEY = 'logging.configuration.health.crit';
|
||||
|
||||
@@ -1,19 +1,10 @@
|
||||
import {
|
||||
HealthModule,
|
||||
HealthModuleOptions,
|
||||
HealthRepositoryPort,
|
||||
} from '@mobicoop/health-module';
|
||||
import { HealthModule, HealthModuleOptions } from '@mobicoop/health-module';
|
||||
import { MessagerModule } from '@modules/messager/messager.module';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import {
|
||||
HEALTH_CONFIGURATION_REPOSITORY,
|
||||
HEALTH_CRITICAL_LOGGING_KEY,
|
||||
SERVICE_NAME,
|
||||
} from './app.constants';
|
||||
import { HEALTH_CRITICAL_LOGGING_KEY, SERVICE_NAME } from './app.constants';
|
||||
import { MessagePublisherPort } from '@mobicoop/ddd-library';
|
||||
import { MESSAGE_PUBLISHER } from '@modules/messager/messager.di-tokens';
|
||||
import { CONFIGURATION_REPOSITORY } from '@modules/configuration/configuration.di-tokens';
|
||||
import { ConfigurationModule } from '@modules/configuration/configuration.module';
|
||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||
import brokerConfig from './config/broker.config';
|
||||
@@ -22,6 +13,7 @@ import paginationConfig from './config/pagination.config';
|
||||
import serviceConfig from './config/service.config';
|
||||
import { RedisModule, RedisModuleOptions } from '@songkeys/nestjs-redis';
|
||||
import redisConfig from './config/redis.config';
|
||||
import { Transport } from '@nestjs/microservices';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -37,21 +29,24 @@ import redisConfig from './config/redis.config';
|
||||
}),
|
||||
EventEmitterModule.forRoot(),
|
||||
HealthModule.forRootAsync({
|
||||
imports: [ConfigurationModule, MessagerModule],
|
||||
inject: [CONFIGURATION_REPOSITORY, MESSAGE_PUBLISHER],
|
||||
imports: [MessagerModule, ConfigModule],
|
||||
inject: [MESSAGE_PUBLISHER, ConfigService],
|
||||
useFactory: async (
|
||||
configurationRepository: HealthRepositoryPort,
|
||||
messagePublisher: MessagePublisherPort,
|
||||
configService: ConfigService,
|
||||
): Promise<HealthModuleOptions> => ({
|
||||
serviceName: SERVICE_NAME,
|
||||
criticalLoggingKey: HEALTH_CRITICAL_LOGGING_KEY,
|
||||
checkRepositories: [
|
||||
messagePublisher,
|
||||
checkMicroservices: [
|
||||
{
|
||||
name: HEALTH_CONFIGURATION_REPOSITORY,
|
||||
repository: configurationRepository,
|
||||
host: configService.get<string>('redis.host') as string,
|
||||
port: configService.get<string>('redis.port') as string,
|
||||
password: configService.get<string>('redis.password'),
|
||||
name: 'Redis',
|
||||
transport: Transport.REDIS,
|
||||
},
|
||||
],
|
||||
messagePublisher,
|
||||
}),
|
||||
}),
|
||||
RedisModule.forRootAsync({
|
||||
|
||||
@@ -1,4 +1 @@
|
||||
export const CONFIGURATION_MESSAGE_PUBLISHER = Symbol(
|
||||
'CONFIGURATION_MESSAGE_PUBLISHER',
|
||||
);
|
||||
export const CONFIGURATION_REPOSITORY = Symbol('CONFIGURATION_REPOSITORY');
|
||||
|
||||
@@ -5,11 +5,7 @@ import { SetConfigurationGrpcController } from './interface/grpc-controllers/set
|
||||
import { SetConfigurationService } from './core/application/commands/set-configuration/set-configuration.service';
|
||||
import { GetConfigurationQueryHandler } from './core/application/queries/get-configuration/get-configuration.query-handler';
|
||||
import { ConfigurationMapper } from './configuration.mapper';
|
||||
import {
|
||||
CONFIGURATION_MESSAGE_PUBLISHER,
|
||||
CONFIGURATION_REPOSITORY,
|
||||
} from './configuration.di-tokens';
|
||||
import { MessageBrokerPublisher } from '@mobicoop/message-broker-module';
|
||||
import { CONFIGURATION_REPOSITORY } from './configuration.di-tokens';
|
||||
import { PopulateService } from './core/application/services/populate.service';
|
||||
import { ConfigurationRepository } from './infrastructure/configuration.repository';
|
||||
|
||||
@@ -33,13 +29,6 @@ const repositories: Provider[] = [
|
||||
},
|
||||
];
|
||||
|
||||
const messagePublishers: Provider[] = [
|
||||
{
|
||||
provide: CONFIGURATION_MESSAGE_PUBLISHER,
|
||||
useExisting: MessageBrokerPublisher,
|
||||
},
|
||||
];
|
||||
|
||||
@Module({
|
||||
imports: [CqrsModule],
|
||||
controllers: [...grpcControllers],
|
||||
@@ -49,7 +38,6 @@ const messagePublishers: Provider[] = [
|
||||
...mappers,
|
||||
...providers,
|
||||
...repositories,
|
||||
...messagePublishers,
|
||||
],
|
||||
exports: [ConfigurationMapper, CONFIGURATION_REPOSITORY],
|
||||
})
|
||||
|
||||
@@ -3,7 +3,6 @@ import { v4 } from 'uuid';
|
||||
import {
|
||||
ConfigurationProps,
|
||||
CreateConfigurationProps,
|
||||
UpdateConfigurationProps,
|
||||
} from './configuration.types';
|
||||
|
||||
export class ConfigurationEntity extends AggregateRoot<ConfigurationProps> {
|
||||
@@ -16,10 +15,6 @@ export class ConfigurationEntity extends AggregateRoot<ConfigurationProps> {
|
||||
return configuration;
|
||||
};
|
||||
|
||||
update(props: UpdateConfigurationProps): void {
|
||||
this.props.value = props.value;
|
||||
}
|
||||
|
||||
validate(): void {
|
||||
// entity business rules validation to protect it's invariant before saving entity to a database
|
||||
}
|
||||
|
||||
@@ -10,10 +10,6 @@ export interface CreateConfigurationProps {
|
||||
value: ConfigurationValue;
|
||||
}
|
||||
|
||||
export interface UpdateConfigurationProps {
|
||||
value: ConfigurationValue;
|
||||
}
|
||||
|
||||
export enum ConfigurationDomain {
|
||||
CARPOOL = 'CARPOOL',
|
||||
PAGINATION = 'PAGINATION',
|
||||
|
||||
@@ -2,7 +2,6 @@ import { ConfigurationEntity } from '@modules/configuration/core/domain/configur
|
||||
import {
|
||||
CreateConfigurationProps,
|
||||
ConfigurationDomain,
|
||||
UpdateConfigurationProps,
|
||||
} from '@modules/configuration/core/domain/configuration.types';
|
||||
|
||||
const createConfigurationProps: CreateConfigurationProps = {
|
||||
@@ -13,10 +12,6 @@ const createConfigurationProps: CreateConfigurationProps = {
|
||||
value: '3',
|
||||
};
|
||||
|
||||
const updateConfigurationProps: UpdateConfigurationProps = {
|
||||
value: '2',
|
||||
};
|
||||
|
||||
describe('Configuration entity create', () => {
|
||||
it('should create a new configuration entity', async () => {
|
||||
const configurationEntity: ConfigurationEntity = ConfigurationEntity.create(
|
||||
@@ -26,13 +21,3 @@ describe('Configuration entity create', () => {
|
||||
expect(configurationEntity.getProps().value).toBe('3');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Configuration entity update', () => {
|
||||
it('should update a configuration entity', async () => {
|
||||
const configurationEntity: ConfigurationEntity = ConfigurationEntity.create(
|
||||
createConfigurationProps,
|
||||
);
|
||||
configurationEntity.update(updateConfigurationProps);
|
||||
expect(configurationEntity.getProps().value).toBe('2');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@ const mockConfigurationMapper = {
|
||||
toDomain: jest.fn().mockImplementation(
|
||||
() =>
|
||||
new ConfigurationEntity({
|
||||
id: ' 001199d4-7187-4e83-a044-12159cba2e33',
|
||||
id: '001199d4-7187-4e83-a044-12159cba2e33',
|
||||
props: {
|
||||
identifier: {
|
||||
domain: ConfigurationDomain.CARPOOL,
|
||||
|
||||
Reference in New Issue
Block a user