MCPcopy Create free account
hub / github.com/devinterface/startersaas-go-api / Create

Method Create

endpoints/team.endpoint.go:51–92  ·  view source on GitHub ↗

Create function

(ctx *fiber.Ctx)

Source from the content-addressed store, hash-verified

49
50// Create function
51func (teamEndpoint *TeamEndpoint) Create(ctx *fiber.Ctx) error {
52 me, _ := userEndpoint.CurrentUser(ctx)
53 if can := userEndpoint.Can(ctx, models.AdminRole); !can {
54 return ctx.Status(401).JSON(fiber.Map{
55 "message": "You are not authorized to perform this action",
56 })
57 }
58
59 currentAccount, _ := userEndpoint.CurrentAccount(ctx)
60
61 teams, err := teamService.FindBy(bson.M{"accountId": me.AccountID})
62 if err != nil {
63 return ctx.Status(401).JSON(fiber.Map{
64 "message": err.Error(),
65 })
66 }
67
68 if len(teams) >= models.MaxTeamsPerPlan(currentAccount.PlanType) {
69 return ctx.Status(401).JSON(fiber.Map{
70 "message": "You have reached the maximum number of teams for your plan. Upgrade it to increase the number.",
71 })
72 }
73
74 var inputMap = make(map[string]interface{})
75 ctx.BodyParser(&inputMap)
76
77 v := validate.Map(inputMap)
78 v.StringRule("code", "string|required")
79 v.StringRule("name", "string|required")
80
81 if !v.Validate() {
82 return ctx.Status(422).JSON(v.Errors)
83 }
84 team, err := teamService.Create(v.SafeData(), me.AccountID)
85 if err != nil {
86 return ctx.Status(422).JSON(fiber.Map{
87 "message": err.Error(),
88 })
89 }
90 showTeam := models.ShowTeamSerializer().Transform(team)
91 return ctx.JSON(showTeam)
92}
93
94// Update function
95func (teamEndpoint *TeamEndpoint) Update(ctx *fiber.Ctx) error {

Callers

nothing calls this directly

Calls 6

MaxTeamsPerPlanFunction · 0.92
ShowTeamSerializerFunction · 0.92
CurrentUserMethod · 0.80
CanMethod · 0.80
CurrentAccountMethod · 0.80
FindByMethod · 0.45

Tested by

no test coverage detected