-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tweak(datatrakWeb): RN-1400: save task due date in unix time #5838
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d17e6e5
Change due date to be number
alexd-bes f268001
Working time zone saving
alexd-bes e774d1e
Save dates
alexd-bes d2c881f
Working filters
alexd-bes a09e807
Fix tests
alexd-bes 098c1bf
Merge branch 'epic-tasks' into rn-1400-timezones-tasks
alexd-bes 31f1828
Task creation handler tests
alexd-bes 45e3fef
database tests
alexd-bes 388f467
Central server tests
alexd-bes c320a4f
Fix merge conflict error
alexd-bes 7ecc324
handle timezones
alexd-bes 9a41766
Fix tests
alexd-bes 3f4fe4a
Handle creating tasks in timezone
alexd-bes eb05952
Set ms to be 0
alexd-bes 046ed8d
Fix tests
alexd-bes 6b84aab
Add task route test
alexd-bes 65998dc
Update packages/datatrak-web-server/src/routes/TasksRoute.ts
alexd-bes 3faa50e
Make custom column selector for due dates
alexd-bes d5f7ac7
Merge branch 'epic-tasks' into rn-1400-timezones-tasks
alexd-bes e1b914a
Update due date field
alexd-bes d0f75fd
build fixes
alexd-bes 406ed91
Build fixes
alexd-bes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd | ||
*/ | ||
import keyBy from 'lodash.keyby'; | ||
import { formatInTimeZone } from 'date-fns-tz'; | ||
import { ChangeHandler } from './ChangeHandler'; | ||
|
||
const getAnswerWrapper = (config, answers) => { | ||
|
@@ -71,6 +72,7 @@ export class TaskCreationHandler extends ChangeHandler { | |
|
||
for (const response of changedResponses) { | ||
const sr = await models.surveyResponse.findById(response.id); | ||
const { timezone } = sr; | ||
const questions = await getQuestions(models, response.survey_id); | ||
|
||
const taskQuestions = questions.filter(question => question.type === 'Task'); | ||
|
@@ -84,7 +86,7 @@ export class TaskCreationHandler extends ChangeHandler { | |
for (const taskQuestion of taskQuestions) { | ||
const config = taskQuestion.config.task; | ||
const getAnswer = getAnswerWrapper(config, answers); | ||
|
||
if ( | ||
!config || | ||
getAnswer('shouldCreateTask') === null || | ||
|
@@ -100,12 +102,29 @@ export class TaskCreationHandler extends ChangeHandler { | |
: getAnswer('entityId'); | ||
const surveyId = await getSurveyId(models, config); | ||
|
||
const dueDateAnswer = getAnswer('dueDate'); | ||
|
||
let dueDate = null; | ||
if (dueDateAnswer) { | ||
// Convert the due date to the timezone of the survey response and set the time to the last second of the day | ||
const dateInTimezone = formatInTimeZone( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a nice way of getting the end of day value for the timezone |
||
dueDateAnswer, | ||
timezone, | ||
"yyyy-MM-dd'T23:59:59'XXX", | ||
); | ||
|
||
// Convert the date to a timestamp | ||
const timestamp = new Date(dateInTimezone).getTime(); | ||
|
||
dueDate = timestamp; | ||
} | ||
|
||
await models.task.create({ | ||
initial_request_id: response.id, | ||
survey_id: surveyId, | ||
entity_id: entityId, | ||
assignee_id: getAnswer('assignee'), | ||
due_date: getAnswer('dueDate'), | ||
due_date: dueDate, | ||
status: 'to_do', | ||
}); | ||
} | ||
|
51 changes: 51 additions & 0 deletions
51
packages/database/src/migrations/20240809001011-ChangeTaskDueDateToUnix-modifies-schema.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
var dbm; | ||
var type; | ||
var seed; | ||
|
||
/** | ||
* We receive the dbmigrate dependency from dbmigrate initially. | ||
* This enables us to not have to rely on NODE_PATH. | ||
*/ | ||
exports.setup = function (options, seedLink) { | ||
dbm = options.dbmigrate; | ||
type = dbm.dataType; | ||
seed = seedLink; | ||
}; | ||
|
||
exports.up = async function (db) { | ||
return db.runSql(` | ||
ALTER TABLE task | ||
RENAME COLUMN due_date TO old_due_date; | ||
|
||
ALTER TABLE task | ||
ADD COLUMN due_date DOUBLE PRECISION; | ||
|
||
UPDATE task | ||
SET due_date = (EXTRACT(EPOCH FROM old_due_date) * 1000)::DOUBLE PRECISION; | ||
|
||
ALTER TABLE task | ||
DROP COLUMN old_due_date; | ||
`); | ||
}; | ||
|
||
exports.down = function (db) { | ||
return db.runSql(` | ||
ALTER TABLE task | ||
RENAME COLUMN due_date TO old_due_date; | ||
|
||
ALTER TABLE task | ||
ADD COLUMN due_date TIMESTAMP WITH TIME ZONE; | ||
|
||
UPDATE task | ||
SET due_date = to_timestamp(CAST(old_due_date AS DOUBLE PRECISION) / 1000); | ||
|
||
ALTER TABLE task | ||
DROP COLUMN old_due_date; | ||
`); | ||
}; | ||
|
||
exports._meta = { | ||
version: 1, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it just be easier if we didn't have all these tests to worry about and maintain ;)