예제 #1
0
    def put(self, request, employee_id, format=None):
        companyId = getCompanyIdFrom(request)
        employee = Employee.objects.filter(id=employee_id).first()
        if employee.company_id != getCompanyIdFrom(request):
            return Response(
                {
                    "Success": "false",
                    "error": "Invalid Employee Type"
                },
                status=status.HTTP_401_UNAUTHORIZED)

        serializedData = EmployeeSerializer(data=request.data)
        if serializedData.is_valid():
            data = serializedData.update(data=request.data,
                                         company_id=companyId,
                                         employee_id=employee_id)
            return Response({
                "Success": "true",
                "response": data
            },
                            status=status.HTTP_201_CREATED)
        return Response(
            {
                "Success": "false",
                "errorMessage": "Field validation errors",
                "error": employee.errors
            },
            status=status.HTTP_400_BAD_REQUEST)
예제 #2
0
 def list(self, request):
     companyid = getCompanyIdFrom(request)
     queryset = Employee.objects.filter(company=companyid)
     serializer = EmployeeListSerializer(queryset, many=True)
     return Response({
         "Success": "true",
         "response": serializer.data
     },
                     status=status.HTTP_200_OK)
예제 #3
0
    def get(self, request, employee_id):
        employee = Employee.objects.filter(id=employee_id)
        if employee[0].company_id != getCompanyIdFrom(request):
            return Response({
                "Success": "false",
                "error": "Invalid employee"
            },
                            status=status.HTTP_401_UNAUTHORIZED)

        serializer = EmployeeListSerializer(employee, many=True)
        return Response(serializer.data[0], status=status.HTTP_200_OK)
예제 #4
0
    def list(self, request, employee_typeid):
        employeeType = EmployeeType.objects.filter(id=employee_typeid)
        employeeTypeDetails = EmployeeTypeDetails.objects.filter(
            employeeType=employee_typeid)
        if employeeType[0].company_id != getCompanyIdFrom(request):
            return Response(
                {
                    "Success": "false",
                    "error": "Invalid Employee Type"
                },
                status=status.HTTP_401_UNAUTHORIZED)

        serializer = WageListSerializer(employeeTypeDetails, many=True)
        return Response(serializer.data, status=status.HTTP_200_OK)
예제 #5
0
 def post(self, request, format=None):
     company_id = getCompanyIdFrom(request)
     employeeType = EmployeeSerializer(data=request.data)
     if employeeType.is_valid():
         data = employeeType.save(company_id=company_id)
         return Response({
             "Success": "true",
             "response": data
         },
                         status=status.HTTP_201_CREATED)
     return Response(
         {
             "Success": "false",
             "errorMessage": "Field validation errors",
             "error": employeeType.errors
         },
         status=status.HTTP_400_BAD_REQUEST)
예제 #6
0
 def get(self, request):
     company_id = getCompanyIdFrom(request)
     company = Company.objects.filter(id=company_id)
     serializer = CompanyListSerializer(company, many=True)
     return Response({"Success": "true", "response": serializer.data[0]}, status=status.HTTP_200_OK)