mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
add restrict create/edit/delete depletion
This commit is contained in:
@@ -324,6 +324,15 @@ func (s *recordingService) CreateOne(c *fiber.Ctx, req *validation.Create) (*ent
|
|||||||
if err := s.enforceTransferRecordingRoute(ctx, pfk, recordTime, routePayload); err != nil {
|
if err := s.enforceTransferRecordingRoute(ctx, pfk, recordTime, routePayload); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if routePayload.DepletionCount > 0 {
|
||||||
|
if err := s.ensureDepletionMutationAllowed(ctx, &entity.Recording{
|
||||||
|
ProjectFlockKandangId: req.ProjectFlockKandangId,
|
||||||
|
RecordDatetime: recordTime,
|
||||||
|
ProjectFlockKandang: pfk,
|
||||||
|
}, "buat"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := s.ProjectFlockSvc.EnsureProjectFlockApproved(ctx, pfk.ProjectFlockId); err != nil {
|
if err := s.ProjectFlockSvc.EnsureProjectFlockApproved(ctx, pfk.ProjectFlockId); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1136,7 +1145,7 @@ func (s *recordingService) ensurePopulationMutationAllowed(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *recordingService) ensureDepletionMutationAllowed(ctx context.Context, recording *entity.Recording, operation string) error {
|
func (s *recordingService) ensureDepletionMutationAllowed(ctx context.Context, recording *entity.Recording, operation string) error {
|
||||||
if recording == nil || recording.Id == 0 || recording.ProjectFlockKandangId == 0 || s.TransferLayingRepo == nil {
|
if recording == nil || recording.ProjectFlockKandangId == 0 || s.TransferLayingRepo == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1177,18 +1186,20 @@ func (s *recordingService) ensureDepletionMutationAllowed(ctx context.Context, r
|
|||||||
}
|
}
|
||||||
|
|
||||||
recordDate := normalizeDateOnlyUTC(recording.RecordDatetime)
|
recordDate := normalizeDateOnlyUTC(recording.RecordDatetime)
|
||||||
physicalMoveDate := transferPhysicalMoveDate(transfer)
|
transferNumber := strings.TrimSpace(transfer.TransferNumber)
|
||||||
if physicalMoveDate.IsZero() || recordDate.Before(physicalMoveDate) {
|
if transferNumber == "" {
|
||||||
return nil
|
transferNumber = "-"
|
||||||
}
|
}
|
||||||
|
executedDate := normalizeDateOnlyUTC(*transfer.ExecutedAt)
|
||||||
|
|
||||||
return fiber.NewError(
|
return fiber.NewError(
|
||||||
fiber.StatusBadRequest,
|
fiber.StatusBadRequest,
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"Deplesi recording tanggal %s tidak dapat di%s karena sudah mempengaruhi transfer laying %s yang sudah dieksekusi. Lakukan unexecute transfer terlebih dahulu bila belum ada pemakaian downstream.",
|
"Deplesi recording tanggal %s tidak dapat di%s karena transfer laying %s sudah dieksekusi pada %s. Setelah transfer dieksekusi, mutasi deplesi di kandang growing tidak diizinkan (termasuk backdate).",
|
||||||
recordDate.Format("2006-01-02"),
|
recordDate.Format("2006-01-02"),
|
||||||
operation,
|
operation,
|
||||||
transfer.TransferNumber,
|
transferNumber,
|
||||||
|
executedDate.Format("2006-01-02"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user