Skip to content

Commit

Permalink
removed version query param
Browse files Browse the repository at this point in the history
  • Loading branch information
MohanKumarAmbati committed Oct 29, 2024
1 parent 96ced45 commit dd57305
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 51 deletions.
10 changes: 3 additions & 7 deletions services/npm/npm-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,18 @@ export default class NpmBase extends BaseJsonService {
serviceKey: 'npm',
}

static buildRoute(base, { withTag, additionalQueryParamSchema } = {}) {
static buildRoute(base, { withTag } = {}) {
if (withTag) {
return {
base,
pattern: ':scope(@[^/]+)?/:packageName/:tag*',
queryParamSchema: additionalQueryParamSchema
? queryParamSchema.append(additionalQueryParamSchema)
: queryParamSchema,
queryParamSchema,
}
} else {
return {
base,
pattern: ':scope(@[^/]+)?/:packageName',
queryParamSchema: additionalQueryParamSchema
? queryParamSchema.append(additionalQueryParamSchema)
: queryParamSchema,
queryParamSchema,
}
}
}
Expand Down
19 changes: 3 additions & 16 deletions services/npm/npm-last-update.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Joi from 'joi'
import dayjs from 'dayjs'
import { InvalidParameter, pathParam, queryParam } from '../index.js'
import { pathParam, queryParam } from '../index.js'
import { formatDate } from '../text-formatters.js'
import { age as ageColor } from '../color-formatters.js'
import NpmBase, { packageNameDescription } from './npm-base.js'
Expand All @@ -13,17 +13,10 @@ const updateResponseSchema = Joi.object({
.required(),
}).required()

const additionalQueryParamSchema = {
version: Joi.string(),
}

export class NpmLastUpdate extends NpmBase {
static category = 'activity'

static route = this.buildRoute('npm/last-update', {
withTag: false,
additionalQueryParamSchema,
})
static route = this.buildRoute('npm/last-update', { withTag: false })

static openApi = {
'/npm/last-update/{packageName}': {
Expand Down Expand Up @@ -70,13 +63,7 @@ export class NpmLastUpdate extends NpmBase {
schema: updateResponseSchema,
})

const version = queryParams?.version

if (version && !time[version]) {
throw new InvalidParameter({ prettyMessage: 'version not found' })
}

const date = version ? dayjs(time[version]) : dayjs(time.modified)
const date = dayjs(time.modified)

return this.constructor.render({ date })
}
Expand Down
28 changes: 0 additions & 28 deletions services/npm/npm-last-update.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,13 @@ t.create('last update from custom repository (valid scenario)')
message: isFormattedDate,
})

t.create('last updated date based on the version (valid scenario)')
.get('/express.json?version=5.0.0')
.expectBadge({
label: 'last updated',
message: isFormattedDate,
})

t.create('last updated date based on the version (invalid scenario)')
.get('/express.json?version=not-a-version')
.expectBadge({
label: 'last updated',
message: 'version not found',
})

t.create('last update scoped package (valid scenario)')
.get('/@npm/types.json')
.expectBadge({
label: 'last updated',
message: isFormattedDate,
})

t.create('last updated scoped package based on the version (valid scenario)')
.get('/@npm/types.json?version=2.0.0')
.expectBadge({
label: 'last updated',
message: isFormattedDate,
})

t.create('last updated scoped package based on the version (invalid scenario)')
.get('/@npm/types.json?version=not-a-version')
.expectBadge({
label: 'last updated',
message: 'version not found',
})

t.create('last update scoped package (invalid scenario)')
.get('/@not-a-scoped-package/not-a-valid-package.json')
.expectBadge({
Expand Down

0 comments on commit dd57305

Please sign in to comment.