diff --git a/Tsi1.Api/Tsi1.Api/Controllers/SurveyController.cs b/Tsi1.Api/Tsi1.Api/Controllers/SurveyController.cs index 3914c15873a6fa7587ee56df99c8a3382a3917df..c08beda1d7019c39a547846180491dd9b31d2a59 100644 --- a/Tsi1.Api/Tsi1.Api/Controllers/SurveyController.cs +++ b/Tsi1.Api/Tsi1.Api/Controllers/SurveyController.cs @@ -64,15 +64,11 @@ namespace Tsi1.Api.Controllers [Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)] [HttpGet("GetAllGlobalSurveys")] - public async Task<IActionResult> GetAllGlobalSurveys(int tenantId) + public async Task<IActionResult> GetAllGlobalSurveys() { - var userType = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role).Value; - if (userType == UserTypes.FacultyAdmin) - { - tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value); - } - - var result = await _surveyService.GetAllGlobalSurveys(tenantId, userType); + var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value); + + var result = await _surveyService.GetAllGlobalSurveys(tenantId); if (result.HasError) { diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ISurveyService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ISurveyService.cs index 6ec00d5ca09c97b8e7afdc174cfb6a9bfdea0324..8f652ecaef6fc2dd9bdb3eef5369a126b417822d 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ISurveyService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ISurveyService.cs @@ -11,7 +11,7 @@ namespace Tsi1.BusinessLayer.Interfaces { Task<ServiceResult<int>> CreateGlobalSurvey(SurveyCreateDto newSurvey, int tenantId); Task<ServiceResult<bool>> DeleteGlobalSurvey(int surveyId, string userType, int tenantId); - Task<ServiceResult<List<SurveyPreviewDto>>> GetAllGlobalSurveys(int tenantId, string userType); + Task<ServiceResult<List<SurveyPreviewDto>>> GetAllGlobalSurveys(int tenantId); Task<ServiceResult<SurveyDetailDto>> GetMySurvey(int surveyId, int userId); Task<ServiceResult<bool>> Complete(SurveyResponseCreateDto surveyResponse); Task<ServiceResult<List<SurveyResponseDetailDto>>> GetAllResponses(int surveyId, string userType, int tenantId); diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/SurveyService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/SurveyService.cs index c27512f8a380a2c17bb04c268568b1196cbf7797..3f6ba2985c3e4a3978868394898a6276097ef3d9 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Services/SurveyService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/SurveyService.cs @@ -83,25 +83,36 @@ namespace Tsi1.BusinessLayer.Services return result; } - public async Task<ServiceResult<List<SurveyPreviewDto>>> GetAllGlobalSurveys(int tenantId, string userType) + public async Task<ServiceResult<List<SurveyPreviewDto>>> GetAllGlobalSurveys(int tenantId) { var result = new ServiceResult<List<SurveyPreviewDto>>(); var tenant = await _context.Tenants.FirstOrDefaultAsync(x => x.Id == tenantId); - var tenantAdmin = await _context.Tenants.FirstOrDefaultAsync(x => x.Name == TenantAdmin.Name); - if (tenant == null || userType == UserTypes.UdelarAdmin && tenantAdmin.Id == tenantId) + if (tenant == null) { result.HasError = true; result.AddMessage(string.Format(ErrorMessages.TenantDoesNotExist, tenantId)); return result; } - var surveys = await _context.Surveys - .Include(x => x.Tenant) - .Where(x => x.IsGlobal && x.Tenant.Id == tenantId) - .ToListAsync(); + var surveys = new List<Survey>(); + if (tenant.Name == TenantAdmin.Name) + { + surveys = await _context.Surveys + .Include(x => x.Tenant) + .Where(x => x.IsGlobal) + .ToListAsync(); + } + else + { + surveys = await _context.Surveys + .Include(x => x.Tenant) + .Where(x => x.IsGlobal && x.Tenant.Id == tenantId) + .ToListAsync(); + } + result.Data = _mapper.Map<List<SurveyPreviewDto>>(surveys); return result;