51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
|
|
package relation
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
|
||
|
|
"muyu-apiserver/gateway/internal/repo"
|
||
|
|
"muyu-apiserver/gateway/internal/svc"
|
||
|
|
"muyu-apiserver/gateway/internal/types"
|
||
|
|
"muyu-apiserver/pkg/ctxdata"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
)
|
||
|
|
|
||
|
|
type UpdateRelationLogic struct {
|
||
|
|
logx.Logger
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewUpdateRelationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateRelationLogic {
|
||
|
|
return &UpdateRelationLogic{
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *UpdateRelationLogic) UpdateRelation(req *types.CrmUpdateRelationReq) (*types.IdResp, error) {
|
||
|
|
relID := ctxdata.GetPathId(l.ctx)
|
||
|
|
if relID == "" {
|
||
|
|
return nil, errors.New("relationship id is required")
|
||
|
|
}
|
||
|
|
|
||
|
|
tenantId := ctxdata.GetTenantId(l.ctx)
|
||
|
|
userId := ctxdata.GetUserId(l.ctx)
|
||
|
|
if err := l.svcCtx.CrmRepo.UpdateRelation(l.ctx, repo.UpdateRelationInput{
|
||
|
|
RelationshipId: relID,
|
||
|
|
OwnerTenantId: tenantId,
|
||
|
|
Status: req.Status,
|
||
|
|
ValidFrom: parseTimeOrNow(req.ValidFrom),
|
||
|
|
ValidTo: parseNullTime(req.ValidTo),
|
||
|
|
UpdatedBy: userId,
|
||
|
|
}); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
|
||
|
|
return &types.IdResp{Id: relID}, nil
|
||
|
|
}
|
||
|
|
|