Git Product home page Git Product logo

helpdesk's Introduction

helpdesk's People

Contributors

bihanviranga avatar dhfernando avatar nishanc avatar

Watchers

 avatar  avatar

helpdesk's Issues

Authentication issues

When we send a request to API, and the request does not contain a token, it returns some big error about a Null Pointer.

If the user is not authenticated, it should simply return a 401 Unauthorized response.

Re-think NULL and NOT NULL fields?

I think some fields are marked as NOT NULL when they aren't necessary. And some necessary fields are marked NULL. Should go over the tables.

Add validation to creation DTOs

Problem

When creating new objects (tickets, companies, anything) and we forget some required fields, it returns a 500 Internal Server Error because validation is not done.

Expected Behaviour

This is not a server error. It is a user error and therefore should return a 400 Bad Request or something.

Steps to reproduce the problem

  • Make a POST request to /ticket endpoint without a required field, such as CompanyId.
  • It will return 500 Internal Server Error

Suggestion

For the fields that cannot be null in the database, add a [Required] annotation in the Create DTO. Then we can do a ModelState.IsValid check in the controller and return BadRequest if false.

Applies to

All Create DTOs.

Using fail first coding Principle

if (userRole == "Manager")

It’s a clean code practice to write to failing part of the code first to make the code cleaner and have less indent

                if (userRole == "Client")
                    return StatusCode(401, "401 Unauthorized  Access");

                if (userRole == "Manager")
                {
                    var modules = await _repository.Module.GetModuleByCondition(userType, userCompanyId);
                    foreach (var module in modules)
                    {
                        var TempModuleDto = _mapper.Map<ModuleDto>(module);
                        if (module.CompanyId != null)
                        {
                            var company = await _repository.Company.GetCompanyById(new Guid(module.CompanyId));
                            if (company != null)
                            {
                                TempModuleDto.CompanyName = company.CompanyName;
                                ModuleList.Add(TempModuleDto);
                            }
                        }
                    }
                    return Ok(ModuleList);
                }
               
                else
                {
                    return StatusCode(500, "Something went wrong");
                }

Method Naming - Better use common names with overloads

public async Task<IEnumerable<ProductModel>> GetProductsByCompanyId(string id)

Better use common names with overloads, so it makes developer who using the contract to use the service easily.

Example:

public async Task<IEnumerable<ProductModel>> GetProductsByCompanyId(string id)
public async Task<IEnumerable<ProductModel>> GetProductsByCondition(string userType, string userCompanyId)

After Refactoring:

public async Task<IEnumerable<ProductModel>> GetProductsAsync(string id)
public async Task<IEnumerable<ProductModel>> GetProductsAsync(string userType, string userCompanyId)

If we could use this type of common method names in all the service contracts, it is easy to use the service, rather having different method names

Error in TicketCode generation

TicketCode field is a char(20) field in the SQL script. But the TicketCode generating code in TicketController does not take this into account.
So when we use a longer company name it throws an error.

How to recreate:

  • Use Helpdesk Company Ltd (or something with similar length, ~20) as company name.
  • Try to create a ticket.

Output:

  • SQL throws a truncation error.
    image

Get rid of hard-coded values

For example, in some places we check whether a user type is "HelpDesk". Ideally, we should use these as constants. So we can say something like UserType=UserTypes.HELPDESK

Reduces the possibility of mistakes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.