1.8.2 • Published 3 years ago
@polyflix/x-utils v1.8.2
X Utils
Install
Install the package with the following command :
npm i @polyflix/x-utilsHow to use
This module expose some utilities
Decorators
Get user roles
 get(@IsAdmin(): isAdmin: boolean) {}
 get(@MeRoles(): roles: Role[]) {}
 get(@MeRoles("Admin"): roles: Role[]) {}Get user id
 get(@MeId(): me: string) {}Guards
Allow only specific roles on a route
@Roles(Role.Admin, Role.Contributor)Kafka
Create kafka modules
@Global()
@Module({
    imports: [
        KafkaModule.register({
            useFactory: (configService: ConfigService) => {
                return kafkaConfig(configService.get("kafka"));
            },
            inject: [ConfigService]
        })
    ],
    exports: [KafkaModule]
})Use kafka client
constructor(
    @InjectKafkaClient() private readonly kafkaClient: ClientKafka,
) {}Kafka message
export interface PolyflixKafkaMessage {
  key: string;
  value: {
    trigger: TriggerType;
    payload: any;
  };
}
export interface PolyflixKafkaValue {
  trigger: TriggerType;
  payload: any;
}
this.kafkaClient.emit<string, PolyflixKafkaMessage>(topic, {
  key: video.slug,
  value: {
    trigger: TriggerType.PROCESSING,
    payload: video
  },
});
@EventPattern("polyflix.legacy.video")
video(@Payload("value") message: PolyflixKafkaValue) {
  // TODO
}MinIO
MinIoMessageValue match to the payload of an MinIO event in kafka
@EventPattern("minio.upload")
async process(@Payload("value") message: MinIOMessageValue) { }1.8.2
3 years ago