Skip to content

Commit

Permalink
feat: fix sync
Browse files Browse the repository at this point in the history
  • Loading branch information
AssisrMatheus committed Jan 29, 2024
1 parent 48340ca commit 2010d85
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions src/services/marathon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
GET_SP_DRAWER_TYPES_LISTING,
GET_SP_FINISH_LISTING
} from './queries';
import fs from 'fs';

type MarathonServiceDependencies = {
db?: PrismaClient;
Expand Down Expand Up @@ -644,9 +645,8 @@ export const marathonService = ({ db }: MarathonServiceDependencies) => {

if (thumbnailUrl) storageSyncQueue.push(thumbnailUrl);

await db.finish.update({
where: { externalId: currentFinish.externalId },
data: {
try {
console.dir({
slug: finishEdge?.node?.slug?.trim(),
thumbnailUrl,
translations:
Expand All @@ -662,8 +662,31 @@ export const marathonService = ({ db }: MarathonServiceDependencies) => {
}
}
: undefined
}
});
});

await db.finish.update({
where: { externalId: currentFinish.externalId },
data: {
slug: finishEdge?.node?.slug?.trim(),
thumbnailUrl,
translations:
translationIds && translationIds.length > 0
? {
update: {
// Theoretically we should only have one id for locale+slug
where: { id: translationIds[0] },
data: {
name: finishEdge?.node?.name?.trim(),
description: finishEdge?.node?.description?.trim()
}
}
}
: undefined
}
});
} catch (ex) {
throw ex;
}

await db.collectionFinishes.deleteMany({ where: { finish: { externalId: currentFinish.externalId } } });
}
Expand Down Expand Up @@ -936,6 +959,18 @@ export const marathonService = ({ db }: MarathonServiceDependencies) => {

const bundleUrl = seed.modules.find((x) => x.partNumber.toLowerCase() === partNumber.toLowerCase())?.bundlePath;

if (!bundleUrl) {
try {
fs.writeFileSync(
path.normalize(__dirname + `./../../../debug/${module.partNumber}.json`),
JSON.stringify(module, null, 2),
{ flag: 'w', encoding: 'utf-8' }
);
} catch {
// Do nothing
}
}

if (!existingProduct && partNumberProduct?.length > 0) {
partNumber = `${partNumber}-${partNumberProduct.length}`;
}
Expand Down

0 comments on commit 2010d85

Please sign in to comment.