refactor: remove console logs, update SaleInvoicePayload interface, and enhance GoodCategoriesService response mapping
This commit is contained in:
@@ -23,8 +23,6 @@ import { map } from 'rxjs/operators'
|
||||
@Injectable()
|
||||
export class ResponseMappingInterceptor implements NestInterceptor {
|
||||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
||||
console.log('first')
|
||||
|
||||
const http = context.switchToHttp()
|
||||
const response = http.getResponse()
|
||||
const request = http.getRequest()
|
||||
@@ -32,7 +30,6 @@ export class ResponseMappingInterceptor implements NestInterceptor {
|
||||
return next.handle().pipe(
|
||||
map(data => {
|
||||
const statusCode: number = (response as Response)?.statusCode ?? 200
|
||||
console.log(data)
|
||||
|
||||
if (data && typeof data === 'object') {
|
||||
if (Array.isArray((data as any).errors) && statusCode >= 400) {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { GoldKarat } from '../enums/enums'
|
||||
|
||||
export interface SaleInvoicePayload {
|
||||
weight: number
|
||||
karat: keyof typeof GoldKarat
|
||||
wages: number
|
||||
profit: number
|
||||
karat?: keyof typeof GoldKarat
|
||||
wages?: number
|
||||
profit?: number
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ export const ResponseMapper = {
|
||||
},
|
||||
|
||||
single<T>(item: T): MapperWrapper<T> {
|
||||
console.log('asdasdsaasdsa')
|
||||
|
||||
return { __mapped: 'single', data: item }
|
||||
},
|
||||
|
||||
|
||||
+13
-1
@@ -30,7 +30,19 @@ async function bootstrap() {
|
||||
})
|
||||
.build()
|
||||
const documentFactory = () => SwaggerModule.createDocument(app, config)
|
||||
SwaggerModule.setup('swagger', app, documentFactory)
|
||||
SwaggerModule.setup('swagger', app, documentFactory, {
|
||||
swaggerOptions: {
|
||||
persistAuthorization: true,
|
||||
requestInterceptor: req => {
|
||||
const _tokenStorage = localStorage.getItem('authorized')
|
||||
if (_tokenStorage) {
|
||||
const tokenStorage = JSON.parse(_tokenStorage)
|
||||
req.headers['Authorization'] = `Bearer ${tokenStorage?.bearer?.value}`
|
||||
}
|
||||
return req
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// Set API prefix and enable URI versioning so alls routes live under /api/v1/*
|
||||
app.setGlobalPrefix('api')
|
||||
|
||||
@@ -25,9 +25,6 @@ export class JwtAuthGuard implements CanActivate {
|
||||
|
||||
const req = context.switchToHttp().getRequest<IWithJWTPayloadRequest>()
|
||||
|
||||
// Log headers to inspect whether Authorization is present
|
||||
|
||||
// Try token from cookie first, then from Authorization header (Bearer)
|
||||
let token: string | undefined = req.cookies?.accessToken
|
||||
if (!token) {
|
||||
const authHeader = (req.headers.authorization || req.headers.Authorization) as
|
||||
@@ -45,8 +42,6 @@ export class JwtAuthGuard implements CanActivate {
|
||||
secret: process.env.JWT_SECRET || 'secret',
|
||||
})
|
||||
|
||||
console.log(payload)
|
||||
|
||||
if (payload.type !== 'POS')
|
||||
throw new UnauthorizedException('Invalid or expired token')
|
||||
|
||||
|
||||
@@ -7,22 +7,32 @@ import { CreateGoodCategoryDto } from './dto/create-good-category.dto'
|
||||
export class GoodCategoriesService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
async findAll(complex_id: string) {
|
||||
// console.log(account)
|
||||
|
||||
const categories = await this.prisma.goodCategory.findMany({
|
||||
where: {
|
||||
complex_id,
|
||||
},
|
||||
include: {
|
||||
goods: {
|
||||
include: {
|
||||
_count: true,
|
||||
_count: {
|
||||
select: {
|
||||
goods: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
omit: {
|
||||
account_id: true,
|
||||
complex_id: true,
|
||||
},
|
||||
})
|
||||
|
||||
return ResponseMapper.list(categories)
|
||||
return ResponseMapper.list(
|
||||
categories.map(category => {
|
||||
const { _count, ...rest } = category
|
||||
return {
|
||||
...rest,
|
||||
goods_count: Number(_count.goods),
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
findOne(categoryId: string, complex_id: string) {
|
||||
|
||||
@@ -52,7 +52,6 @@ export class GoodsService {
|
||||
},
|
||||
},
|
||||
}
|
||||
console.log(dataToCreate)
|
||||
|
||||
const good = await this.prisma.good.create({
|
||||
data: dataToCreate,
|
||||
@@ -62,7 +61,6 @@ export class GoodsService {
|
||||
deleted_at: true,
|
||||
},
|
||||
})
|
||||
console.log(good)
|
||||
|
||||
return ResponseMapper.create(good)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user