Add Expiring Soon

This commit is contained in:
aditya.siregar
2024-08-02 01:21:21 +07:00
parent c1ae2fd14a
commit 2e1b62e33a
3 changed files with 8 additions and 4 deletions
+5 -4
View File
@@ -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 {