-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
411709: Add in progress filters endpoint
- Add querry params to in-progress endpoint
- Loading branch information
1 parent
8444e79
commit af958fc
Showing
6 changed files
with
123 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Joi from 'joi' | ||
|
||
import { statuses } from '~/src/constants/statuses.js' | ||
import { getStatusFilters } from '~/src/api/status/helpers/get-status-filters.js' | ||
|
||
const inProgressFiltersController = { | ||
options: { | ||
validate: { | ||
query: Joi.object({ | ||
kind: Joi.string().allow('') | ||
}) | ||
} | ||
}, | ||
handler: async (request, h) => { | ||
const filters = await getStatusFilters( | ||
request.db, | ||
[statuses.inProgress, statuses.failure], | ||
request.query | ||
) | ||
|
||
return h.response({ message: 'success', filters }) | ||
} | ||
} | ||
|
||
export { inProgressFiltersController } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import isNil from 'lodash/isNil.js' | ||
|
||
/** | ||
* @param {import('mongodb').Db} db | ||
* @param {string[]} statuses | ||
* @param {Record<string, string>} [queryParams] | ||
* @returns {Promise<*>} | ||
*/ | ||
async function getStatusFilters(db, statuses, queryParams = {}) { | ||
const kind = queryParams.kind | ||
|
||
const stages = [] | ||
|
||
if (!isNil(kind)) { | ||
stages.push({ | ||
$match: { kind } | ||
}) | ||
} | ||
|
||
stages.push( | ||
{ | ||
$match: { status: { $in: statuses } } | ||
}, | ||
{ | ||
$group: { | ||
_id: null, | ||
services: { $addToSet: '$repositoryName' }, | ||
teams: { $addToSet: '$team' } | ||
} | ||
}, | ||
{ | ||
$project: { | ||
_id: 0, | ||
services: 1, | ||
teams: { | ||
teamId: 1, | ||
name: 1 | ||
} | ||
} | ||
} | ||
) | ||
|
||
const filters = await db.collection('status').aggregate(stages).toArray() | ||
return filters.at(0) | ||
} | ||
|
||
export { getStatusFilters } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters