feat(transaction): #85 replace datetime with date
Some checks failed
Build Docker Image / Build-Docker-Image (push) Has been cancelled
Some checks failed
Build Docker Image / Build-Docker-Image (push) Has been cancelled
This commit is contained in:
@@ -132,13 +132,12 @@ func (h TransactionImpl) handleUpdateTransaction() http.HandlerFunc {
|
|||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
input := types.TransactionInput{
|
input := types.TransactionInput{
|
||||||
Id: r.PathValue("id"),
|
Id: r.PathValue("id"),
|
||||||
AccountId: r.FormValue("account-id"),
|
AccountId: r.FormValue("account-id"),
|
||||||
TreasureChestId: r.FormValue("treasure-chest-id"),
|
TreasureChestId: r.FormValue("treasure-chest-id"),
|
||||||
Value: r.FormValue("value"),
|
Value: r.FormValue("value"),
|
||||||
Timestamp: r.FormValue("timestamp"),
|
Timestamp: r.FormValue("timestamp"),
|
||||||
TimezoneOffsetMinutes: r.FormValue("timezone-offset"),
|
Note: r.FormValue("note"),
|
||||||
Note: r.FormValue("note"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.Id == "new" {
|
if input.Id == "new" {
|
||||||
|
|||||||
@@ -440,20 +440,12 @@ func (s TransactionImpl) validateAndEnrichTransaction(oldTransaction *types.Tran
|
|||||||
}
|
}
|
||||||
valueInt := int64(valueFloat * 100)
|
valueInt := int64(valueFloat * 100)
|
||||||
|
|
||||||
timestampTime, err := time.Parse("2006-01-02T15:04", input.Timestamp)
|
timestamp, err := time.Parse("2006-01-02", input.Timestamp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("transaction validate: %v", err)
|
log.Error("transaction validate: %v", err)
|
||||||
return nil, fmt.Errorf("could not parse timestamp: %w", ErrBadRequest)
|
return nil, fmt.Errorf("could not parse timestamp: %w", ErrBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
if input.TimezoneOffsetMinutes != "" {
|
|
||||||
timezoneOffsetMinutes, err := strconv.Atoi(input.TimezoneOffsetMinutes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("could not parse timezone offset: %w", ErrBadRequest)
|
|
||||||
}
|
|
||||||
timestampTime = timestampTime.Add(time.Duration(-1*timezoneOffsetMinutes) * time.Minute)
|
|
||||||
}
|
|
||||||
|
|
||||||
if input.Note != "" {
|
if input.Note != "" {
|
||||||
err = validateString(input.Note, "note")
|
err = validateString(input.Note, "note")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -468,7 +460,7 @@ func (s TransactionImpl) validateAndEnrichTransaction(oldTransaction *types.Tran
|
|||||||
AccountId: accountUuid,
|
AccountId: accountUuid,
|
||||||
TreasureChestId: treasureChestUuid,
|
TreasureChestId: treasureChestUuid,
|
||||||
Value: valueInt,
|
Value: valueInt,
|
||||||
Timestamp: timestampTime,
|
Timestamp: timestamp,
|
||||||
Note: input.Note,
|
Note: input.Note,
|
||||||
|
|
||||||
CreatedAt: createdAt,
|
CreatedAt: createdAt,
|
||||||
|
|||||||
@@ -9,17 +9,12 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
function updateTime(e) {
|
function updateTime(e) {
|
||||||
const timezoneOffset = - new Date().getTimezoneOffset();
|
|
||||||
e.querySelectorAll("#timezone-offset").forEach((el) => {
|
|
||||||
el.value = timezoneOffset;
|
|
||||||
});
|
|
||||||
document.querySelectorAll(".datetime").forEach((el) => {
|
document.querySelectorAll(".datetime").forEach((el) => {
|
||||||
if (el.textContent !== "") {
|
if (el.textContent !== "") {
|
||||||
el.textContent = el.textContent.includes("UTC") ? new Date(el.textContent).toLocaleString([], { day: 'numeric', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' }) : el.textContent;
|
el.textContent = el.textContent.includes("UTC") ? new Date(el.textContent).toLocaleString([], { day: 'numeric', month: 'short', year: 'numeric' }) : el.textContent;
|
||||||
} else if (el.attributes['value'] !== "") {
|
} else if (el.attributes['value'] !== "") {
|
||||||
const value = el.attributes['value'].value;
|
const value = el.attributes['value'].value;
|
||||||
const newDate = value.includes("UTC") ? new Date(value) : value;
|
const newDate = value.includes("UTC") ? new Date(value) : value;
|
||||||
newDate.setTime(newDate.getTime() + timezoneOffset * 60 * 1000);
|
|
||||||
el.valueAsDate = newDate;
|
el.valueAsDate = newDate;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -70,11 +70,10 @@ templ EditTransaction(transaction *types.Transaction, accounts []*types.Account,
|
|||||||
<input
|
<input
|
||||||
autofocus
|
autofocus
|
||||||
name="timestamp"
|
name="timestamp"
|
||||||
type="datetime-local"
|
type="date"
|
||||||
value={ timestamp.String() }
|
value={ timestamp.String() }
|
||||||
class="bg-white input datetime"
|
class="bg-white input datetime"
|
||||||
/>
|
/>
|
||||||
<input class="hidden" id="timezone-offset" name="timezone-offset" type="text"/>
|
|
||||||
<label for="note" class="text-sm text-gray-500">Note</label>
|
<label for="note" class="text-sm text-gray-500">Note</label>
|
||||||
<input
|
<input
|
||||||
name="note"
|
name="note"
|
||||||
|
|||||||
@@ -35,11 +35,10 @@ type Transaction struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TransactionInput struct {
|
type TransactionInput struct {
|
||||||
Id string
|
Id string
|
||||||
AccountId string
|
AccountId string
|
||||||
TreasureChestId string
|
TreasureChestId string
|
||||||
Value string
|
Value string
|
||||||
Timestamp string
|
Timestamp string
|
||||||
TimezoneOffsetMinutes string
|
Note string
|
||||||
Note string
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user