feat: update approval workflows
This commit is contained in:
parent
e1b099f6a2
commit
50d86183bf
|
|
@ -59,13 +59,13 @@ func (_i *ApprovalWorkflowsRouter) RegisterApprovalWorkflowsRoutes() {
|
||||||
_i.App.Route("/approval-workflows", func(router fiber.Router) {
|
_i.App.Route("/approval-workflows", func(router fiber.Router) {
|
||||||
router.Get("/", approvalWorkflowsController.All)
|
router.Get("/", approvalWorkflowsController.All)
|
||||||
router.Get("/default", approvalWorkflowsController.GetDefault)
|
router.Get("/default", approvalWorkflowsController.GetDefault)
|
||||||
router.Get("/:id", approvalWorkflowsController.Show)
|
router.Get("/detail/:id", approvalWorkflowsController.Show)
|
||||||
router.Get("/:id/with-steps", approvalWorkflowsController.GetWithSteps)
|
router.Get("/:id/with-steps", approvalWorkflowsController.GetWithSteps)
|
||||||
router.Post("/", approvalWorkflowsController.Save)
|
router.Post("/", approvalWorkflowsController.Save)
|
||||||
router.Post("/with-steps", approvalWorkflowsController.SaveWithSteps)
|
router.Post("/with-steps", approvalWorkflowsController.SaveWithSteps)
|
||||||
router.Post("/with-client-settings", approvalWorkflowsController.SaveWithClientSettings)
|
router.Post("/with-client-settings", approvalWorkflowsController.SaveWithClientSettings)
|
||||||
router.Put("/with-client-settings", approvalWorkflowsController.UpdateWithClientSettings)
|
router.Put("/with-client-settings", approvalWorkflowsController.UpdateWithClientSettings)
|
||||||
router.Post("/comprehensive-details", approvalWorkflowsController.GetComprehensiveDetails)
|
router.Get("/comprehensive-details", approvalWorkflowsController.GetComprehensiveDetails)
|
||||||
router.Put("/:id", approvalWorkflowsController.Update)
|
router.Put("/:id", approvalWorkflowsController.Update)
|
||||||
router.Put("/:id/with-steps", approvalWorkflowsController.UpdateWithSteps)
|
router.Put("/:id/with-steps", approvalWorkflowsController.UpdateWithSteps)
|
||||||
router.Put("/:id/set-default", approvalWorkflowsController.SetDefault)
|
router.Put("/:id/set-default", approvalWorkflowsController.SetDefault)
|
||||||
|
|
|
||||||
|
|
@ -532,23 +532,17 @@ func (_i *approvalWorkflowsController) SaveWithClientSettings(c *fiber.Ctx) erro
|
||||||
// @Tags ApprovalWorkflows
|
// @Tags ApprovalWorkflows
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param Authorization header string true "Insert the Authorization"
|
// @Param Authorization header string true "Insert the Authorization"
|
||||||
// @Param req body request.ComprehensiveWorkflowDetailRequest true "Workflow detail request"
|
|
||||||
// @Success 200 {object} response.Response
|
// @Success 200 {object} response.Response
|
||||||
// @Failure 400 {object} response.BadRequestError
|
// @Failure 400 {object} response.BadRequestError
|
||||||
// @Failure 401 {object} response.UnauthorizedError
|
// @Failure 401 {object} response.UnauthorizedError
|
||||||
// @Failure 500 {object} response.InternalServerError
|
// @Failure 500 {object} response.InternalServerError
|
||||||
// @Router /approval-workflows/comprehensive-details [post]
|
// @Router /approval-workflows/comprehensive-details [get]
|
||||||
func (_i *approvalWorkflowsController) GetComprehensiveDetails(c *fiber.Ctx) error {
|
func (_i *approvalWorkflowsController) GetComprehensiveDetails(c *fiber.Ctx) error {
|
||||||
req := new(request.ComprehensiveWorkflowDetailRequest)
|
|
||||||
if err := utilVal.ParseAndValidate(c, req); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get authToken from context
|
// Get authToken from context
|
||||||
authToken := c.Get("Authorization")
|
authToken := c.Get("Authorization")
|
||||||
|
|
||||||
// Get comprehensive workflow details
|
// Get comprehensive workflow details
|
||||||
details, err := _i.approvalWorkflowsService.GetComprehensiveWorkflowDetails(authToken, req.WorkflowId)
|
details, err := _i.approvalWorkflowsService.GetComprehensiveWorkflowDetails(authToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -301,8 +301,9 @@ func (req ApprovalWorkflowsQueryRequestContext) ToParamRequest() ApprovalWorkflo
|
||||||
}
|
}
|
||||||
|
|
||||||
// ComprehensiveWorkflowDetailRequest - Request for getting comprehensive workflow details
|
// ComprehensiveWorkflowDetailRequest - Request for getting comprehensive workflow details
|
||||||
|
// Note: workflowId is now automatically determined from user's clientId
|
||||||
type ComprehensiveWorkflowDetailRequest struct {
|
type ComprehensiveWorkflowDetailRequest struct {
|
||||||
WorkflowId uint `json:"workflowId" validate:"required"`
|
// No parameters needed - workflow is determined from user's clientId
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateApprovalWorkflowWithClientSettingsRequest - Request for updating approval workflow with client settings
|
// UpdateApprovalWorkflowWithClientSettingsRequest - Request for updating approval workflow with client settings
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ type ApprovalWorkflowsService interface {
|
||||||
UpdateWorkflowWithClientSettings(authToken string, req request.UpdateApprovalWorkflowWithClientSettingsRequest) (workflow *entity.ApprovalWorkflows, clientSettings *entity.ClientApprovalSettings, err error)
|
UpdateWorkflowWithClientSettings(authToken string, req request.UpdateApprovalWorkflowWithClientSettingsRequest) (workflow *entity.ApprovalWorkflows, clientSettings *entity.ClientApprovalSettings, err error)
|
||||||
|
|
||||||
// Comprehensive workflow details
|
// Comprehensive workflow details
|
||||||
GetComprehensiveWorkflowDetails(authToken string, workflowId uint) (details *response.ComprehensiveWorkflowDetailResponse, err error)
|
GetComprehensiveWorkflowDetails(authToken string) (details *response.ComprehensiveWorkflowDetailResponse, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewApprovalWorkflowsService(
|
func NewApprovalWorkflowsService(
|
||||||
|
|
@ -739,7 +739,7 @@ func (_i *approvalWorkflowsService) CreateWorkflowWithClientSettings(authToken s
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetComprehensiveWorkflowDetails retrieves comprehensive workflow details including all related data
|
// GetComprehensiveWorkflowDetails retrieves comprehensive workflow details including all related data
|
||||||
func (_i *approvalWorkflowsService) GetComprehensiveWorkflowDetails(authToken string, workflowId uint) (details *response.ComprehensiveWorkflowDetailResponse, err error) {
|
func (_i *approvalWorkflowsService) GetComprehensiveWorkflowDetails(authToken string) (details *response.ComprehensiveWorkflowDetailResponse, err error) {
|
||||||
// Extract clientId from authToken
|
// Extract clientId from authToken
|
||||||
var clientId *uuid.UUID
|
var clientId *uuid.UUID
|
||||||
if authToken != "" {
|
if authToken != "" {
|
||||||
|
|
@ -755,19 +755,30 @@ func (_i *approvalWorkflowsService) GetComprehensiveWorkflowDetails(authToken st
|
||||||
}
|
}
|
||||||
|
|
||||||
_i.Log.Info().
|
_i.Log.Info().
|
||||||
Uint("workflowId", workflowId).
|
|
||||||
Interface("clientId", clientId).
|
Interface("clientId", clientId).
|
||||||
Msg("Getting comprehensive workflow details")
|
Msg("Getting comprehensive workflow details")
|
||||||
|
|
||||||
// Get workflow
|
// Get workflow - first try to get default workflow, if not found get any active workflow
|
||||||
workflow, err := _i.ApprovalWorkflowsRepository.FindOne(clientId, workflowId)
|
workflow, err := _i.ApprovalWorkflowsRepository.FindDefault(clientId)
|
||||||
|
if err != nil || workflow == nil {
|
||||||
|
_i.Log.Info().Msg("No default workflow found, getting first active workflow")
|
||||||
|
// If no default workflow, get the first active workflow for this client
|
||||||
|
queryReq := request.ApprovalWorkflowsQueryRequest{
|
||||||
|
Pagination: &paginator.Pagination{
|
||||||
|
Limit: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
workflows, _, err := _i.ApprovalWorkflowsRepository.GetAll(clientId, queryReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get workflow: %w", err)
|
return nil, fmt.Errorf("failed to get workflows: %w", err)
|
||||||
|
}
|
||||||
|
if len(workflows) == 0 {
|
||||||
|
return nil, errors.New("no active workflows found for this client")
|
||||||
|
}
|
||||||
|
workflow = workflows[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if workflow == nil {
|
workflowId := workflow.ID
|
||||||
return nil, errors.New("workflow not found")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get workflow steps
|
// Get workflow steps
|
||||||
steps, err := _i.ApprovalWorkflowStepsRepository.GetByWorkflowId(clientId, workflowId)
|
steps, err := _i.ApprovalWorkflowStepsRepository.GetByWorkflowId(clientId, workflowId)
|
||||||
|
|
|
||||||
|
|
@ -361,8 +361,8 @@ func (_i *clientsService) CreateClientWithUser(req request.ClientWithUserCreateR
|
||||||
LastEducation: adminUserReq.LastEducation,
|
LastEducation: adminUserReq.LastEducation,
|
||||||
ClientId: &createdClient.ID,
|
ClientId: &createdClient.ID,
|
||||||
// Set default admin level and role (you may need to adjust these based on your system)
|
// Set default admin level and role (you may need to adjust these based on your system)
|
||||||
UserLevelId: 1, // Assuming level 1 is admin level
|
UserLevelId: 1, // Assuming level 1 is generic level
|
||||||
UserRoleId: 1, // Assuming role 1 is admin role
|
UserRoleId: 2, // Assuming role 1 is admin client role
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create user with the new client ID
|
// Create user with the new client ID
|
||||||
|
|
|
||||||
|
|
@ -1707,7 +1707,7 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/approval-workflows/comprehensive-details": {
|
"/approval-workflows/comprehensive-details": {
|
||||||
"post": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"Bearer": []
|
"Bearer": []
|
||||||
|
|
@ -1725,15 +1725,6 @@ const docTemplate = `{
|
||||||
"name": "Authorization",
|
"name": "Authorization",
|
||||||
"in": "header",
|
"in": "header",
|
||||||
"required": true
|
"required": true
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Workflow detail request",
|
|
||||||
"name": "req",
|
|
||||||
"in": "body",
|
|
||||||
"required": true,
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/request.ComprehensiveWorkflowDetailRequest"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|
@ -17458,17 +17449,6 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"request.ComprehensiveWorkflowDetailRequest": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"workflowId"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"workflowId": {
|
|
||||||
"type": "integer"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"request.CreateApprovalWorkflowStepsRequest": {
|
"request.CreateApprovalWorkflowStepsRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
|
|
|
||||||
|
|
@ -1696,7 +1696,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/approval-workflows/comprehensive-details": {
|
"/approval-workflows/comprehensive-details": {
|
||||||
"post": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"Bearer": []
|
"Bearer": []
|
||||||
|
|
@ -1714,15 +1714,6 @@
|
||||||
"name": "Authorization",
|
"name": "Authorization",
|
||||||
"in": "header",
|
"in": "header",
|
||||||
"required": true
|
"required": true
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Workflow detail request",
|
|
||||||
"name": "req",
|
|
||||||
"in": "body",
|
|
||||||
"required": true,
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/request.ComprehensiveWorkflowDetailRequest"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|
@ -17447,17 +17438,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"request.ComprehensiveWorkflowDetailRequest": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"workflowId"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"workflowId": {
|
|
||||||
"type": "integer"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"request.CreateApprovalWorkflowStepsRequest": {
|
"request.CreateApprovalWorkflowStepsRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
|
|
|
||||||
|
|
@ -802,13 +802,6 @@ definitions:
|
||||||
description: Custom settings
|
description: Custom settings
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
request.ComprehensiveWorkflowDetailRequest:
|
|
||||||
properties:
|
|
||||||
workflowId:
|
|
||||||
type: integer
|
|
||||||
required:
|
|
||||||
- workflowId
|
|
||||||
type: object
|
|
||||||
request.CreateApprovalWorkflowStepsRequest:
|
request.CreateApprovalWorkflowStepsRequest:
|
||||||
properties:
|
properties:
|
||||||
approverRoleId:
|
approverRoleId:
|
||||||
|
|
@ -3066,7 +3059,7 @@ paths:
|
||||||
tags:
|
tags:
|
||||||
- ApprovalWorkflows
|
- ApprovalWorkflows
|
||||||
/approval-workflows/comprehensive-details:
|
/approval-workflows/comprehensive-details:
|
||||||
post:
|
get:
|
||||||
description: API for getting comprehensive details of approval workflow including
|
description: API for getting comprehensive details of approval workflow including
|
||||||
steps, client settings, and related data
|
steps, client settings, and related data
|
||||||
parameters:
|
parameters:
|
||||||
|
|
@ -3075,12 +3068,6 @@ paths:
|
||||||
name: Authorization
|
name: Authorization
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
- description: Workflow detail request
|
|
||||||
in: body
|
|
||||||
name: req
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/request.ComprehensiveWorkflowDetailRequest'
|
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue