Spaces:
Sleeping
Sleeping
vanitha commited on
Commit ·
2b0115b
1
Parent(s): 43d08bc
sync staff and system user IDs
Browse files
app/system_users/schemas.py
CHANGED
|
@@ -12,14 +12,14 @@ class SystemUserCreateSchema(BaseModel):
|
|
| 12 |
name: str
|
| 13 |
email: EmailStr
|
| 14 |
phone: str
|
| 15 |
-
status: str = Field(...,
|
| 16 |
role: str
|
| 17 |
|
| 18 |
class SystemUserUpdateSchema(BaseModel):
|
| 19 |
name: Optional[str] = None
|
| 20 |
email: Optional[EmailStr] = None
|
| 21 |
phone: Optional[str] = None
|
| 22 |
-
status: Optional[str] = Field(None,
|
| 23 |
role: Optional[str] = None
|
| 24 |
|
| 25 |
class SystemUserResponseSchema(BaseModel):
|
|
|
|
| 12 |
name: str
|
| 13 |
email: EmailStr
|
| 14 |
phone: str
|
| 15 |
+
status: str = Field(..., pattern="^(active|inactive|on_leave|suspended|terminated)$")
|
| 16 |
role: str
|
| 17 |
|
| 18 |
class SystemUserUpdateSchema(BaseModel):
|
| 19 |
name: Optional[str] = None
|
| 20 |
email: Optional[EmailStr] = None
|
| 21 |
phone: Optional[str] = None
|
| 22 |
+
status: Optional[str] = Field(None, pattern="^(active|inactive|on_leave|suspended|terminated)$")
|
| 23 |
role: Optional[str] = None
|
| 24 |
|
| 25 |
class SystemUserResponseSchema(BaseModel):
|
app/system_users/service.py
CHANGED
|
@@ -17,8 +17,7 @@ class SystemUserService:
|
|
| 17 |
# Try to find existing user by staff_id and merchant_id
|
| 18 |
user = await db[POS_SYSTEM_USERS_COLLECTION].find_one({
|
| 19 |
"staff_id": str(payload.staff_id),
|
| 20 |
-
"merchant_id": str(payload.merchant_id)
|
| 21 |
-
"user_id": str(payload.user_id)
|
| 22 |
})
|
| 23 |
if user:
|
| 24 |
# Update existing user
|
|
@@ -35,8 +34,8 @@ class SystemUserService:
|
|
| 35 |
)
|
| 36 |
user_id = user["user_id"]
|
| 37 |
else:
|
| 38 |
-
# Create new user
|
| 39 |
-
user_id = str(
|
| 40 |
await db[POS_SYSTEM_USERS_COLLECTION].insert_one({
|
| 41 |
"user_id": user_id,
|
| 42 |
"staff_id": str(payload.staff_id),
|
|
|
|
| 17 |
# Try to find existing user by staff_id and merchant_id
|
| 18 |
user = await db[POS_SYSTEM_USERS_COLLECTION].find_one({
|
| 19 |
"staff_id": str(payload.staff_id),
|
| 20 |
+
"merchant_id": str(payload.merchant_id)
|
|
|
|
| 21 |
})
|
| 22 |
if user:
|
| 23 |
# Update existing user
|
|
|
|
| 34 |
)
|
| 35 |
user_id = user["user_id"]
|
| 36 |
else:
|
| 37 |
+
# Create new user with user_id from payload
|
| 38 |
+
user_id = str(payload.user_id) # <-- system user ID
|
| 39 |
await db[POS_SYSTEM_USERS_COLLECTION].insert_one({
|
| 40 |
"user_id": user_id,
|
| 41 |
"staff_id": str(payload.staff_id),
|