Update monthly order app #151
|
|
@ -47,15 +47,16 @@ func (h *Handler) processNextStepOrComplete(bot *tgbotapi.BotAPI, ctx context.Co
|
|||
originalApproverID := *nextStep.ApproverID
|
||||
if approval.TopicID != nil {
|
||||
topic, _ := h.ipc.Database.ApprovalTopic.GetApprovalTopicByIDDB(ctx, *approval.TopicID)
|
||||
if topic != nil && topic.CategoryID != nil {
|
||||
if delegations, _, err := h.ipc.Database.ApprovalDelegation.GetApprovalDelegationsListDB(ctx, typescore.ListDbOptions{
|
||||
Filtering: &typescore.ApprovalDelegation{
|
||||
IsActive: utilscore.PointerToBool(true),
|
||||
TopicID: approval.TopicID,
|
||||
},
|
||||
}); err == nil {
|
||||
for _, deleg := range delegations {
|
||||
if deleg.DelegatorID != nil && *deleg.DelegatorID == originalApproverID && deleg.DelegateID != nil {
|
||||
if delegations, _, err := h.ipc.Database.ApprovalDelegation.GetApprovalDelegationsListDB(ctx, typescore.ListDbOptions{
|
||||
Filtering: &typescore.ApprovalDelegation{
|
||||
IsActive: utilscore.PointerToBool(true),
|
||||
TopicID: approval.TopicID,
|
||||
},
|
||||
}); err == nil {
|
||||
for _, deleg := range delegations {
|
||||
if deleg.DelegatorID != nil && *deleg.DelegatorID == originalApproverID && deleg.DelegateID != nil {
|
||||
// ⏳ ПРОВЕРКА ДАТЫ ТУТ
|
||||
if deleg.ValidUntil != nil && deleg.ValidUntil.After(time.Now()) {
|
||||
delegate, _ := h.ipc.Database.User.GetUserByIDDB(ctx, *deleg.DelegateID)
|
||||
if delegate != nil && delegate.TelegramID != nil {
|
||||
actualApprover = delegate
|
||||
|
|
@ -64,15 +65,19 @@ func (h *Handler) processNextStepOrComplete(bot *tgbotapi.BotAPI, ctx context.Co
|
|||
}
|
||||
}
|
||||
}
|
||||
if actualApprover == nextApprover {
|
||||
if delegations, _, err := h.ipc.Database.ApprovalDelegation.GetApprovalDelegationsListDB(ctx, typescore.ListDbOptions{
|
||||
Filtering: &typescore.ApprovalDelegation{
|
||||
IsActive: utilscore.PointerToBool(true),
|
||||
CategoryID: topic.CategoryID,
|
||||
},
|
||||
}); err == nil {
|
||||
for _, deleg := range delegations {
|
||||
if deleg.DelegatorID != nil && *deleg.DelegatorID == originalApproverID && deleg.DelegateID != nil {
|
||||
}
|
||||
|
||||
if actualApprover == nextApprover {
|
||||
if delegations, _, err := h.ipc.Database.ApprovalDelegation.GetApprovalDelegationsListDB(ctx, typescore.ListDbOptions{
|
||||
Filtering: &typescore.ApprovalDelegation{
|
||||
IsActive: utilscore.PointerToBool(true),
|
||||
CategoryID: topic.CategoryID,
|
||||
},
|
||||
}); err == nil {
|
||||
for _, deleg := range delegations {
|
||||
if deleg.DelegatorID != nil && *deleg.DelegatorID == originalApproverID && deleg.DelegateID != nil {
|
||||
// ⏳ И ТУТ
|
||||
if deleg.ValidUntil != nil && deleg.ValidUntil.After(time.Now()) {
|
||||
delegate, _ := h.ipc.Database.User.GetUserByIDDB(ctx, *deleg.DelegateID)
|
||||
if delegate != nil && delegate.TelegramID != nil {
|
||||
actualApprover = delegate
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import (
|
|||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"github.com/sirupsen/logrus"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func sendText(bot *tgbotapi.BotAPI, chatID int64, text string) {
|
||||
|
|
@ -320,32 +321,41 @@ func (h *Handler) submitApprovalForSystem(ctx context.Context, bot *tgbotapi.Bot
|
|||
}
|
||||
|
||||
if approvalTopic.CategoryID != nil {
|
||||
var foundDelegation bool
|
||||
|
||||
if delegations, _, err := h.ipc.Database.ApprovalDelegation.GetApprovalDelegationsListDB(ctx, typescore.ListDbOptions{
|
||||
Filtering: &typescore.ApprovalDelegation{
|
||||
IsActive: utilscore.PointerToBool(true),
|
||||
TopicID: approvalTopic.ID,
|
||||
}}); err == nil && len(delegations) > 0 {
|
||||
}}); err == nil {
|
||||
for _, deleg := range delegations {
|
||||
if deleg.DelegatorID != nil && *deleg.DelegatorID == *actualApprover.ID && deleg.DelegateID != nil {
|
||||
delegate, _ := h.ipc.Database.User.GetUserByIDDB(ctx, *deleg.DelegateID)
|
||||
if delegate != nil && delegate.TelegramID != nil {
|
||||
actualApprover = delegate
|
||||
break
|
||||
if deleg.ValidUntil != nil && deleg.ValidUntil.After(time.Now()) {
|
||||
delegate, _ := h.ipc.Database.User.GetUserByIDDB(ctx, *deleg.DelegateID)
|
||||
if delegate != nil && delegate.TelegramID != nil {
|
||||
actualApprover = delegate
|
||||
foundDelegation = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
if !foundDelegation {
|
||||
if delegations, _, err := h.ipc.Database.ApprovalDelegation.GetApprovalDelegationsListDB(ctx, typescore.ListDbOptions{
|
||||
Filtering: &typescore.ApprovalDelegation{
|
||||
IsActive: utilscore.PointerToBool(true),
|
||||
CategoryID: approvalTopic.CategoryID,
|
||||
}}); err == nil && len(delegations) > 0 {
|
||||
}}); err == nil {
|
||||
for _, deleg := range delegations {
|
||||
if deleg.DelegatorID != nil && *deleg.DelegatorID == *actualApprover.ID && deleg.DelegateID != nil {
|
||||
delegate, _ := h.ipc.Database.User.GetUserByIDDB(ctx, *deleg.DelegateID)
|
||||
if delegate != nil && delegate.TelegramID != nil {
|
||||
actualApprover = delegate
|
||||
break
|
||||
if deleg.ValidUntil != nil && deleg.ValidUntil.After(time.Now()) {
|
||||
delegate, _ := h.ipc.Database.User.GetUserByIDDB(ctx, *deleg.DelegateID)
|
||||
if delegate != nil && delegate.TelegramID != nil {
|
||||
actualApprover = delegate
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -836,7 +846,9 @@ func (h *Handler) findStepForCurrentApprover(ctx context.Context, approvalID uin
|
|||
for _, deleg := range allDelegations {
|
||||
if deleg.DelegatorID != nil && *deleg.DelegatorID == *s.ApproverID &&
|
||||
deleg.DelegateID != nil && *deleg.DelegateID == currentUserID {
|
||||
return s
|
||||
if deleg.ValidUntil != nil && deleg.ValidUntil.After(time.Now()) {
|
||||
return s
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue