Conversation
| export const AppDataSource = new DataSource({ | ||
| type: 'postgres', | ||
| host: 'localhost', | ||
| port: 5432, | ||
| username: 'myuser', | ||
| password: 'mypassword', | ||
| database: 'mydatabase', | ||
| schema: 'public', | ||
| synchronize: true, | ||
| logging: false, | ||
| entities: [ProductEntity], | ||
| }); |
There was a problem hiding this comment.
You need to init the data source using the config values (+ env variables).
We get the values using @map-colonies/config package
See how we create data sources here
| const existingMetric = this.metricsRegistry.getSingleMetric('created_resource'); | ||
| this.createdProductCounter = | ||
| (existingMetric as Counter<string>) ?? | ||
| new Counter({ | ||
| name: 'created_product', | ||
| help: 'number of created products', | ||
| registers: [this.metricsRegistry], | ||
| }); |
| return res.json({ | ||
| message: 'There is no products', | ||
| }); |
There was a problem hiding this comment.
Controller level don't have logic level in it.
In the manager check length === 0 and throw error.
You can create custom HttpErrors -> you set each error with the corresponding error -> when they are being thrown, the server will auth return the correct http code.
cleaner code
see example here
| import { SERVICES } from '@common/constants'; | ||
| import { ProductManager } from '../models/products'; | ||
| import { getProductsQuerySchema } from '../schema/products.schema'; | ||
| import { ZodError } from 'zod'; |
There was a problem hiding this comment.
You don't need zod.
The passed values are being validated by express-openapi-validator.
So, you may only create the needed types
| url: https://opensource.org/licenses/MIT | ||
|
|
||
| paths: | ||
| /anotherResource: |
| 200: | ||
| description: OK | ||
| description: A JSON array of products | ||
| content: |
There was a problem hiding this comment.
Currently, you return or json array or a message (if length === 0)
The OpenAPI should always correspond to how our API is handling requests.
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/error' | ||
| 404: |
| type: array | ||
| items: | ||
| $ref: '#/components/schemas/Product' | ||
| UpdateProduct: |
Related issues: #XXX , #XXX ...
Closes #XXX ...
Further information: