Skip to content

Commit

Permalink
add ratings to api
Browse files Browse the repository at this point in the history
  • Loading branch information
0x7d8 committed Jan 21, 2025
1 parent 694fadf commit a71fef3
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 57 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"name": "api",
"version": "1.4.3",
"version": "1.5.0",
"scripts": {
"build": "rm -rf lib && esbuild `find src \\( -name '*.ts' -o -name '*.tsx' \\)` --platform='node' --sourcemap --ignore-annotations --format='cjs' --target='es2022' --outdir='lib' && esbuild src/index.ts --platform='node' --sourcemap --ignore-annotations --format='cjs' --target='es2022' --outdir='lib' --banner:js='require(\"module-alias\").addAlias(\"@\", __dirname);'",
"kit": "drizzle-kit",
"lint": "tsc",
"dev": "pnpm build && cd lib && NODE_ENV=development node --enable-source-maps index && cd .."
},
"keywords": [],
"author": "",
"license": "ISC",
"author": "0x7d8",
"license": "MIT",
"dependencies": {
"@rjweb/runtime-node": "^1.1.1",
"@rjweb/sentry": "^2.1.5",
"@rjweb/utils": "^1.12.27",
"@sentry/node": "^8.48.0",
"@sentry/node": "^8.50.0",
"ansi-colors": "^4.1.3",
"drizzle-kit": "^0.28.1",
"drizzle-orm": "^0.36.4",
"drizzle-orm": "^0.38.4",
"drizzle-kit": "^0.30.2",
"ioredis": "^5.4.2",
"module-alias": "^2.2.3",
"node-cron": "^3.0.3",
Expand All @@ -26,7 +26,7 @@
"zod": "^3.24.1"
},
"devDependencies": {
"@types/node": "^22.10.6",
"@types/node": "^22.10.7",
"@types/node-cron": "^3.0.11",
"@types/pg": "^8.11.10",
"esbuild": "^0.24.2",
Expand Down
80 changes: 40 additions & 40 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ server.schema('Extension', {
properties: {
url: { type: 'string', format: 'uri' },
price: { type: 'number' },
currency: { type: 'string', enum: Array.from(database.schema.currency) }
}, required: ['url', 'price', 'currency']
currency: { type: 'string', enum: Array.from(database.schema.currency) },
reviews: { type: 'integer' },
rating: { type: 'number' }
}, required: ['url', 'price', 'currency', 'reviews']
}
},

Expand Down
22 changes: 15 additions & 7 deletions src/crontabs/update-prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export default new Crontab()
])

for (const extension of extensions) {
if (!Object.keys(extension.platforms).filter((platform) => platform !== 'GITHUB').length) continue

logger()
.text('Updating Extension Prices of')
.text(extension.name, (c) => c.cyan)
Expand All @@ -44,7 +42,9 @@ export default new Crontab()
platforms.SOURCEXCHANGE = {
url: extension.platforms.SOURCEXCHANGE.url,
price: product.price,
currency: product.currency
currency: product.currency,
reviews: product.review_count,
rating: product.rating_avg || undefined
}
}
}
Expand All @@ -56,16 +56,24 @@ export default new Crontab()
platforms.BUILTBYBIT = {
url: extension.platforms.BUILTBYBIT.url,
price: product.price,
currency: product.currency
currency: product.currency,
reviews: product.review_count,
rating: product.review_average || undefined
}
}
}

if (extension.platforms.GITHUB && (!platforms.GITHUB.price || !platforms.GITHUB.currency || !platforms.GITHUB.reviews)) {
platforms.GITHUB = Object.assign(extension.platforms.GITHUB, {
price: 0,
currency: 'USD',
reviews: 0
})
}

if (JSON.stringify(platforms) !== JSON.stringify(extension.platforms)) {
await ctx.database.write.update(ctx.database.schema.extensions)
.set({
platforms
})
.set({ platforms })
.where(eq(ctx.database.schema.extensions.id, extension.id))
}

Expand Down
2 changes: 2 additions & 0 deletions src/globals/builtbybit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Currency } from "@/schema"
export type BBBProduct = {
price: number
currency: Currency
review_average: number | null
review_count: number
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/globals/sourcexchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export type SXCProduct = {
price: number
currency: Currency
url: string
rating_avg: number | null
review_count: number
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const extensions = pgTable('extensions', {
identifier: varchar('identifier', { length: 63 }).notNull(),
summary: varchar('summary', { length: 255 }).notNull(),

platforms: jsonb('platforms').notNull().$type<Record<Platform, { price: number, currency: Currency, url: string }>>(),
platforms: jsonb('platforms').notNull().$type<Record<Platform, { price: number, currency: Currency, url: string, reviews: number, rating?: number }>>(),
keywords: varchar('keywords', { length: 255 }).array().notNull().default([]),
banner: varchar('banner', { length: 255 }).notNull(),

Expand Down

0 comments on commit a71fef3

Please sign in to comment.