niki/repository/mysql/kind_box/register_emptying_request.go

28 lines
939 B
Go

package mysqlkindbox
import (
"context"
"git.gocasts.ir/ebhomengo/niki/entity"
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
)
func (d DB) RegisterEmptyingRequestForKindBox(ctx context.Context, kindBox entity.KindBox) error {
const op = "mysqlkindbox.RegisterEmptyingRequest"
query := `UPDATE kind_boxes
SET return_address_id = ?, return_refer_time_id = ?, return_refer_date = ?, status = ?
WHERE id = ? AND benefactor_id = ? AND status = ? AND deleted_at IS NULL`
_, err := d.conn.Conn().ExecContext(ctx, query,
kindBox.ReturnAddressID, kindBox.ReturnReferTimeID, kindBox.ReturnReferDate, kindBox.Status.String(),
kindBox.ID, kindBox.BenefactorID, entity.KindBoxDeliveredStatus.String())
if err != nil {
return richerror.New(op).WithErr(err).WithMessage(errmsg.ErrorMsgSomethingWentWrong).
WithKind(richerror.KindUnexpected)
}
return nil
}