feat(purchase
This commit is contained in:
@@ -238,6 +238,10 @@ func (s *AnalyticsServiceImpl) validatePurchasingAnalyticsRequest(req *models.Pu
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := models.ParsePurchaseTeamFilter(req.Team); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,16 @@ func TestAnalyticsServiceGetPurchasingAnalyticsValidation(t *testing.T) {
|
||||
},
|
||||
wantErr: "invalid group_by value: quarter",
|
||||
},
|
||||
{
|
||||
name: "unknown team",
|
||||
req: &models.PurchasingAnalyticsRequest{
|
||||
OrganizationID: uuid.New(),
|
||||
DateFrom: now,
|
||||
DateTo: now,
|
||||
Team: "marketing",
|
||||
},
|
||||
wantErr: "team must be one of",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -120,6 +120,20 @@ func (s *PurchaseOrderServiceImpl) ListPurchaseOrders(ctx context.Context, apctx
|
||||
if modelReq.TeamCategoryID != nil {
|
||||
filters["team_category_id"] = *modelReq.TeamCategoryID
|
||||
}
|
||||
// team spells out the same two filters in one value; the validator has already
|
||||
// ruled out sending it together with them.
|
||||
switch modelReq.Team {
|
||||
case "":
|
||||
case constants.PurchaseTeamNone:
|
||||
filters["team_unassigned"] = true
|
||||
case constants.PurchaseTeamScopeCentral:
|
||||
filters["team_scope"] = constants.PurchaseTeamScopeCentral
|
||||
default:
|
||||
if teamCategoryID, err := uuid.Parse(modelReq.Team); err == nil {
|
||||
filters["team_scope"] = constants.PurchaseTeamScopeCategory
|
||||
filters["team_category_id"] = teamCategoryID
|
||||
}
|
||||
}
|
||||
if modelReq.StartDate != nil {
|
||||
filters["start_date"] = *modelReq.StartDate
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user