fix: fix weight/length/height/width types in updates (#12500)

This commit is contained in:
Pedro Guzman
2025-05-16 10:16:43 +02:00
committed by GitHub
parent 04acc5d219
commit 2affc0d7d9
3 changed files with 34 additions and 0 deletions

View File

@@ -21,6 +21,8 @@ export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory(
) => void,
context: Context = {}
): Promise<InferEntityType<typeof Product>[]> {
updates.forEach((update) => this.correctUpdateDTOTypes(update))
const products = await this.find(
buildQuery({ id: updates.map((p) => p.id) }, { relations: ["*"] }),
context
@@ -80,6 +82,15 @@ export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory(
.filter((product) => product !== undefined)
}
// We should probably fix the column types in the database to avoid this
// It would also match the types in ProductVariant, which are already numbers
protected correctUpdateDTOTypes(update: any) {
update.weight = update.weight?.toString()
update.length = update.length?.toString()
update.height = update.height?.toString()
update.width = update.width?.toString()
}
/**
* In order to be able to have a strict not in categories, and prevent a product
* to be return in the case it also belongs to other categories, we need to