nodejs-cofast-package
v0.1.33
Published
:pushpin: **Validate Token**
Downloads
260
Readme
:pushpin: Validate Token
- Cách sử dụng + Wrapper
import { GrpcMetadataInterceptor } from "src/utils.common/utils.interceptor/grpc-metadata.interceptor";
@Controller("users")
@UseInterceptors(GrpcMetadataInterceptor)
...
@Get("/:id")
@UseGuards(UserGuard)
async findOneUser(
@Req() request: RequestWithUser,
@Param("id") id: number,
@Res() res: Response,
@AddGrpcMetadata() metadata: Metadata
) {
return res
.status(HttpStatus.OK)
.send(await this.userService.findOneUser(id, metadata));
}
+ Service
async findOneUser(
request: FindOneUserDTO,
metadata: Metadata,
call: ServerUnaryCall<any, any>
): Promise<any> {
console.log(new UtilsUser(call).getUser());
}
:pushpin: Enum
AccountType
AccountStatus
StoreProcedureStatusEnum
:bangbang: Exception
GrpcExceptionFilter
ExceptionStoreProcedure
ExceptionResponseDetail
:file_folder: Store
StoreProcedureResultOutput
StoreProcedureResult
StoreProcedureOutputResultInterface
StoreProcedureResultInterface
:zap: Utils
UtilsTime
Kafka Log Module
Introduction
This module provides functionality to log messages to Kafka.
Cách dùng
-Đổi tên
KafkaLogModule -> KafkaCofastModule
KafkaLogService -> KafkaCofastService
- Import vào module cần dùng
import { KafkaCofastModule } from 'nodejs-cofast-package/dist/v1';
KafkaCofastModule.register({
client_id: 'my-app-test-1', // có thể sửa
host: process.env.CONFIG_KAFKA_HOST,
port: process.env.CONFIG_KAFKA_PORT,
})
- Khai báo service
private readonly kafkaCofastService: KafkaCofastService
- Send log
export interface ILogActivity {
user_id: number;
log_type: LOG_TYPE_ENUM;
object_id: number;
action_type: ACTION_TYPE_ENUM;
action_detail: string;
json_data_before: string;
json_data_after: string;
platform_type: PLATFORM_TYPE_ENUM;
timestamp: number;
subscription_type: SUBSCRIPTION_TYPE_ENUM;
}
await this.kafkaCofastService.sendLogToKafka(message: ILogActivity);
- send notification
export interface INotification {
recipient_user_id: number;
avatar: string;
image_url: string;
title: string;
content: string;
object_id: number;
object_type: LOG_TYPE_ENUM;
timestamp: number;
}
await this.kafkaCofastService.sendNotificationToKafka(message: INotification);
- KeyRedisGenerate
KeyRedisGenerate.generateKey(REDIS_PREFIX_ENUM.AIR_FREIGHT, request)