Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 18, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/utils/__tests__/updateSailthru.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ jest.mock("../../Entities", () => ({ Collection: jest.fn() }))
jest.mock("../../config/database", () => ({ databaseConfig: jest.fn() }))
const pushContent = jest.fn()

jest.mock("../getArtists", () => ({ getArtists: jest.fn() }))
jest.mock("../getArtworks", () => ({ getArtworks: jest.fn() }))
jest.mock("../getArtworks", () => ({
getArtworks: jest.fn().mockReturnValue([[], []]),
}))

jest.mock("sailthru-client", () => ({
createSailthruClient: jest.fn().mockReturnValue({
Expand Down Expand Up @@ -68,6 +69,7 @@ describe("pushContentToSailthru", () => {
// 2nd argument: tags, vars, and images being passed to Sailthru
expect(argumentsForPushToSailthru[2].tags[0]).toEqual("collection")
expect(argumentsForPushToSailthru[2].vars).toEqual({
artworks_slugs: [],
slug: "cat-pictures",
collection_category: "Contemporary",
description: "Wow! Look at those cats!",
Expand Down
17 changes: 0 additions & 17 deletions src/utils/getArtists.ts

This file was deleted.

6 changes: 5 additions & 1 deletion src/utils/getArtworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import metaphysics from "../lib/metaphysics"
export const getArtworks = async (query: string) => {
const results: any = await metaphysics(`${query}`)
let artworkArray
let artistArray
try {
artworkArray = results.marketingCollection.artworks.hits.map(x => x.id)
artistArray = results.marketingCollection.artworks.hits.map(
x => x.artist.id
)
} catch (error) {
throw error
}
return artworkArray
return [artworkArray, artistArray]
}
78 changes: 36 additions & 42 deletions src/utils/updateSailthru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as SailthruAPI from "sailthru-client"
import { Connection, createConnection, getMongoRepository } from "typeorm"
import { databaseConfig } from "../config/database"
import { Collection } from "../Entities"
import { getArtists } from "./getArtists"
import { getArtworks } from "./getArtworks"

const { SAILTHRU_KEY, SAILTHRU_SECRET } = process.env
Expand All @@ -27,51 +26,46 @@ export const pushContentToSailthru = async () => {
const image = collection.headerImage
const body_text = collection.description
const full_url = `https://www.artsy.net/collection/${collection_slug}`
const all_artworks = await getArtworks(
`{marketingCollection(slug: "${collection.slug}") {
artworks {
hits {
id
try {
const [all_artworks, all_artists] = await getArtworks(
`{
marketingCollection(slug: "${collection.slug}") {
artworks {
hits {
id
artist {
id
}
}
}
}
}
}
}`
)
const all_artists = await getArtists(`
{
marketingCollection(slug: "${collection.slug}") {
artworks {
hits {
artist {
id
}
}
}
}
}
`)
}`
)

const options = {
tags: ["collection"].concat(all_artists),
vars: {
slug: collection_slug,
collection_category: featured_names,
description: body_text,
artworks_slugs: all_artworks,
},
images: {
full: {
url: image,
const options = {
tags: ["collection"].concat(all_artists),
vars: {
slug: collection_slug,
collection_category: featured_names,
description: body_text,
artworks_slugs: all_artworks,
},
images: {
full: {
url: image,
},
},
},
}
sailthru.pushContent(name, full_url, options, (err, response) => {
if (err) {
console.log(`Error: ${err}`)
return
}
console.log(`Success: collection ${name} posted`)
})
sailthru.pushContent(name, full_url, options, (err, response) => {
if (err) {
console.log(`Error: ${err}`)
return
}
console.log(`Success: collection ${name} posted`)
})
} catch (e) {
console.log(e)
}
}
} else {
throw new Error("Could not connect to database")
Expand Down