Add Expiring Soon
This commit is contained in:
parent
c1ae2fd14a
commit
2e1b62e33a
@ -34,6 +34,7 @@ type LicenseGetAll struct {
|
||||
PartnerName string `gorm:"type:varchar(255);not null"`
|
||||
LicenseStatus string `gorm:"type:string(255);not null"`
|
||||
CreatedByName string `gorm:"type:string(255);not null"`
|
||||
DaysToExpire int64 `gorm:"type:bigint"`
|
||||
}
|
||||
|
||||
func (License) TableName() string {
|
||||
|
||||
@ -16,6 +16,7 @@ type License struct {
|
||||
UpdatedBy int64 `json:"updated_by"`
|
||||
PartnerName string `json:"partner_name"`
|
||||
Status string `json:"status"`
|
||||
DaysToExpire int64 `json:"days_to_expire"`
|
||||
}
|
||||
|
||||
type LicenseList struct {
|
||||
@ -67,4 +68,5 @@ func (r *License) FromEntityGetAll(e *entity.LicenseGetAll) {
|
||||
r.UpdatedBy = e.UpdatedBy
|
||||
r.PartnerName = e.PartnerName
|
||||
r.Status = e.LicenseStatus
|
||||
r.DaysToExpire = e.DaysToExpire
|
||||
}
|
||||
|
||||
@ -58,10 +58,11 @@ func (r *LicenseRepository) GetAll(ctx context.Context, limit, offset int, statu
|
||||
Table("licenses").
|
||||
Select(`licenses.*, partners.name as partner_name,
|
||||
CASE
|
||||
WHEN licenses.end_date < CURRENT_DATE THEN 'Expired'
|
||||
WHEN licenses.end_date < CURRENT_DATE + INTERVAL '30 days' THEN '< 30 days'
|
||||
ELSE 'Active'
|
||||
WHEN licenses.end_date < CURRENT_DATE THEN 'EXPIRED'
|
||||
WHEN licenses.end_date < CURRENT_DATE + INTERVAL '30 days' THEN 'EXPIRING_SOON'
|
||||
ELSE 'ACTIVE'
|
||||
END as license_status,
|
||||
(GREATEST(licenses.end_date - CURRENT_DATE, 0)) as days_to_expire,
|
||||
users.name as created_by_name`).
|
||||
Joins("LEFT JOIN partners ON licenses.partner_id = partners.id").
|
||||
Joins("LEFT JOIN users ON licenses.created_by = users.id").
|
||||
@ -87,7 +88,7 @@ func (r *LicenseRepository) GetAll(ctx context.Context, limit, offset int, statu
|
||||
|
||||
func (r *LicenseRepository) FindByPartnerIDMaxEndDate(ctx context.Context, partnerID *int64) (*entity.LicenseDB, error) {
|
||||
var licenseDB entity.LicenseDB
|
||||
if err := r.db.WithContext(ctx).
|
||||
if err := r.db.Debug().WithContext(ctx).
|
||||
Where("partner_id = ?", partnerID).
|
||||
Order("end_date DESC").
|
||||
First(&licenseDB).Error; err != nil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user