这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: numero string in changes requested #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MaGOs92
Copy link
Contributor

@MaGOs92 MaGOs92 commented Jul 24, 2025

Parfois quand un numéro d'adresse est stocké sous forme de string, on récupère des erreurs 400 sur mes-adresses à la validation du signalement.
Cette PR s'assure que tous les numéros sont des numbers

@MaGOs92 MaGOs92 requested review from fufeck and Copilot July 24, 2025 08:57
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where address numbers stored as strings were causing 400 errors during validation in mes-adresses. The fix ensures all numbers are properly converted to numeric types.

  • Enables class-transformer's automatic type transformation globally by adding transform: true to ValidationPipe
  • Adds explicit number validation and transformation to the NumeroChangesRequestedDTO
  • Includes a database migration to convert existing string numbers to integers in pending signalements

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/main.ts Enables global transformation in ValidationPipe for production
src/tests/*.spec.ts Updates test configurations to match production ValidationPipe settings
src/modules/signalement/dto/changes-requested.dto.ts Adds number validation and transformation decorators to numero field
src/migrations/1753283848477-fix-numero-string-in-changes-requested.ts Migration to convert existing string numbers to integers in database
src/migrations/index.ts Registers the new migration

);

return queryRunner.query(
`UPDATE "signalements" SET "changes_requested" = jsonb_set("changes_requested", '{numero}', '${parseInt(numero, 10)}') WHERE id = '${id}'`,
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

This query is vulnerable to SQL injection. The id variable is interpolated directly into the SQL string without parameterization. Use parameterized queries instead: queryRunner.query('UPDATE "signalements" SET "changes_requested" = jsonb_set("changes_requested", '{numero}', $1) WHERE id = $2', [parseInt(numero, 10), id])

Suggested change
`UPDATE "signalements" SET "changes_requested" = jsonb_set("changes_requested", '{numero}', '${parseInt(numero, 10)}') WHERE id = '${id}'`,
`UPDATE "signalements" SET "changes_requested" = jsonb_set("changes_requested", '{numero}', $1) WHERE id = $2`,
[parseInt(numero, 10), id],

Copilot uses AI. Check for mistakes.

Comment on lines +20 to +21
signalements.map(({ id, changesRequested }) => {
const { numero } = changesRequested as any;
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

Using as any bypasses type safety. Consider defining a proper interface for changesRequested or add proper type checking before destructuring.

Suggested change
signalements.map(({ id, changesRequested }) => {
const { numero } = changesRequested as any;
signalements.map(({ id, changesRequested }: { id: string; changesRequested: ChangesRequested }) => {
const { numero } = changesRequested;

Copilot uses AI. Check for mistakes.

Comment on lines +31 to +32
}
}),
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

The map function returns undefined for signalements that don't need updating, which will be passed to Promise.all. Filter out undefined values or use a different approach: signalements.filter(({changesRequested}) => {...}).map(...) or handle the undefined case explicitly.

Suggested change
}
}),
}),

Copilot uses AI. Check for mistakes.

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.

1 participant