all tests works...
This commit is contained in:
@@ -108,19 +108,51 @@ func (r *BudgetRepo) Create(ctx context.Context, req model.CreateBudgetRequest)
|
||||
}
|
||||
|
||||
func (r *BudgetRepo) Update(ctx context.Context, req model.UpdateBudgetRequest) (*model.Budget, error) {
|
||||
_, err := r.db.ExecContext(ctx, `
|
||||
UPDATE budgets
|
||||
SET version=?, amount=?, notes=?,
|
||||
updated_at=strftime('%Y-%m-%dT%H:%M:%SZ','now')
|
||||
WHERE id=?`,
|
||||
req.Version, req.Amount, req.Notes, req.ID,
|
||||
)
|
||||
if err != nil {
|
||||
q := `UPDATE budgets SET updated_at = strftime('%Y-%m-%dT%H:%M:%SZ','now')`
|
||||
args := []any{}
|
||||
|
||||
if req.Amount != nil {
|
||||
q += `, amount = ?`
|
||||
args = append(args, *req.Amount)
|
||||
}
|
||||
if req.Notes != nil {
|
||||
q += `, notes = ?`
|
||||
args = append(args, *req.Notes)
|
||||
}
|
||||
if req.Version != nil {
|
||||
q += `, version = ?`
|
||||
args = append(args, *req.Version)
|
||||
}
|
||||
if req.Currency != nil {
|
||||
q += `, currency = ?`
|
||||
args = append(args, *req.Currency)
|
||||
}
|
||||
if req.FiscalYear != nil {
|
||||
q += `, fiscal_year = ?`
|
||||
args = append(args, *req.FiscalYear)
|
||||
}
|
||||
if req.FiscalPeriod != nil {
|
||||
q += `, fiscal_period = ?`
|
||||
args = append(args, *req.FiscalPeriod)
|
||||
}
|
||||
if req.DepartmentID != nil {
|
||||
q += `, department_id = ?`
|
||||
args = append(args, *req.DepartmentID)
|
||||
}
|
||||
if req.GLAccountID != nil {
|
||||
q += `, gl_account_id = ?`
|
||||
args = append(args, *req.GLAccountID)
|
||||
}
|
||||
|
||||
q += ` WHERE id = ?`
|
||||
args = append(args, req.ID)
|
||||
|
||||
if _, err := r.db.ExecContext(ctx, q, args...); err != nil {
|
||||
return nil, fmt.Errorf("update budget: %w", err)
|
||||
}
|
||||
|
||||
row := r.db.QueryRowContext(ctx,
|
||||
`SELECT`+budgetSelectCols+`FROM budgets WHERE id = ?`, req.ID)
|
||||
`SELECT `+budgetSelectCols+` FROM budgets WHERE id = ?`, req.ID)
|
||||
b, err := scanBudget(row)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("fetch updated budget: %w", err)
|
||||
|
||||
@@ -123,8 +123,8 @@ func (r *ReferenceRepo) ListDepartments(ctx context.Context) ([]model.Department
|
||||
return depts, rows.Err()
|
||||
}
|
||||
|
||||
func (r *ReferenceRepo) DeleteDepartment(ctx context.Context, id int) error {
|
||||
_, err := r.db.ExecContext(ctx, `DELETE FROM departments WHERE id = ?`, id)
|
||||
func (r *ReferenceRepo) DeleteDepartment(ctx context.Context, req model.DeleteDepartmentRequest) error {
|
||||
_, err := r.db.ExecContext(ctx, `DELETE FROM departments WHERE id = ?`, req.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ func (r *ReferenceRepo) getGLAccountByCode(ctx context.Context, code string) (*m
|
||||
func (r *ReferenceRepo) ListGLAccounts(ctx context.Context) ([]model.GLAccount, error) {
|
||||
rows, err := r.db.QueryContext(ctx,
|
||||
`SELECT id, code, description, type, favour_high, active
|
||||
FROM gl_accounts ORDER BY code`)
|
||||
FROM gl_accounts ORDER BY code`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -179,10 +179,12 @@ func (r *ReferenceRepo) ListGLAccounts(ctx context.Context) ([]model.GLAccount,
|
||||
var accts []model.GLAccount
|
||||
for rows.Next() {
|
||||
var a model.GLAccount
|
||||
var glType string
|
||||
var favourHigh, active int
|
||||
if err := rows.Scan(&a.ID, &a.Code, &a.Description, &a.Type, &favourHigh, &active); err != nil {
|
||||
if err := rows.Scan(&a.ID, &a.Code, &a.Description, &glType, &favourHigh, &active); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
a.Type = glType
|
||||
a.FavourHigh = favourHigh == 1
|
||||
a.Active = active == 1
|
||||
accts = append(accts, a)
|
||||
|
||||
Reference in New Issue
Block a user