diff --git a/application/admin.proforma.go b/application/admin.proforma.go index bc30ed4..f45debc 100644 --- a/application/admin.proforma.go +++ b/application/admin.proforma.go @@ -86,6 +86,8 @@ func putProformaHandler(ctx *gin.Context) { return } + jp.ActionTakenBy = middleware.GetUserID(ctx) + publishNotice := oldJp.Deadline == 0 && jp.Deadline != 0 err = updateProforma(ctx, &jp) diff --git a/application/db.proforma.go b/application/db.proforma.go index 92afe61..8bd2ced 100644 --- a/application/db.proforma.go +++ b/application/db.proforma.go @@ -5,6 +5,7 @@ import ( "time" "github.com/gin-gonic/gin" + "github.com/spo-iitk/ras-backend/middleware" "github.com/spo-iitk/ras-backend/rc" ) @@ -199,7 +200,9 @@ func updateProforma(ctx *gin.Context, jp *Proforma) error { } func updateHideProforma(ctx *gin.Context, jp *hideProformaRequest) error { - tx := db.WithContext(ctx).Model(&Proforma{}).Where("id = ?", jp.ID).Update("hide_details", jp.HideDetails) + tx := db.WithContext(ctx).Model(&Proforma{}).Where("id = ?", jp.ID). + Update("hide_details", jp.HideDetails). + Update("action_taken_by", middleware.GetUserID(ctx)) return tx.Error } diff --git a/application/model.hooks.go b/application/model.hooks.go index 17251d8..e2d2994 100644 --- a/application/model.hooks.go +++ b/application/model.hooks.go @@ -45,6 +45,14 @@ func (jp *Proforma) AfterUpdate(tx *gorm.DB) (err error) { return } +// Set first char of eligibility to 0 +func (p *Proforma) BeforeUpdate(tx *gorm.DB) (err error) { + if p.Eligibility != "" { + p.Eligibility = "0" + p.Eligibility[1:] + } + return +} + // Set default eligibility to none func (p *Proforma) BeforeCreate(tx *gorm.DB) (err error) { p.Eligibility = strings.Repeat("0", 130)