mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
feat(BE): fix fifo system recording and uniformity dto
This commit is contained in:
@@ -229,7 +229,13 @@ func (s *recordingService) CreateOne(c *fiber.Ctx, req *validation.Create) (*ent
|
||||
CreatedBy: actorID,
|
||||
}
|
||||
|
||||
if err := s.Repository.CreateOne(ctx, &createdRecording, func(*gorm.DB) *gorm.DB { return tx }); err != nil {
|
||||
createTx := tx.WithContext(ctx).Select(
|
||||
"ProjectFlockKandangId",
|
||||
"RecordDatetime",
|
||||
"Day",
|
||||
"CreatedBy",
|
||||
)
|
||||
if err := createTx.Create(&createdRecording).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||
return fiber.NewError(
|
||||
fiber.StatusBadRequest,
|
||||
@@ -299,9 +305,11 @@ func (s recordingService) UpdateOne(c *fiber.Ctx, req *validation.Update, id uin
|
||||
ctx := c.Context()
|
||||
|
||||
var recordingEntity *entity.Recording
|
||||
var updatedRecording *entity.Recording
|
||||
transactionErr := s.Repository.DB().WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
recording, err := s.Repository.GetByID(ctx, id, func(db *gorm.DB) *gorm.DB {
|
||||
return s.Repository.WithRelations(tx)
|
||||
repoTx := s.Repository.WithTx(tx)
|
||||
recording, err := repoTx.GetByID(ctx, id, func(db *gorm.DB) *gorm.DB {
|
||||
return s.Repository.WithRelations(db)
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
@@ -470,13 +478,31 @@ func (s recordingService) UpdateOne(c *fiber.Ctx, req *validation.Update, id uin
|
||||
}
|
||||
}
|
||||
|
||||
updated, err := repoTx.GetByID(ctx, recordingEntity.Id, func(db *gorm.DB) *gorm.DB {
|
||||
return s.Repository.WithRelations(db)
|
||||
})
|
||||
if err != nil {
|
||||
s.Log.Errorf("Failed to reload recording %d after update: %+v", recordingEntity.Id, err)
|
||||
return err
|
||||
}
|
||||
updatedRecording = updated
|
||||
|
||||
return nil
|
||||
})
|
||||
if transactionErr != nil {
|
||||
return nil, transactionErr
|
||||
}
|
||||
|
||||
return s.GetOne(c, id)
|
||||
if updatedRecording == nil {
|
||||
return s.GetOne(c, id)
|
||||
}
|
||||
if err := s.attachLatestApproval(ctx, updatedRecording); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.attachProductionStandard(ctx, updatedRecording); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return updatedRecording, nil
|
||||
}
|
||||
|
||||
func (s recordingService) Approval(c *fiber.Ctx, req *validation.Approve) ([]entity.Recording, error) {
|
||||
|
||||
Reference in New Issue
Block a user