sio-2425/delivery2/server/models/org.py

23 lines
1.1 KiB
Python

from database import db_connection
class Organization(db_connection.Model):
__tablename__ = 'organizations'
id = db_connection.Column(db_connection.Integer, primary_key=True, index=True)
name = db_connection.Column(db_connection.String, unique=True, index=True, nullable=False)
roles = db_connection.Column(db_connection.JSON, nullable=False, default=dict)
users = db_connection.Column(db_connection.JSON, nullable=False, default=dict)
users_id = db_connection.Column(db_connection.Integer, db_connection.ForeignKey('users.id'))
def to_dict(self):
return {
"id": self.id,
"name": self.name,
"roles": [{"role": role, "permissions": permissions} for role, permissions in self.roles.items()],
"users": [{"id": user_id, "user_data": {
"username": user_data["username"],
"full_name": user_data["full_name"],
"email": user_data["email"],
"status": user_data["status"]
}} for user_id, user_data in self.users.items()],
}