Advertisement
bivacandra

Untitled

Feb 25th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. const asyncHandler = require('../middleware/asyncHandler')
  2. const { assignedproject, features, project, scenarios } = require('../src/models')
  3.  
  4. exports.getTesterStatistic = asyncHandler(async (req, res, next) => {
  5. const testerId = req.user.id
  6.  
  7. const totalAssigned = await assignedproject.findAndCountAll({
  8. where: {
  9. userId: testerId
  10. },
  11. attributes: ['projectId']
  12. })
  13. const projectId = totalAssigned.rows.map(row => row.projectId)
  14.  
  15. const projectTested = await project
  16. .findAll({
  17. where: {
  18. id: projectId,
  19. status: 'TESTED'
  20. },
  21. attributes: ['id']
  22. })
  23. .map(project => project.id)
  24.  
  25. const totalFeature = await features.findAndCountAll({
  26. where: {
  27. projectId: projectTested
  28. },
  29. attributes: ['id']
  30. })
  31. const featureId = totalFeature.rows.map(row => row.id)
  32.  
  33. const totalScenarios = await scenarios.count({
  34. where: {
  35. id: featureId
  36. }
  37. })
  38.  
  39. res.jsend.success({
  40. totalProjects: totalAssigned.count,
  41. totalFeatures: totalFeature.count,
  42. totalScenarios: totalScenarios
  43. })
  44. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement