feat: update article approvals

This commit is contained in:
hanif salafi 2025-02-18 05:15:57 +07:00
parent d61198ef22
commit 23493e7800
5 changed files with 42 additions and 22 deletions

View File

@ -8,6 +8,6 @@ type ArticleApprovals struct {
ApprovalBy uint `json:"approval_by" gorm:"type:int4"`
StatusId int `json:"status_id" gorm:"type:int4"`
Message string `json:"message" gorm:"type:varchar"`
ApprovalAtLevel int `json:"approval_at_level" gorm:"type:int4"`
ApprovalAtLevel *int `json:"approval_at_level" gorm:"type:int4"`
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
}

View File

@ -10,6 +10,7 @@ type UserLevels struct {
ParentLevelId *int `json:"parent_level_id" gorm:"type:int4"`
ProvinceId *int `json:"province_id" gorm:"type:int4"`
Group *string `json:"group" gorm:"type:varchar"`
IsApprovalActive *bool `json:"is_approval_active" gorm:"type:bool;default:false"`
IsActive *bool `json:"is_active" gorm:"type:bool"`
CreatedAt time.Time `json:"created_at" gorm:"default:now()"`
UpdatedAt time.Time `json:"updated_at" gorm:"default:now()"`

View File

@ -8,6 +8,6 @@ type ArticleApprovalsResponse struct {
ApprovalBy uint `json:"approvalBy"`
StatusId int `json:"statusId"`
Message string `json:"message"`
ApprovalAtLevel int `json:"approvalAtLevel"`
ApprovalAtLevel *int `json:"approvalAtLevel"`
CreatedAt time.Time `json:"createdAt"`
}

View File

@ -72,12 +72,12 @@ func (_i *articleApprovalsService) Save(req request.ArticleApprovalsCreateReques
createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
newReq.ApprovalBy = createdBy.ID
newReq.ApprovalAtLevel = createdBy.UserLevel.LevelNumber
newReq.ApprovalAtLevel = &createdBy.UserLevel.LevelNumber
approvalByUserLevelId := createdBy.UserLevelId
approvalParentLevelId := createdBy.UserLevel.ParentLevelId
err = _i.ArticlesService.UpdateApproval(newReq.ArticleId, newReq.StatusId, int(approvalByUserLevelId), newReq.ApprovalAtLevel, *approvalParentLevelId)
err = _i.ArticlesService.UpdateApproval(newReq.ArticleId, newReq.StatusId, int(approvalByUserLevelId), *newReq.ApprovalAtLevel, *approvalParentLevelId)
if err != nil {
return nil, err
}

View File

@ -179,8 +179,15 @@ func (_i *articlesService) Save(req request.ArticlesCreateRequest, authToken str
// Approval
statusIdOne := 1
statusIdTwo := 2
createdBy := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
if createdBy != nil && *createdBy.UserLevel.IsApprovalActive == true {
newReq.NeedApprovalFrom = nil
newReq.StatusId = &statusIdTwo
} else {
newReq.NeedApprovalFrom = &userParentLevelId
newReq.StatusId = &statusIdOne
}
saveArticleRes, err := _i.Repo.Create(newReq)
if err != nil {
@ -188,12 +195,24 @@ func (_i *articlesService) Save(req request.ArticlesCreateRequest, authToken str
}
// Approval
articleApproval := &entity.ArticleApprovals{
var articleApproval *entity.ArticleApprovals
if createdBy != nil && *createdBy.UserLevel.IsApprovalActive == true {
articleApproval = &entity.ArticleApprovals{
ArticleId: saveArticleRes.ID,
ApprovalBy: *newReq.CreatedById,
StatusId: statusIdOne,
Message: "Need Approval",
ApprovalAtLevel: userLevelNumber,
ApprovalAtLevel: &userLevelNumber,
}
} else {
articleApproval = &entity.ArticleApprovals{
ArticleId: saveArticleRes.ID,
ApprovalBy: *newReq.CreatedById,
StatusId: statusIdTwo,
Message: "Publish Otomatis",
ApprovalAtLevel: nil,
}
}
_, err = _i.ArticleApprovalsRepo.Create(articleApproval)