|
@@ -2,7 +2,9 @@ package label
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+ "fmt"
|
|
|
"github.com/zeromicro/go-zero/core/errorx"
|
|
|
+ "wechat-api/ent/contact"
|
|
|
"wechat-api/ent/label"
|
|
|
"wechat-api/ent/labelrelationship"
|
|
|
"wechat-api/internal/svc"
|
|
@@ -29,16 +31,24 @@ func NewDeleteLabelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delet
|
|
|
|
|
|
func (l *DeleteLabelLogic) DeleteLabel(req *types.IDsReq) (*types.BaseMsgResp, error) {
|
|
|
organizationId := l.ctx.Value("organizationId").(uint64)
|
|
|
-
|
|
|
+ fmt.Printf("req.Ids: %+v", req.Ids)
|
|
|
data, err := l.svcCtx.DB.LabelRelationship.Query().
|
|
|
Where(
|
|
|
- labelrelationship.LabelIDIn(req.Ids...), // Filter by ID
|
|
|
+ labelrelationship.HasLabelsWith(
|
|
|
+ label.IDIn(req.Ids...),
|
|
|
+ ), // Filter by ID
|
|
|
labelrelationship.OrganizationID(organizationId), // Additional filter by organizationId
|
|
|
+ labelrelationship.DeletedAtIsNil(),
|
|
|
+ labelrelationship.HasContactsWith(
|
|
|
+ contact.OrganizationIDEQ(organizationId),
|
|
|
+ contact.DeletedAtIsNil(),
|
|
|
+ ),
|
|
|
).
|
|
|
Only(l.ctx)
|
|
|
//if err != nil {
|
|
|
// return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
//}
|
|
|
+ fmt.Printf("data: %+v", data)
|
|
|
if data == nil {
|
|
|
_, err := l.svcCtx.DB.Label.Delete().Where(label.IDIn(req.Ids...), label.OrganizationIDEQ(organizationId)).Exec(l.ctx)
|
|
|
|