forked from ebhomengo/niki
minor change validation Accept/Reject kind box request
This commit is contained in:
parent
79be4d0a0e
commit
96eb93bb69
|
@ -14,6 +14,6 @@ const (
|
|||
ErrorMsgOtpCodeIsNotValid = "verification code is not valid"
|
||||
ErrorMsgCantScanQueryResult = "can't scan query result"
|
||||
ErrorMsgPhoneNumberOrPassIsIncorrect = "phone number or password is incorrect"
|
||||
ErrorMsgReAcceptKindBoxReq = "accepted request cannot be re-accepted"
|
||||
ErrorMsgReRejectKindBoxReq = "rejected request cannot be re-rejected"
|
||||
ErrorMsgAcceptKindBoxReqStatus = "only pending requests will have the ability to be confirmed"
|
||||
ErrorMsgRejectKindBoxReqStatus = "only pending requests will have the ability to be rejected"
|
||||
)
|
||||
|
|
|
@ -74,37 +74,6 @@ func (d DB) KindBoxRequestExist(id uint) (bool, error) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
func (d DB) CheckKindBoxReqStatusForAccepting(id uint) error {
|
||||
op := richerror.Op("mysqlkindboxreq.CheckKindBoxReqStatusForAccepting")
|
||||
|
||||
k, err := d.GetByID(context.Background(), id)
|
||||
if err != nil {
|
||||
return richerror.New(op).WithErr(err)
|
||||
}
|
||||
if k.Status == entity.KindBoxReqAcceptedStatus {
|
||||
return richerror.New(op).WithMessage(errmsg.ErrorMsgReAcceptKindBoxReq).WithMeta(map[string]interface{}{
|
||||
"id": id,
|
||||
}).WithKind(richerror.KindInvalid)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d DB) CheckKindBoxReqStatusForRejecting(id uint) error {
|
||||
op := richerror.Op("mysqlkindboxreq.CheckKindBoxReqStatusForRejecting")
|
||||
k, err := d.GetByID(context.Background(), id)
|
||||
if err != nil {
|
||||
return richerror.New(op).WithErr(err)
|
||||
}
|
||||
if k.Status == entity.KindBoxReqRejectedStatus {
|
||||
return richerror.New(op).WithMessage(errmsg.ErrorMsgReRejectKindBoxReq).WithMeta(map[string]interface{}{
|
||||
"id": id,
|
||||
}).WithKind(richerror.KindInvalid)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d DB) RejectKindBoxReq(ctx context.Context, kindBoxReqID uint, description string) error {
|
||||
op := richerror.Op("mysqlkindboxreq.RejectKindBoxReq")
|
||||
statement, err := d.conn.Conn().
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package adminkindboxreqvalidator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||
|
||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||
)
|
||||
|
@ -18,8 +20,7 @@ type Repository interface {
|
|||
// TypeExist(id int) (bool, error)
|
||||
// KindBoxBelongToBenefactor(benefactorID uint, kindboxID uint) (bool, error)
|
||||
// PendingStatus(id uint) (bool, error)
|
||||
CheckKindBoxReqStatusForAccepting(id uint) error
|
||||
CheckKindBoxReqStatusForRejecting(id uint) error
|
||||
GetByID(ctx context.Context, id uint) (entity.KindBoxReq, error)
|
||||
}
|
||||
|
||||
type Validator struct {
|
||||
|
@ -79,10 +80,13 @@ func (v Validator) CheckKindBoxReqStatusForAccepting(value interface{}) error {
|
|||
if !ok {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||
}
|
||||
err := v.repo.CheckKindBoxReqStatusForAccepting(kindboxreqID)
|
||||
kindBox, err := v.repo.GetByID(context.Background(), kindboxreqID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if kindBox.Status != entity.KindBoxReqPendingStatus {
|
||||
return fmt.Errorf(errmsg.ErrorMsgAcceptKindBoxReqStatus)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -92,10 +96,13 @@ func (v Validator) CheckKindBoxReqStatusForRejecting(value interface{}) error {
|
|||
if !ok {
|
||||
return fmt.Errorf(errmsg.ErrorMsgSomethingWentWrong)
|
||||
}
|
||||
err := v.repo.CheckKindBoxReqStatusForRejecting(kindboxreqID)
|
||||
kindBox, err := v.repo.GetByID(context.Background(), kindboxreqID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if kindBox.Status != entity.KindBoxReqPendingStatus {
|
||||
return fmt.Errorf(errmsg.ErrorMsgRejectKindBoxReqStatus)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue