feat: Update date handling to use local time formatting across various components and queries

This commit is contained in:
2025-10-04 19:44:35 +02:00
parent 79238dd643
commit 119b03a7ba
9 changed files with 71 additions and 28 deletions

View File

@@ -20,7 +20,7 @@ export function addNoteToProject(project_id, note, created_by = null, is_system
db.prepare(
`
INSERT INTO notes (project_id, note, created_by, is_system, note_date)
VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)
VALUES (?, ?, ?, ?, datetime('now', 'localtime'))
`
).run(project_id, note, created_by, is_system ? 1 : 0);
}
@@ -49,7 +49,7 @@ export function addNoteToTask(
) {
db.prepare(
`INSERT INTO notes (task_id, note, is_system, created_by, note_date)
VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP)`
VALUES (?, ?, ?, ?, datetime('now', 'localtime'))`
).run(task_id, note, is_system ? 1 : 0, created_by);
}

View File

@@ -77,7 +77,7 @@ export function createProject(data, userId = null) {
INSERT INTO projects (
contract_id, project_name, project_number, address, plot, district, unit, city, investment_number, finish_date,
wp, contact, notes, project_type, project_status, coordinates, created_by, assigned_to, created_at, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now', 'localtime'), datetime('now', 'localtime'))
`);
const result = stmt.run(

View File

@@ -85,7 +85,7 @@ export function createProjectTask(data) {
project_id, task_template_id, custom_max_wait_days, status, priority,
created_by, assigned_to, created_at, updated_at
)
VALUES (?, ?, NULL, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
VALUES (?, ?, NULL, ?, ?, ?, ?, datetime('now', 'localtime'), datetime('now', 'localtime'))
`);
result = stmt.run(
data.project_id,
@@ -107,7 +107,7 @@ export function createProjectTask(data) {
project_id, custom_task_name, custom_max_wait_days, custom_description,
status, priority, created_by, assigned_to, created_at, updated_at
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, datetime('now', 'localtime'), datetime('now', 'localtime'))
`);
result = stmt.run(
data.project_id,
@@ -162,7 +162,7 @@ export function updateProjectTaskStatus(taskId, status, userId = null) {
// Starting a task - set date_started
stmt = db.prepare(`
UPDATE project_tasks
SET status = ?, date_started = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP
SET status = ?, date_started = datetime('now', 'localtime'), updated_at = datetime('now', 'localtime')
WHERE id = ?
`);
result = stmt.run(status, taskId);
@@ -170,7 +170,7 @@ export function updateProjectTaskStatus(taskId, status, userId = null) {
// Completing a task - set date_completed
stmt = db.prepare(`
UPDATE project_tasks
SET status = ?, date_completed = CURRENT_TIMESTAMP, updated_at = CURRENT_TIMESTAMP
SET status = ?, date_completed = datetime('now', 'localtime'), updated_at = datetime('now', 'localtime')
WHERE id = ?
`);
result = stmt.run(status, taskId);
@@ -178,7 +178,7 @@ export function updateProjectTaskStatus(taskId, status, userId = null) {
// Just updating status without changing timestamps
stmt = db.prepare(`
UPDATE project_tasks
SET status = ?, updated_at = CURRENT_TIMESTAMP
SET status = ?, updated_at = datetime('now', 'localtime')
WHERE id = ?
`);
result = stmt.run(status, taskId);
@@ -283,7 +283,7 @@ export function getProjectTasksByCreator(userId) {
export function updateProjectTaskAssignment(taskId, assignedToUserId) {
const stmt = db.prepare(`
UPDATE project_tasks
SET assigned_to = ?, updated_at = CURRENT_TIMESTAMP
SET assigned_to = ?, updated_at = datetime('now', 'localtime')
WHERE id = ?
`);
return stmt.run(assignedToUserId, taskId);
@@ -335,9 +335,9 @@ export function updateProjectTask(taskId, updates, userId = null) {
// Handle status-specific timestamp updates
if (currentTask.status === "pending" && updates.status === "in_progress") {
fields.push("date_started = CURRENT_TIMESTAMP");
fields.push("date_started = datetime('now', 'localtime')");
} else if (updates.status === "completed") {
fields.push("date_completed = CURRENT_TIMESTAMP");
fields.push("date_completed = datetime('now', 'localtime')");
}
}
@@ -352,7 +352,7 @@ export function updateProjectTask(taskId, updates, userId = null) {
}
// Always update the updated_at timestamp
fields.push("updated_at = CURRENT_TIMESTAMP");
fields.push("updated_at = datetime('now', 'localtime')");
values.push(taskId);
const stmt = db.prepare(`