feat(transaction): #85 replace datetime with date #89
@@ -137,7 +137,6 @@ func (h TransactionImpl) handleUpdateTransaction() http.HandlerFunc {
|
|||||||
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"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -911,7 +911,7 @@ func TestIntegrationAuth(t *testing.T) {
|
|||||||
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
assert.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
|
|
||||||
formData = url.Values{
|
formData = url.Values{
|
||||||
"timestamp": {"2006-01-02T15:04"},
|
"timestamp": {"2006-01-02"},
|
||||||
"value": {"100.00"},
|
"value": {"100.00"},
|
||||||
"csrf-token": {csrfToken},
|
"csrf-token": {csrfToken},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -40,6 +40,5 @@ type TransactionInput struct {
|
|||||||
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