Изменить логику выставления next_show_at: для repetition_period - сегодняшняя дата, для repetition_date - следующая подходящая дата
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 57s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 57s
This commit is contained in:
@@ -6876,28 +6876,14 @@ func (a *App) createTaskHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
var insertSQL string
|
var insertSQL string
|
||||||
var insertArgs []interface{}
|
var insertArgs []interface{}
|
||||||
if repetitionPeriod.Valid {
|
if repetitionPeriod.Valid {
|
||||||
// Вычисляем next_show_at для задачи с repetition_period
|
// Для repetition_period выставляем сегодняшнюю дату
|
||||||
periodStr := strings.TrimSpace(repetitionPeriod.String)
|
now := time.Now()
|
||||||
isZeroPeriod := strings.HasPrefix(periodStr, "0 ") || periodStr == "0"
|
|
||||||
var nextShowAt *time.Time
|
|
||||||
if !isZeroPeriod {
|
|
||||||
nextShowAt = calculateNextShowAtFromRepetitionPeriod(repetitionPeriod.String, time.Now())
|
|
||||||
}
|
|
||||||
if nextShowAt != nil {
|
|
||||||
insertSQL = `
|
insertSQL = `
|
||||||
INSERT INTO tasks (user_id, name, reward_message, progression_base, repetition_period, repetition_date, next_show_at, completed, deleted)
|
INSERT INTO tasks (user_id, name, reward_message, progression_base, repetition_period, repetition_date, next_show_at, completed, deleted)
|
||||||
VALUES ($1, $2, $3, $4, $5::INTERVAL, NULL, $6, 0, FALSE)
|
VALUES ($1, $2, $3, $4, $5::INTERVAL, NULL, $6, 0, FALSE)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`
|
`
|
||||||
insertArgs = []interface{}{userID, strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriodValue, nextShowAt}
|
insertArgs = []interface{}{userID, strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriodValue, now}
|
||||||
} else {
|
|
||||||
insertSQL = `
|
|
||||||
INSERT INTO tasks (user_id, name, reward_message, progression_base, repetition_period, repetition_date, completed, deleted)
|
|
||||||
VALUES ($1, $2, $3, $4, $5::INTERVAL, NULL, 0, FALSE)
|
|
||||||
RETURNING id
|
|
||||||
`
|
|
||||||
insertArgs = []interface{}{userID, strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriodValue}
|
|
||||||
}
|
|
||||||
} else if repetitionDate.Valid {
|
} else if repetitionDate.Valid {
|
||||||
// Вычисляем next_show_at для задачи с repetition_date
|
// Вычисляем next_show_at для задачи с repetition_date
|
||||||
nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now())
|
nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now())
|
||||||
@@ -7149,28 +7135,14 @@ func (a *App) updateTaskHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
var updateSQL string
|
var updateSQL string
|
||||||
var updateArgs []interface{}
|
var updateArgs []interface{}
|
||||||
if repetitionPeriod.Valid {
|
if repetitionPeriod.Valid {
|
||||||
// Вычисляем next_show_at для задачи с repetition_period
|
// Для repetition_period выставляем сегодняшнюю дату
|
||||||
periodStr := strings.TrimSpace(repetitionPeriod.String)
|
now := time.Now()
|
||||||
isZeroPeriod := strings.HasPrefix(periodStr, "0 ") || periodStr == "0"
|
|
||||||
var nextShowAt *time.Time
|
|
||||||
if !isZeroPeriod {
|
|
||||||
nextShowAt = calculateNextShowAtFromRepetitionPeriod(repetitionPeriod.String, time.Now())
|
|
||||||
}
|
|
||||||
if nextShowAt != nil {
|
|
||||||
updateSQL = `
|
updateSQL = `
|
||||||
UPDATE tasks
|
UPDATE tasks
|
||||||
SET name = $1, reward_message = $2, progression_base = $3, repetition_period = $4::INTERVAL, repetition_date = NULL, next_show_at = $5
|
SET name = $1, reward_message = $2, progression_base = $3, repetition_period = $4::INTERVAL, repetition_date = NULL, next_show_at = $5
|
||||||
WHERE id = $6
|
WHERE id = $6
|
||||||
`
|
`
|
||||||
updateArgs = []interface{}{strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriod.String, nextShowAt, taskID}
|
updateArgs = []interface{}{strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriod.String, now, taskID}
|
||||||
} else {
|
|
||||||
updateSQL = `
|
|
||||||
UPDATE tasks
|
|
||||||
SET name = $1, reward_message = $2, progression_base = $3, repetition_period = $4::INTERVAL, repetition_date = NULL, next_show_at = NULL
|
|
||||||
WHERE id = $5
|
|
||||||
`
|
|
||||||
updateArgs = []interface{}{strings.TrimSpace(req.Name), rewardMessage, progressionBase, repetitionPeriod.String, taskID}
|
|
||||||
}
|
|
||||||
} else if repetitionDate.Valid {
|
} else if repetitionDate.Valid {
|
||||||
// Вычисляем next_show_at для задачи с repetition_date
|
// Вычисляем next_show_at для задачи с repetition_date
|
||||||
nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now())
|
nextShowAt := calculateNextShowAtFromRepetitionDate(repetitionDate.String, time.Now())
|
||||||
|
|||||||
Reference in New Issue
Block a user