Skip to content

Dev#17

Closed
Powfu2 wants to merge 11 commits into
initialfrom
dev
Closed

Dev#17
Powfu2 wants to merge 11 commits into
initialfrom
dev

Conversation

@Powfu2
Copy link
Copy Markdown
Owner

@Powfu2 Powfu2 commented Apr 29, 2026

Question Answer
Bug fix ✔/✖
New feature ✔/✖
Breaking change ✔/✖
Deprecations ✔/✖
Documentation ✔/✖
Tests added ✔/✖
Chore ✔/✖

Related issues: #XXX , #XXX ...
Closes #XXX ...

Further information:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove boilerplate file

Comment thread src/common/db/data-source.ts Outdated
Comment on lines +5 to +16
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],
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/products/controllers/products.ts Outdated
Comment on lines +21 to +28
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],
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create real metrics

Comment thread src/products/controllers/products.ts Outdated
Comment on lines +37 to +39
return res.json({
message: 'There is no products',
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/products/controllers/products.ts Outdated
import { SERVICES } from '@common/constants';
import { ProductManager } from '../models/products';
import { getProductsQuerySchema } from '../schema/products.schema';
import { ZodError } from 'zod';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need zod.
The passed values are being validated by express-openapi-validator.
So, you may only create the needed types

Comment thread openapi3.yaml Outdated
url: https://opensource.org/licenses/MIT

paths:
/anotherResource:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Comment thread openapi3.yaml
200:
description: OK
description: A JSON array of products
content:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, you return or json array or a message (if length === 0)
The OpenAPI should always correspond to how our API is handling requests.

Comment thread openapi3.yaml
application/json:
schema:
$ref: '#/components/schemas/error'
404:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about 500 status code?

Comment thread openapi3.yaml
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove boilerplate stuff

Comment thread openapi3.yaml
type: array
items:
$ref: '#/components/schemas/Product'
UpdateProduct:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can reference Schemas/Product?

@Powfu2 Powfu2 closed this May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants