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