Skip to content

Commit c47c70d

Browse files
committed
temp
1 parent 6bf7a80 commit c47c70d

File tree

7 files changed

+19
-0
lines changed

7 files changed

+19
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
Warnings:
3+
4+
- Added the required column `is_public` to the `products` table without a default value. This is not possible if the table is not empty.
5+
6+
*/
7+
-- AlterTable
8+
ALTER TABLE "public"."products" ADD COLUMN "is_public" TEXT NOT NULL;

prisma/schema.prisma

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ model Product {
158158
declaredScore Float? @map("declared_score")
159159
category String
160160
161+
isPublic String? @map("is_public")
162+
161163
// Encrypted string
162164
business String
163165
countryDyeing String @map("country_dyeing")

src/services/validation/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const productAPIValidation = z.object({
3333
gtins: z.array(z.string().regex(/^\d{8}$|^\d{13}$/, "Le code GTIN doit contenir 8 ou 13 chiffres")).min(1),
3434
internalReference: z.string(),
3535
declaredScore: z.number().optional(),
36+
isPublic: z.boolean().optional(),
3637
product: z.enum(productValues),
3738
airTransportRatio: z.number().min(0).max(1).optional(),
3839
upcycled: z.boolean().optional(),

src/services/validation/product.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const productValidation = z.object({
3838
.min(1, "Il doit y avoir au moins un GTIN"),
3939
internalReference: z.string({ message: "La référence interne est obligatoire" }),
4040
declaredScore: z.number().min(1, "Le score doit être un nombre positif").nullable(),
41+
isPublic: z.boolean(),
4142
category: z.enum(ProductCategory, { message: "Catégorie de produit invalide" }),
4243
airTransportRatio: z
4344
.number({ message: "La part de transport aérien doit être un pourcentage" })

src/types/Product.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export type ParsedProduct = {
122122
internalReference: string
123123
brand: string
124124
declaredScore: number | undefined
125+
isPublic: string | undefined
125126
product: ProductCategory
126127
airTransportRatio: string | number | undefined
127128
business: Business

src/utils/csv/parse.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type ColumnType = [
1818
"referenceinterne",
1919
"marque",
2020
"score",
21+
"donneespubliques",
2122
"categorie",
2223
"masse",
2324
"remanufacture",
@@ -165,6 +166,7 @@ const getBooleanValue = (value: string) => {
165166
} else if (simplifiedValue === "non" || simplifiedValue === "no" || simplifiedValue === "false") {
166167
return false
167168
}
169+
168170
return value
169171
}
170172

@@ -239,6 +241,9 @@ export const parseCSV = async (buffer: Buffer, encoding: string | null, upload:
239241
internalReference: row.record["referenceinterne"] || "",
240242
brand: row.record["marque"] || upload.createdBy.organization?.name || "",
241243
declaredScore: getNumberValue(row.record["score"], 1, -1) as number | undefined,
244+
isPublic: row.record["donneespubliques"]
245+
? getBooleanValue(row.record["donneespubliques"])?.toString()
246+
: undefined,
242247
product: getValue<ProductCategory>(productCategories, row.record["categorie"]),
243248
airTransportRatio: getNumberValue(row.record["partdutransportaerien"], 0.01),
244249
business: getValue<Business>(businesses, row.record["tailledelentreprise"]),

src/utils/encryption/encryption.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export function encryptProductFields(product: ProductAPIValidation | ParsedProdu
111111
internalReference: product.internalReference,
112112
brand: product.brand,
113113
declaredScore: product.declaredScore || null,
114+
isPublic: product.isPublic === undefined ? null : product.isPublic.toString(),
114115
category: product.product,
115116
airTransportRatio: encrypt(product.airTransportRatio),
116117
business: encrypt(product.business),

0 commit comments

Comments
 (0)