start alerts
This commit is contained in:
@@ -195,3 +195,50 @@ type VehicleAttachment struct {
|
||||
VehicleID string `gorm:"primaryKey" json:"vehicleId"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
type VehicleAlert struct {
|
||||
Base
|
||||
VehicleID string `json:"vehicleId"`
|
||||
Vehicle Vehicle `json:"-"`
|
||||
UserID string `json:"userId"`
|
||||
User User `json:"user"`
|
||||
Title string `json:"title"`
|
||||
Comments string `json:"comments"`
|
||||
StartDate time.Time `json:"date"`
|
||||
StartOdoReading int `json:"startOdoReading"`
|
||||
DistanceUnit DistanceUnit `json:"distanceUnit"`
|
||||
AlertFrequency AlertFrequency `json:"alertFrequency"`
|
||||
OdoFrequency int `json:"odoFrequency"`
|
||||
DayFrequency int `json:"dayFrequency"`
|
||||
AlertAllUsers bool `json:"alertAllUsers"`
|
||||
IsActive bool `json:"isActive"`
|
||||
EndDate *time.Time `json:"endDate"`
|
||||
AlertType AlertType `json:"alertType"`
|
||||
}
|
||||
type AlertOccurance struct {
|
||||
Base
|
||||
VehicleID string `json:"vehicleId"`
|
||||
Vehicle Vehicle `json:"-"`
|
||||
VehicleAlertID string `json:"vehicleAlertId"`
|
||||
VehicleAlert VehicleAlert `json:"-"`
|
||||
UserID string `json:"userId"`
|
||||
User User `json:"-"`
|
||||
OdoReading int `json:"odoReading"`
|
||||
Date *time.Time `json:"date"`
|
||||
ProcessDate *time.Time `json:"processDate"`
|
||||
AlertProcessType AlertType `json:"alertProcessType"`
|
||||
CompleteDate *time.Time `json:"completeDate"`
|
||||
}
|
||||
|
||||
type Notification struct {
|
||||
Base
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
UserID string `json:"userId"`
|
||||
VehicleID string `json:"vehicleId"`
|
||||
User User `json:"-"`
|
||||
Date time.Time `json:"date"`
|
||||
ReadDate *time.Time `json:"readDate"`
|
||||
ParentID string `json:"parentId"`
|
||||
ParentType string `json:"parentType"`
|
||||
}
|
||||
|
||||
@@ -160,6 +160,11 @@ func GetFillupsByVehicleId(id string) (*[]Fillup, error) {
|
||||
result := DB.Preload(clause.Associations).Order("date desc").Find(&obj, &Fillup{VehicleID: id})
|
||||
return &obj, result.Error
|
||||
}
|
||||
func GetLatestFillupsByVehicleId(id string) (*Fillup, error) {
|
||||
var obj Fillup
|
||||
result := DB.Preload(clause.Associations).Order("date desc").First(&obj, &Fillup{VehicleID: id})
|
||||
return &obj, result.Error
|
||||
}
|
||||
func GetFillupsByVehicleIdSince(id string, since time.Time) (*[]Fillup, error) {
|
||||
var obj []Fillup
|
||||
result := DB.Where("date >= ? AND vehicle_id = ?", since, id).Preload(clause.Associations).Order("date desc").Find(&obj)
|
||||
@@ -190,6 +195,11 @@ func GetExpensesByVehicleId(id string) (*[]Expense, error) {
|
||||
result := DB.Preload(clause.Associations).Order("date desc").Find(&obj, &Expense{VehicleID: id})
|
||||
return &obj, result.Error
|
||||
}
|
||||
func GetLatestExpenseByVehicleId(id string) (*Expense, error) {
|
||||
var obj Expense
|
||||
result := DB.Preload(clause.Associations).Order("date desc").First(&obj, &Expense{VehicleID: id})
|
||||
return &obj, result.Error
|
||||
}
|
||||
func GetExpenseById(id string) (*Expense, error) {
|
||||
var obj Expense
|
||||
result := DB.Preload(clause.Associations).First(&obj, "id=?", id)
|
||||
@@ -271,6 +281,29 @@ func GetVehicleAttachments(vehicleId string) (*[]Attachment, error) {
|
||||
}
|
||||
return &attachments, nil
|
||||
}
|
||||
func GeAlertById(id string) (*VehicleAlert, error) {
|
||||
var alert VehicleAlert
|
||||
result := DB.Preload(clause.Associations).First(&alert, "id=?", id)
|
||||
return &alert, result.Error
|
||||
}
|
||||
func GetAlertOccurenceByAlertId(id string) (*[]AlertOccurance, error) {
|
||||
var alertOccurance []AlertOccurance
|
||||
result := DB.Preload(clause.Associations).Order("created_at desc").Find(&alertOccurance, "vehicle_alert_id=?", id)
|
||||
return &alertOccurance, result.Error
|
||||
}
|
||||
|
||||
func GetUnprocessedAlertOccurances() (*[]AlertOccurance, error) {
|
||||
var alertOccurance []AlertOccurance
|
||||
result := DB.Preload(clause.Associations).Order("created_at desc").Find(&alertOccurance, "process_date is NULL")
|
||||
return &alertOccurance, result.Error
|
||||
}
|
||||
func MarkAlertOccuranceAsProcessed(id string, alertProcessType AlertType, date time.Time) error {
|
||||
tx := DB.Debug().Model(&AlertOccurance{}).Where("id= ?", id).
|
||||
Update("alert_process_type", alertProcessType).
|
||||
Update("process_date", date)
|
||||
return tx.Error
|
||||
|
||||
}
|
||||
|
||||
func UpdateSettings(setting *Setting) error {
|
||||
tx := DB.Save(&setting)
|
||||
|
||||
@@ -36,6 +36,21 @@ const (
|
||||
USER
|
||||
)
|
||||
|
||||
type AlertFrequency int
|
||||
|
||||
const (
|
||||
ONETIME AlertFrequency = iota
|
||||
RECURRING
|
||||
)
|
||||
|
||||
type AlertType int
|
||||
|
||||
const (
|
||||
DISTANCE AlertType = iota
|
||||
TIME
|
||||
BOTH
|
||||
)
|
||||
|
||||
type EnumDetail struct {
|
||||
Short string `json:"short"`
|
||||
Long string `json:"long"`
|
||||
|
||||
Reference in New Issue
Block a user