Add validation to mailman service
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -3902,8 +3902,8 @@ input CreateMailingListUpdateInput {
|
||||
|
||||
input UpdateMailingListUpdateInput {
|
||||
id: ID!
|
||||
title: String!
|
||||
body: String!
|
||||
title: String
|
||||
body: String
|
||||
}
|
||||
|
||||
input SendMailingListUpdateInput {
|
||||
|
||||
@@ -15318,8 +15318,8 @@ input CreateMailingListUpdateInput {
|
||||
|
||||
input UpdateMailingListUpdateInput {
|
||||
id: ID!
|
||||
title: String!
|
||||
body: String!
|
||||
title: String
|
||||
body: String
|
||||
}
|
||||
|
||||
input SendMailingListUpdateInput {
|
||||
@@ -73536,14 +73536,14 @@ func (ec *executionContext) unmarshalInputUpdateMailingListUpdateInput(ctx conte
|
||||
it.ID = data
|
||||
case "title":
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title"))
|
||||
data, err := ec.unmarshalNString2string(ctx, v)
|
||||
data, err := ec.unmarshalOString2ᚖstring(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
it.Title = data
|
||||
case "body":
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("body"))
|
||||
data, err := ec.unmarshalNString2string(ctx, v)
|
||||
data, err := ec.unmarshalOString2ᚖstring(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
|
||||
@@ -2227,8 +2227,8 @@ type UpdateMailingListPayload struct {
|
||||
|
||||
type UpdateMailingListUpdateInput struct {
|
||||
ID gid.GID `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Title *string `json:"title,omitempty"`
|
||||
Body *string `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateMailingListUpdatePayload struct {
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"go.probo.inc/probo/pkg/server/api/console/v1/types"
|
||||
"go.probo.inc/probo/pkg/server/gqlutils"
|
||||
"go.probo.inc/probo/pkg/server/gqlutils/types/cursor"
|
||||
"go.probo.inc/probo/pkg/validator"
|
||||
)
|
||||
|
||||
// StateOfApplicability is the resolver for the stateOfApplicability field.
|
||||
@@ -2072,8 +2073,18 @@ func (r *mutationResolver) CreateMailingListUpdate(ctx context.Context, input ty
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mlu, err := r.mailman.CreateMailingListUpdate(ctx, input.MailingListID, input.Title, input.Body)
|
||||
mlu, err := r.mailman.CreateMailingListUpdate(
|
||||
ctx,
|
||||
&mailman.CreateMailingListUpdateRequest{
|
||||
MailingListID: input.MailingListID,
|
||||
Title: input.Title,
|
||||
Body: input.Body,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
||||
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
||||
}
|
||||
r.logger.ErrorCtx(ctx, "cannot create mailing list update", log.Error(err))
|
||||
return nil, gqlutils.Internal(ctx)
|
||||
}
|
||||
@@ -2089,8 +2100,18 @@ func (r *mutationResolver) UpdateMailingListUpdate(ctx context.Context, input ty
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mlu, err := r.mailman.UpdateMailingListUpdate(ctx, input.ID, input.Title, input.Body)
|
||||
mlu, err := r.mailman.UpdateMailingListUpdate(
|
||||
ctx,
|
||||
&mailman.UpdateMailingListUpdateRequest{
|
||||
ID: input.ID,
|
||||
Title: input.Title,
|
||||
Body: input.Body,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
||||
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
||||
}
|
||||
if errors.Is(err, mailman.ErrMailingListUpdateAlreadySent) {
|
||||
return nil, gqlutils.Conflictf(ctx, "mailing list update can only be edited when in draft")
|
||||
}
|
||||
@@ -2173,11 +2194,16 @@ func (r *mutationResolver) CreateMailingListSubscriber(ctx context.Context, inpu
|
||||
|
||||
subscriber, err := r.mailman.CreateSubscriber(
|
||||
ctx,
|
||||
input.MailingListID,
|
||||
input.Email,
|
||||
input.FullName,
|
||||
&mailman.CreateSubscriberRequest{
|
||||
MailingListID: input.MailingListID,
|
||||
Email: input.Email,
|
||||
FullName: input.FullName,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
if validationErrors, ok := errors.AsType[validator.ValidationErrors](err); ok {
|
||||
return nil, gqlutils.InvalidValidationErrors(ctx, validationErrors)
|
||||
}
|
||||
if errors.Is(err, mailman.ErrSubscriberAlreadyExist) {
|
||||
return nil, gqlutils.Conflictf(ctx, "subscriber already exists in this mailing list")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user