Fix database query in profile api