Skip to content

Commit 2c728d5

Browse files
committed
fix: missing reupload product check on success
1 parent 6bf7a80 commit 2c728d5

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/db/upload.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,17 @@ export const checkUploadsStatus = async (uploadsId: string[]) => {
135135

136136
return Promise.all(
137137
uploads
138-
.filter((upload) =>
139-
upload.products.every((product) => product.status === Status.Done || product.status === Status.Error),
138+
.filter(
139+
(upload) =>
140+
upload.products.every((product) => product.status === Status.Done || product.status === Status.Error) &&
141+
upload.reUploadProducts.every(
142+
(product) => product.product.status === Status.Done || product.product.status === Status.Error,
143+
),
140144
)
141145
.map(async (upload) => {
142-
const allDone = upload.products.every((product) => product.status === Status.Done)
146+
const allDone =
147+
upload.products.every((product) => product.status === Status.Done) &&
148+
upload.reUploadProducts.every((product) => product.product.status === Status.Done)
143149
if (allDone) {
144150
return completeUpload(upload)
145151
} else {

src/scripts/generateCSV.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const generate = (name: string, length?: string) => {
4444
countryMaking: faker.helpers.arrayElement(Object.keys(countries)),
4545
countrySpinning: faker.helpers.arrayElement(Object.keys(countries)),
4646
impressionMapping: faker.helpers.arrayElement(["", ...Object.keys(impressionMapping)]),
47-
impressionPercentage: faker.number.float({ min: 0, max: 1 }),
47+
impressionPercentage: faker.number.float({ min: 0, max: 0.8 }),
4848
mass: faker.number.float({ min: 0.01 }),
4949
price: faker.number.float({ min: 1, max: 1000 }),
5050
airTransportRatio: faker.number.float({ min: 0, max: 1 }),

src/utils/queue/uploads.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import chardet from "chardet"
22
import { parseCSV } from "../csv/parse"
33
import { createProducts } from "../../db/product"
4-
import { completeUpload, failUpload } from "../../services/upload"
5-
import { getFirstFileUpload, updateUploadToPending } from "../../db/upload"
4+
import { failUpload } from "../../services/upload"
5+
import { checkUploadsStatus, getFirstFileUpload, updateUploadToPending } from "../../db/upload"
66
import { downloadFileFromS3 } from "../s3/bucket"
77
import { decryptAndDezipFile } from "../encryption/encryption"
88

@@ -39,7 +39,7 @@ export const processUploadsToQueue = async () => {
3939
const csvData = await parseCSV(buffer, encoding, upload)
4040
const numberOfCreatedProduct = await createProducts(csvData)
4141
if (numberOfCreatedProduct === 0) {
42-
await completeUpload(upload)
42+
await checkUploadsStatus([upload.id])
4343
}
4444
console.log(`Upload processed, ${csvData.products.length} products, ${numberOfCreatedProduct} created`)
4545
} catch (error) {

0 commit comments

Comments
 (0)