diff --git a/__mocks__/data.ts b/__mocks__/data.ts index 81226cb..9fc5652 100644 --- a/__mocks__/data.ts +++ b/__mocks__/data.ts @@ -22,6 +22,7 @@ export const dummyKeywords = [ lastUpdated: '2022-11-15T10:49:53.113', added: '2022-11-11T10:01:06.951', position: 19, + volume: 10000, history: { '2022-11-11': 21, '2022-11-12': 24, @@ -45,6 +46,7 @@ export const dummyKeywords = [ lastUpdated: '2022-11-15T10:49:53.119', added: '2022-11-15T10:01:06.951', position: 29, + volume: 1200, history: { '2022-11-11': 33, '2022-11-12': 34, diff --git a/components/common/ChartSlim.tsx b/components/common/ChartSlim.tsx index 3c6dad2..8f126f1 100644 --- a/components/common/ChartSlim.tsx +++ b/components/common/ChartSlim.tsx @@ -36,7 +36,7 @@ const ChartSlim = ({ labels, sreies, noMaxLimit = false }:ChartProps) => { }, }; - return
Update Volume data for all your Tracked Keywords.
+Integrate Google Adwords to get Keyword Ideas & Search Volume.{' '}
diff --git a/database/migrations/1709217223856-add-keyword-volume-field copy.js b/database/migrations/1709217223856-add-keyword-volume-field copy.js new file mode 100644 index 0000000..19b3564 --- /dev/null +++ b/database/migrations/1709217223856-add-keyword-volume-field copy.js @@ -0,0 +1,35 @@ +// Migration: Adds volume field to the keyword table. + +// CLI Migration +module.exports = { + up: async (queryInterface, Sequelize) => { + return queryInterface.sequelize.transaction(async (t) => { + try { + const keywordTableDefinition = await queryInterface.describeTable('keyword'); + if (keywordTableDefinition) { + if (!keywordTableDefinition.volume) { + await queryInterface.addColumn('keyword', 'volume', { + type: Sequelize.DataTypes.STRING, allowNull: false, defaultValue: 0, + }, { transaction: t }); + } + } + } catch (error) { + console.log('error :', error); + } + }); + }, + down: (queryInterface) => { + return queryInterface.sequelize.transaction(async (t) => { + try { + const keywordTableDefinition = await queryInterface.describeTable('keyword'); + if (keywordTableDefinition) { + if (keywordTableDefinition.volume) { + await queryInterface.removeColumn('keyword', 'volume', { transaction: t }); + } + } + } catch (error) { + console.log('error :', error); + } + }); + }, +}; diff --git a/database/models/keyword.ts b/database/models/keyword.ts index 352e8a8..884c304 100644 --- a/database/models/keyword.ts +++ b/database/models/keyword.ts @@ -47,6 +47,9 @@ class Keyword extends Model { @Column({ type: DataType.STRING, allowNull: true, defaultValue: JSON.stringify([]) }) history!: string; + @Column({ type: DataType.INTEGER, allowNull: false, defaultValue: 0 }) + volume!: number; + @Column({ type: DataType.STRING, allowNull: true, defaultValue: JSON.stringify([]) }) url!: string; diff --git a/pages/api/keywords.ts b/pages/api/keywords.ts index 7139e63..a02a317 100644 --- a/pages/api/keywords.ts +++ b/pages/api/keywords.ts @@ -7,6 +7,7 @@ import verifyUser from '../../utils/verifyUser'; import parseKeywords from '../../utils/parseKeywords'; import { integrateKeywordSCData, readLocalSCData } from '../../utils/searchConsole'; import refreshAndUpdateKeywords from '../../utils/refresh'; +import { getKeywordsVolume, updateKeywordsVolumeData } from '../../utils/adwords'; type KeywordsGetResponse = { keywords?: KeywordType[], @@ -103,8 +104,20 @@ const addKeywords = async (req: NextApiRequest, res: NextApiResponse