Skip to content

Commit

Permalink
Merge pull request #73 from perimetre/dev
Browse files Browse the repository at this point in the history
Promoting dev
  • Loading branch information
AssisrMatheus authored Mar 3, 2022
2 parents e3d6a97 + 5770a2e commit 0982b84
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ export const env = {
? Number(process.env.MARATHON_SYNC_EMPTY_PAGES_TO_STOP)
: 50,
MARATHON_MEDIA_URI: process.env.MARATHON_MEDIA_URI,
SYNC_AUTH: process.env.SYNC_AUTH
SYNC_AUTH: process.env.SYNC_AUTH,
MARATHON_COLLECTIONS_WHITELIST: process.env.MARATHON_COLLECTIONS_WHITELIST || '',
MARATHON_FINISHES_WHITELIST: process.env.MARATHON_FINISHES_WHITELIST || '',
MARATHON_DRAWER_TYPES_WHITELIST: process.env.MARATHON_DRAWER_TYPES_WHITELIST || ''
};
26 changes: 22 additions & 4 deletions src/services/marathon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export const marathonService = ({ db }: MarathonServiceDependencies) => {
MARATHON_API_LOGIN,
MARATHON_SYNC_PRODUCTS_PER_PAGE,
MARATHON_SYNC_EMPTY_PAGES_TO_STOP,
MARATHON_MEDIA_URI
MARATHON_MEDIA_URI,
MARATHON_COLLECTIONS_WHITELIST,
MARATHON_FINISHES_WHITELIST,
MARATHON_DRAWER_TYPES_WHITELIST
} = env;

const defaultSyncLocale: Locale = 'en';
Expand Down Expand Up @@ -308,10 +311,15 @@ export const marathonService = ({ db }: MarathonServiceDependencies) => {
existingCollections.some((col) => col.slug === collectionEdge?.node?.slug?.trim())
);

const whitelistedSlugs = MARATHON_COLLECTIONS_WHITELIST.split(',').filter((x) => !!x);

// Received collections
const collectionsToCreate = collections.filter(
// Where it DOESN'T exist in the database
(collectionEdge) => !existingCollections.some((col) => col.slug === collectionEdge?.node?.slug?.trim())
(collectionEdge) =>
collectionEdge?.node?.slug?.trim() &&
!existingCollections.some((col) => col.slug === collectionEdge?.node?.slug?.trim()) &&
whitelistedSlugs.includes(collectionEdge.node.slug.trim())
);

for (let i = 0; i < collectionsToUpdate.length; i++) {
Expand Down Expand Up @@ -458,10 +466,15 @@ export const marathonService = ({ db }: MarathonServiceDependencies) => {
existingDrawerTypes.some((type) => type.slug === drawerTypeEdge?.node?.slug?.trim())
);

const whitelistedSlugs = MARATHON_DRAWER_TYPES_WHITELIST.split(',').filter((x) => !!x);

// Received drawer types
const drawerTypesToCreate = drawerTypes.filter(
// Where it DOESN'T exist in the database
(drawerTypeEdge) => !existingDrawerTypes.some((type) => type.slug === drawerTypeEdge?.node?.slug?.trim())
(drawerTypeEdge) =>
drawerTypeEdge?.node?.slug?.trim() &&
!existingDrawerTypes.some((type) => type.slug === drawerTypeEdge?.node?.slug?.trim()) &&
whitelistedSlugs.includes(drawerTypeEdge.node.slug.trim())
);

for (let i = 0; i < drawerTypesToUpdate.length; i++) {
Expand Down Expand Up @@ -604,10 +617,15 @@ export const marathonService = ({ db }: MarathonServiceDependencies) => {
existingFinishes.some((fin) => fin.slug === finishEdge?.node?.slug?.trim())
);

const whitelistedSlugs = MARATHON_FINISHES_WHITELIST.split(',').filter((x) => !!x);

// Received finishes
const finishesToCreate = finishes.filter(
// Where it DOESN'T exist in the database
(finishEdge) => !existingFinishes.some((fin) => fin.slug === finishEdge?.node?.slug?.trim())
(finishEdge) =>
finishEdge?.node?.slug?.trim() &&
!existingFinishes.some((fin) => fin.slug === finishEdge?.node?.slug?.trim()) &&
whitelistedSlugs.includes(finishEdge.node.slug.trim())
);

for (let i = 0; i < finishesToUpdate.length; i++) {
Expand Down

0 comments on commit 0982b84

Please sign in to comment.