Update QR token generation
This commit is contained in:
parent
1834dd0b19
commit
6064ef8fde
@ -4,6 +4,7 @@ import (
|
||||
"apskel-pos-be/internal/constants"
|
||||
"apskel-pos-be/internal/entities"
|
||||
"apskel-pos-be/internal/models"
|
||||
"apskel-pos-be/internal/pkg/tabletoken"
|
||||
"apskel-pos-be/internal/repository"
|
||||
"context"
|
||||
"errors"
|
||||
@ -212,6 +213,15 @@ func (p *TableProcessor) GetTokenByID(ctx context.Context, id uuid.UUID) (string
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if _, _, _, err := tabletoken.Decode(table.Token); err != nil {
|
||||
newToken := tabletoken.Encode(table.ID, table.OrganizationID, table.OutletID)
|
||||
if updateErr := p.tableRepo.UpdateToken(ctx, table.ID, newToken); updateErr != nil {
|
||||
return "", updateErr
|
||||
}
|
||||
return newToken, nil
|
||||
}
|
||||
|
||||
return table.Token, nil
|
||||
}
|
||||
|
||||
|
||||
@ -171,6 +171,13 @@ func (r *TableRepository) ReleaseTable(ctx context.Context, tableID uuid.UUID, p
|
||||
}).Error
|
||||
}
|
||||
|
||||
func (r *TableRepository) UpdateToken(ctx context.Context, tableID uuid.UUID, token string) error {
|
||||
return r.db.WithContext(ctx).
|
||||
Model(&entities.Table{}).
|
||||
Where("id = ?", tableID).
|
||||
Update("token", token).Error
|
||||
}
|
||||
|
||||
func (r *TableRepository) GetByOrderID(ctx context.Context, orderID uuid.UUID) (*entities.Table, error) {
|
||||
var table entities.Table
|
||||
err := r.db.WithContext(ctx).
|
||||
|
||||
@ -24,4 +24,5 @@ type TableRepositoryInterface interface {
|
||||
OccupyTable(ctx context.Context, tableID, orderID uuid.UUID, startTime *time.Time) error
|
||||
ReleaseTable(ctx context.Context, tableID uuid.UUID, paymentAmount float64) error
|
||||
GetByOrderID(ctx context.Context, orderID uuid.UUID) (*entities.Table, error)
|
||||
UpdateToken(ctx context.Context, tableID uuid.UUID, token string) error
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user