Skip to content

Commit

Permalink
Merge pull request #51 from zulfikarrosadi/fix/error-handling
Browse files Browse the repository at this point in the history
Fix/error handling
  • Loading branch information
zulfikarrosadi authored Nov 21, 2024
2 parents 278960f + b520299 commit 4404506
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"nodemailer": "^6.9.15",
"pino": "^9.5.0",
"pino-http": "^10.3.0",
"swagger-ui-express": "^5.0.1",
"swagger-ui-express": "^4.6.3",
"xss-filters": "^1.2.7",
"zod": "^3.23.8"
},
Expand Down
13 changes: 12 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const app = express()
import swaggerDocument from './openapi.json'
import routes from './routes'

const SWAGGER_CSS_URL =
'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.1.0/swagger-ui.min.css'

const port = process.env.SERVER_PORT

BigInt.prototype.toJSON = function () {
Expand All @@ -18,7 +21,15 @@ app.use(cors())
app.use(express.json())
app.use(cookieParser())
app.use(sanitizeInput)
app.use('/api/docs', swaggerUI.serve, swaggerUI.setup(swaggerDocument))
app.use(
'/api/docs',
swaggerUI.serve,
swaggerUI.setup(swaggerDocument, {
customCssUrl: SWAGGER_CSS_URL,
customCss:
'.swagger-ui .opblock .opblock-summary-path-description-wrapper { align-items: center; display: flex; flex-wrap: wrap; gap: 0 10px; padding: 0 10px; width: 100%; }',
}),
)
app.use('/api/', routes)
app.listen(port, () => {
console.info(`Server running at port ${port}`)
Expand Down
2 changes: 1 addition & 1 deletion src/product/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class ProductRepository {
return products
}

async deleteProductById(id: number) {
async deleteProductById(id: bigint) {
try {
await this.prisma.products.delete({
where: {
Expand Down
3 changes: 2 additions & 1 deletion src/product/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type UpdateProductDataService = {
new: string[]
}
}
export type FlattenUpdateProduct = Omit<UpdateProduct, 'images'> & {
export type FlattenUpdateProduct = Omit<UpdateProduct, 'images' | 'price'> & {
images: string[]
price: number
}
1 change: 1 addition & 0 deletions src/product/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('product service', () => {
createProduct: jest.fn(),
getProductById: jest.fn(),
getProducts: jest.fn(),
deleteProductById: jest.fn(),
} as unknown as jest.Mocked<ProductRepository>

productService = new ProductService(productRepo, logger)
Expand Down

0 comments on commit 4404506

Please # to comment.