def get(self, rf, month_id):        
        try:
            # Fetch point by rf
            points = Point.objects(
                Q(date__contains=month_id) & Q(rf=rf)
            ).order_by('date')
            
        except DoesNotExist:
            return resp_does_not_exist('PointServices', 'ponto')

        except FieldDoesNotExist as e:
            return resp_exception('PointServices', description=e.__str__())

        except Exception as e:
            return resp_exception('PointServices', description=e.__str__())

        # It will be auxiliar for changing date
        # Convert string to datetime
        staticDate = datetime.strptime(points.first().date, '%Y-%m-%d').date()
        result = {}
        hoursPerDay = 0
        hoursPerMonth = 0
        for point in range(0, points.count()):
            date = datetime.strptime(
                points[point].date, '%Y-%m-%d'
            ).date()

            if (date != staticDate):
                staticDate = date
                hoursPerDay=0
            
            if point%2 == 0:
                punchIn = datetime.strptime(
                    points[point].time, '%H:%M:%S'
                ).hour
            else:
                punchOut = datetime.strptime(
                    points[point].time, '%H:%M:%S'
                ).hour

            if point%2 == 1:
                hoursPerDay = hoursPerDay + (punchOut-punchIn)
                
                # Take work hours per day,
                # Convert datetime to string
                result["Day " + date.strftime('%Y-%m-%d')] = hoursPerDay
                
                hoursPerMonth = hoursPerMonth + punchOut - punchIn
        
        result["Month " + month_id] = hoursPerMonth
        return resp_ok(
            'ReportService',
            MSG_RESOURCE_FETCHED.format('Relatorio'),
            result
        )
        
Beispiel #2
0
    def get(username):
        schema = UserSchema()
        user = get_user_by_user_name(username)
        if not isinstance(user, User):
            return user

        result = schema.dump(user)

        return resp_ok("Users",
                       MSG_RESOURCE_FETCHED.format("Usuário",
                                                   username), result)
Beispiel #3
0
    def get(self):
        schema = CarSchema(many=True)

        try:
            cars = Car.objects()
            
            result = schema.dump(cars)
            
            return resp_ok('Car', MSG_RESOURCE_FETCHED.format('Cars'), data=result.data)
        except Exception as e:
            return resp_exception('Car', description=e.__str__())
    def get(self, planet_id):
        result = None
        schema = PlanetSchema()

        planet = get_planet_by_id(planet_id)

        result = schema.dump(planet)

        return resp_ok('Planets',
                       MSG_RESOURCE_FETCHED.format('Planets'),
                       data=result.data)
Beispiel #5
0
    def get(self, user_id):
        schema = UserSchema()

        try:
            user = User.objects().get(id=user_id)
        except Exception as e:
            return resp_exception('User', description=e.__str__())

        result = schema.dump(user)

        return resp_ok('User', MSG_RESOURCE_FETCHED.format('usuários'), result.data)
    def get(self, user_id: int) -> dict:

        try:
            query = get_user_by_id(user_id)
            result = UserSchema(many=True).dump(query)

        except Exception:
            return resp_does_not_exist('User', "user")

        return resp_ok('User',
                       MSG_RESOURCE_FETCHED.format('User'),
                       data=result)
    def get(self, rf):
        result = None
        schema = CollaboratorSchema()

        collaborator = get_collaborator_by_rf(rf=rf)

        result = schema.dump(collaborator)

        return resp_ok(
            'ColaboratorServices',
            MSG_RESOURCE_FETCHED.format('Colaborador'),
            data=result.data
        )
    def get(self, user_id):
        result = None
        schema = UserSchema()

        user = get_user_by_id(user_id)

        if not isinstance(user, User):
            return user

        result = schema.dump(user)

        return resp_ok('Users',
                       MSG_RESOURCE_FETCHED.format('Usuários'),
                       data=result.data)
    def get(self, order_id):
        result = None
        schema = OrderSchema()

        order = get_order_by_id(order_id)

        if not isinstance(order, OrderModel):
            return order

        result = schema.dump(order)

        return resp_ok('Order',
                       MSG_RESOURCE_FETCHED.format('Compra'),
                       data=result)
    def get(self, point_id):
        result = None
        schema = PointSchema()

        point = get_point_by_id(point_id=point_id)
        
        if not isinstance(point, Point):
            return point

        result = schema.dump(point)

        return resp_ok(
            'PointServices',
            MSG_RESOURCE_FETCHED.format('Ponto'),
            data=result.data
        )
Beispiel #11
0
    def get(self, user_id):
        result = None
        schema = UserSchema()
        current_user = get_user_by_email(get_jwt_identity())

        if not isinstance(current_user, User):
            return current_user

        if not (current_user.is_active()) and current_user.is_admin():
            return resp_notallowed_user('Users')

        user = get_user_by_id(user_id)

        if not isinstance(user, User):
            return user

        result = schema.dump(user)

        return resp_ok('Users',
                       MSG_RESOURCE_FETCHED.format('Usuários'),
                       data=result.data)