Ejemplo n.º 1
0
def delete_job():
    try:
        validated_attr = validate_request_attr(request, ["job_id"])
        current_job = read.get_job_by("id", validated_attr['job_id'])
        delete.delete_job(current_job)
        return Success("JOB_DELETED").asdict()

    except Error as myError:
        return myError.asdict()
Ejemplo n.º 2
0
def toggle_activate_job():
    try:
        validated_attr = validate_request_attr(request, ["job_id"])
        job = read.get_job_by("id", validated_attr["job_id"])
        if job.is_active == False:
            update.update_job(job, "is_active", True)
        else:
            update.update_job(job, "is_active", False)
        return Success("PROFILE_UPDATED").asdict()
    except Error as myError:
        return myError.asdict()
Ejemplo n.º 3
0
def test_get_set_jobs(client, app, login_employer):
    # login
    head = login_employer
    # get jobs
    response = client.post("/api/profile/get_jobs",
                           json={},
                           content_type="application/json",
                           headers=head)
    assert response.json["jobs"][0]["title"] == "myTitle"
    job_id = response.json["jobs"][0]["job_id"]
    # deactivate job
    response = client.post("/api/profile/activate_job",
                           json={},
                           content_type="application/json",
                           headers=head)
    # activate job

    # set_job
    response = client.post("/api/profile/update_job",
                           json={
                               "job_id": job_id,
                               "title": "myTitle",
                               "type": "myType",
                               "description": "myDescription",
                               "hashtags": "myHashtags",
                               "must_have": "myMust_have",
                               "nice_have": "myNice_have",
                               "location": "myLocation"
                           },
                           content_type="application/json",
                           headers=head)
    assert response.json["message"] == Success("PROFILE_UPDATED").message
    # delete_job
    response = client.post("/api/profile/delete_job",
                           json={"job_id": job_id},
                           content_type="application/json",
                           headers=head)
    with app.app_context():
        assert read.get_job_by("id", job_id) == None
Ejemplo n.º 4
0
def get_chats():
    try:
        chats = []
        # for worker get chats
        if g.user.worker:
            current_user = g.user
            for current_chat in current_user.worker.chat:
                chats.append({
                    "chat_id": current_chat.id,
                    "title": current_chat.job.title
                })
        else:
            # for jobs get chats
            validated_attr = validate_request_attr(request, ["job_id"])
            current_job = read.get_job_by("id", validated_attr['job_id'])
            for current_chat in current_job.chat:
                chats.append({
                    "chat_id": current_chat.id,
                    "first_name": current_chat.worker.first_name
                })
        return Success("READ_CORRECT").asdict() | {"chats": chats}
    except Error as myError:
        return myError.asdict()
Ejemplo n.º 5
0
def update_job():
    try:
        validated_attr = validate_request_attr(request, [
            "title", "type", "description", "hashtags", "location",
            "must_have", "nice_have", "job_id"
        ])
        current_job = read.get_job_by("id", validated_attr['job_id'])
        user = g.user
        if not user.employer:
            raise Error("NO_JOBS")
        update.update_job(current_job, "title", validated_attr['title'])
        update.update_job(current_job, "type", validated_attr['type'])
        update.update_job(current_job, "description",
                          validated_attr['description'])
        update.update_job(current_job, "hashtags", validated_attr['hashtags'])
        update.update_job(current_job, "location", validated_attr['location'])
        update.update_job(current_job, "must_have",
                          validated_attr['must_have'])
        update.update_job(current_job, "nice_have",
                          validated_attr['nice_have'])
        return Success("PROFILE_UPDATED").asdict()
    except Error as myError:
        return myError.asdict()