forked from kompetenzinventar/ki-backend
26 lines
659 B
Python
26 lines
659 B
Python
|
from flask import make_response, request
|
||
|
|
||
|
from ki.models import User, Profile
|
||
|
from app import db
|
||
|
|
||
|
|
||
|
def update_profile(user_id):
|
||
|
user = User.query.filter(User.id == int(user_id)).first()
|
||
|
|
||
|
if user is None:
|
||
|
return make_response({}, 404)
|
||
|
|
||
|
profile = user.profile
|
||
|
|
||
|
if (profile is None):
|
||
|
profile = Profile(user=user, nickname=user.auth_id)
|
||
|
db.session.add(profile)
|
||
|
|
||
|
profile.pronouns = request.json.get("pronouns", "")
|
||
|
profile.volunteerwork = request.json.get("volunteerwork", "")
|
||
|
profile.freetext = request.json.get("freetext", "")
|
||
|
|
||
|
db.session.commit()
|
||
|
|
||
|
return make_response({"profile": profile.to_dict()})
|