mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: change organization schema
This commit is contained in:
parent
dee9ae6cf3
commit
ae280b2cfb
1 changed files with 6 additions and 9 deletions
|
|
@ -16,12 +16,11 @@ class Organization(BaseModel):
|
||||||
description: str
|
description: str
|
||||||
email: str
|
email: str
|
||||||
slug: str
|
slug: str
|
||||||
|
default: bool
|
||||||
|
|
||||||
|
|
||||||
class OrganizationInDB(Organization):
|
class OrganizationInDB(Organization):
|
||||||
org_id: str
|
org_id: str
|
||||||
owners: List[str]
|
|
||||||
admins: List[str]
|
|
||||||
|
|
||||||
|
|
||||||
class PublicOrganization(Organization):
|
class PublicOrganization(Organization):
|
||||||
|
|
@ -75,9 +74,7 @@ async def create_org(request: Request, org_object: Organization, current_user: P
|
||||||
# generate org_id with uuid4
|
# generate org_id with uuid4
|
||||||
org_id = str(f"org_{uuid4()}")
|
org_id = str(f"org_{uuid4()}")
|
||||||
|
|
||||||
org = OrganizationInDB(org_id=org_id, owners=[
|
org = OrganizationInDB(org_id=org_id, **org_object.dict())
|
||||||
current_user.user_id], admins=[
|
|
||||||
current_user.user_id], **org_object.dict())
|
|
||||||
|
|
||||||
org_in_db = await orgs.insert_one(org.dict())
|
org_in_db = await orgs.insert_one(org.dict())
|
||||||
|
|
||||||
|
|
@ -113,7 +110,7 @@ async def update_org(request: Request, org_object: Organization, org_id: str, cu
|
||||||
status_code=status.HTTP_409_CONFLICT, detail="Organization does not exist")
|
status_code=status.HTTP_409_CONFLICT, detail="Organization does not exist")
|
||||||
|
|
||||||
updated_org = OrganizationInDB(
|
updated_org = OrganizationInDB(
|
||||||
org_id=org_id, owners=owners, admins=admins, **org_object.dict())
|
org_id=org_id, **org_object.dict())
|
||||||
|
|
||||||
await orgs.update_one({"org_id": org_id}, {"$set": updated_org.dict()})
|
await orgs.update_one({"org_id": org_id}, {"$set": updated_org.dict()})
|
||||||
|
|
||||||
|
|
@ -152,7 +149,7 @@ async def get_orgs_by_user(request: Request, user_id: str, page: int = 1, limit:
|
||||||
# get user orgs
|
# get user orgs
|
||||||
user_orgs = await user.find_one({"user_id": user_id})
|
user_orgs = await user.find_one({"user_id": user_id})
|
||||||
|
|
||||||
org_ids : list[UserOrganization] = []
|
org_ids: list[UserOrganization] = []
|
||||||
|
|
||||||
for org in user_orgs["orgs"]:
|
for org in user_orgs["orgs"]:
|
||||||
if org["org_role"] == "owner" or org["org_role"] == "editor" or org["org_role"] == "member":
|
if org["org_role"] == "owner" or org["org_role"] == "editor" or org["org_role"] == "member":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue