Skip to content

Commit

Permalink
feat: add more logging (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsangste authored Sep 12, 2024
1 parent f022a4a commit 709debf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion libs/nestjs-auth/src/middleware/user-decode.middleware.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { Injectable, NestMiddleware } from '@nestjs/common'
import { Inject, Injectable, Logger, LoggerService, NestMiddleware } from '@nestjs/common'

import { NextFunction, Request, Response } from 'express'

@Injectable()
export class UserDecodeMiddleware implements NestMiddleware {
constructor(@Inject(Logger) private readonly logger: LoggerService) {}

use(req: Request, res: Response, next: NextFunction) {
const userData = req.headers['user-data'] as string

if (userData) {
const buffer = Buffer.from(userData, 'base64')
req.user = JSON.parse(buffer.toString('ascii'))

this.logger.debug({ message: 'we have user!', user: req.user })
}

next()
Expand Down
2 changes: 2 additions & 0 deletions libs/nestjs-storage/src/services/storage.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing'
import { Logger } from '@nestjs/common'

import { S3Client } from '@aws-sdk/client-s3'

Expand All @@ -11,6 +12,7 @@ describe('StorageService', () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
StorageService,
Logger,
{
provide: S3Client,
useValue: {}
Expand Down
6 changes: 3 additions & 3 deletions libs/nestjs-storage/src/services/storage.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Injectable } from '@nestjs/common'
import { Inject, Injectable, Logger, LoggerService } from '@nestjs/common'

import { S3Client } from '@aws-sdk/client-s3'

@Injectable()
export class StorageService {
constructor(private readonly s3client: S3Client) {}
constructor(@Inject(Logger) private readonly logger: LoggerService, private readonly s3client: S3Client) {}

upload() {
console.log('upload files!')
this.logger.debug('upload files!')
}
}

0 comments on commit 709debf

Please sign in to comment.