Skip to content

Commit

Permalink
update admin proforma update
Browse files Browse the repository at this point in the history
  • Loading branch information
1-Harshit committed Sep 13, 2022
1 parent 98c56ee commit a30f388
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions application/admin.proforma.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion application/db.proforma.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 8 additions & 0 deletions application/model.hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a30f388

Please sign in to comment.