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()
|
@Injectable()
|
||||||
export class ResponseMappingInterceptor implements NestInterceptor {
|
export class ResponseMappingInterceptor implements NestInterceptor {
|
||||||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
||||||
console.log('first')
|
|
||||||
|
|
||||||
const http = context.switchToHttp()
|
const http = context.switchToHttp()
|
||||||
const response = http.getResponse()
|
const response = http.getResponse()
|
||||||
const request = http.getRequest()
|
const request = http.getRequest()
|
||||||
@@ -32,7 +30,6 @@ export class ResponseMappingInterceptor implements NestInterceptor {
|
|||||||
return next.handle().pipe(
|
return next.handle().pipe(
|
||||||
map(data => {
|
map(data => {
|
||||||
const statusCode: number = (response as Response)?.statusCode ?? 200
|
const statusCode: number = (response as Response)?.statusCode ?? 200
|
||||||
console.log(data)
|
|
||||||
|
|
||||||
if (data && typeof data === 'object') {
|
if (data && typeof data === 'object') {
|
||||||
if (Array.isArray((data as any).errors) && statusCode >= 400) {
|
if (Array.isArray((data as any).errors) && statusCode >= 400) {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { GoldKarat } from '../enums/enums'
|
import { GoldKarat } from '../enums/enums'
|
||||||
|
|
||||||
export interface SaleInvoicePayload {
|
export interface SaleInvoicePayload {
|
||||||
weight: number
|
karat?: keyof typeof GoldKarat
|
||||||
karat: keyof typeof GoldKarat
|
wages?: number
|
||||||
wages: number
|
profit?: number
|
||||||
profit: number
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ export const ResponseMapper = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
single<T>(item: T): MapperWrapper<T> {
|
single<T>(item: T): MapperWrapper<T> {
|
||||||
console.log('asdasdsaasdsa')
|
|
||||||
|
|
||||||
return { __mapped: 'single', data: item }
|
return { __mapped: 'single', data: item }
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
+13
-1
@@ -30,7 +30,19 @@ async function bootstrap() {
|
|||||||
})
|
})
|
||||||
.build()
|
.build()
|
||||||
const documentFactory = () => SwaggerModule.createDocument(app, config)
|
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/*
|
// Set API prefix and enable URI versioning so alls routes live under /api/v1/*
|
||||||
app.setGlobalPrefix('api')
|
app.setGlobalPrefix('api')
|
||||||
|
|||||||
@@ -25,9 +25,6 @@ export class JwtAuthGuard implements CanActivate {
|
|||||||
|
|
||||||
const req = context.switchToHttp().getRequest<IWithJWTPayloadRequest>()
|
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
|
let token: string | undefined = req.cookies?.accessToken
|
||||||
if (!token) {
|
if (!token) {
|
||||||
const authHeader = (req.headers.authorization || req.headers.Authorization) as
|
const authHeader = (req.headers.authorization || req.headers.Authorization) as
|
||||||
@@ -45,8 +42,6 @@ export class JwtAuthGuard implements CanActivate {
|
|||||||
secret: process.env.JWT_SECRET || 'secret',
|
secret: process.env.JWT_SECRET || 'secret',
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(payload)
|
|
||||||
|
|
||||||
if (payload.type !== 'POS')
|
if (payload.type !== 'POS')
|
||||||
throw new UnauthorizedException('Invalid or expired token')
|
throw new UnauthorizedException('Invalid or expired token')
|
||||||
|
|
||||||
|
|||||||
@@ -7,22 +7,32 @@ import { CreateGoodCategoryDto } from './dto/create-good-category.dto'
|
|||||||
export class GoodCategoriesService {
|
export class GoodCategoriesService {
|
||||||
constructor(private prisma: PrismaService) {}
|
constructor(private prisma: PrismaService) {}
|
||||||
async findAll(complex_id: string) {
|
async findAll(complex_id: string) {
|
||||||
// console.log(account)
|
|
||||||
|
|
||||||
const categories = await this.prisma.goodCategory.findMany({
|
const categories = await this.prisma.goodCategory.findMany({
|
||||||
where: {
|
where: {
|
||||||
complex_id,
|
complex_id,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
goods: {
|
_count: {
|
||||||
include: {
|
select: {
|
||||||
_count: true,
|
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) {
|
findOne(categoryId: string, complex_id: string) {
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ export class GoodsService {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
console.log(dataToCreate)
|
|
||||||
|
|
||||||
const good = await this.prisma.good.create({
|
const good = await this.prisma.good.create({
|
||||||
data: dataToCreate,
|
data: dataToCreate,
|
||||||
@@ -62,7 +61,6 @@ export class GoodsService {
|
|||||||
deleted_at: true,
|
deleted_at: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
console.log(good)
|
|
||||||
|
|
||||||
return ResponseMapper.create(good)
|
return ResponseMapper.create(good)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user