Update function
(ctx *fiber.Ctx)
| 23 | |
| 24 | // Update function |
| 25 | func (accountEndpoint *AccountEndpoint) Update(ctx *fiber.Ctx) error { |
| 26 | if can := userEndpoint.Can(ctx, models.AdminRole); !can { |
| 27 | return ctx.Status(401).JSON(fiber.Map{ |
| 28 | "message": "You are not authorized to perform this action", |
| 29 | }) |
| 30 | } |
| 31 | |
| 32 | var inputMap = make(map[string]interface{}) |
| 33 | ctx.BodyParser(&inputMap) |
| 34 | |
| 35 | v := validate.Map(inputMap) |
| 36 | v.StringRule("companyName", "ascii") |
| 37 | v.StringRule("companyVat", "ascii") |
| 38 | v.StringRule("companyBillingAddress", "ascii") |
| 39 | v.StringRule("companySdi", "ascii") |
| 40 | v.StringRule("companyEmail", "email") |
| 41 | v.StringRule("companyPec", "email") |
| 42 | v.StringRule("companyCountry", "ascii") |
| 43 | |
| 44 | if !v.Validate() { |
| 45 | return ctx.Status(422).JSON(v.Errors) |
| 46 | } |
| 47 | updatedAccount, err := accountService.Update(ctx.Params("id"), inputMap) |
| 48 | if err != nil { |
| 49 | return ctx.Status(404).JSON(fiber.Map{ |
| 50 | "message": err.Error(), |
| 51 | }) |
| 52 | } |
| 53 | showAccount := models.ShowAccountSerializer().Transform(updatedAccount) |
| 54 | return ctx.JSON(showAccount) |
| 55 | } |
nothing calls this directly
no test coverage detected