model.py (2253B)
1 import datetime 2 3 from fastapi.encoders import jsonable_encoder 4 from typing import List, Optional, Union 5 from pydantic import BaseModel, Field 6 7 class Users(BaseModel): 8 _id: Optional[PydanticObjectId] = Field(None, alias="_id") 9 slug: str 10 username: str 11 role: str 12 location: str 13 phone: int 14 email: str 15 active: bool 16 pay_period: str 17 pay_value: float 18 19 def to_json(self): 20 return jsonable_encoder(self, exclude_none=True) 21 22 def to_bson(self): 23 data = self.dict(by_alias=True, exclude_none=True) 24 25 if data["_id"] is None: 26 data.pop("_id") 27 return data 28 29 30 class Time(BaseModel): 31 _id: str 32 # forign key 33 clock_in: datetime.utcnow #System time 34 modified_by: str #link to _id of user 35 date: datetime.date 36 project: str 37 clock_out: datetime.utcnow #System time 38 note: str 39 perdium: bool 40 total_time: int #clock_out - clock_in 41 42 def to_json(self): 43 return jsonable_encoder(self, exclude_none=True) 44 45 def to_bson(self): 46 data = self.dict(by_alias=True, exclude_none=True) 47 48 if data["_id"] is None: 49 data.pop("_id") 50 return data 51 52 53 class Fleet(BaseModel): 54 _id: int 55 date: datetime.date 56 operator: int #forign key to userID 57 safety_checks: bool #array for different safety checks 58 additional_notes: str 59 vehicle: int #vehicleID 60 incident_report: str 61 mileage: int 62 63 def to_json(self): 64 return jsonable_encoder(self, exclude_none=True) 65 66 def to_bson(self): 67 data = self.dict(by_alias=True, exclude_none=True) 68 69 if data["_id"] is None: 70 data.pop("_id") 71 return data 72 73 74 class Agreement(BaseModel): 75 _id: int #forign key to user 76 start_date: int 77 end_date: int 78 bid_document: str #Filepath to document 79 budget: float 80 cost: int 81 82 class Projects(BaseModel):#Projects references agreement 83 project_id: int 84 project_name: str 85 project_budget: List[float] = [ 86 # labor_budget: float | Indexed 0 87 # travel_budget: float | Indexed 1 88 # supplies_budget: float | Indexed 2 89 # contact_budget: float | Indexed 3 90 # equipment_budget: float | Indexed 4 91 # other: float | Indexed 5 92 ]