mirror of https://github.com/ghostfolio/ghostfolio
11 changed files with 122 additions and 11 deletions
@ -0,0 +1,32 @@ |
|||||
|
import { Type as ActivityType } from '@prisma/client'; |
||||
|
import { endOfToday, isAfter } from 'date-fns'; |
||||
|
|
||||
|
const ACTIVITY_TYPES_NEVER_DRAFT: ActivityType[] = [ |
||||
|
'FEE', |
||||
|
'INTEREST', |
||||
|
'LIABILITY' |
||||
|
]; |
||||
|
|
||||
|
export function isDraftTagToBeAssigned({ |
||||
|
date, |
||||
|
endOfTodayDate = endOfToday(), |
||||
|
storedDate, |
||||
|
type |
||||
|
}: { |
||||
|
date: Date; |
||||
|
endOfTodayDate?: Date; |
||||
|
storedDate?: Date; |
||||
|
type: ActivityType; |
||||
|
}) { |
||||
|
if (ACTIVITY_TYPES_NEVER_DRAFT.includes(type)) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
if (!isAfter(date, endOfTodayDate)) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
// Assign only when the date newly moves into the future, so that a tag the
|
||||
|
// user has removed is not restored by an unrelated change
|
||||
|
return storedDate ? !isAfter(storedDate, endOfTodayDate) : true; |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
-- Create the "DRAFT" tag if it does not exist yet |
||||
|
INSERT INTO "Tag" ("id", "name") |
||||
|
VALUES ('0c077abd-eca2-4cbb-818c-6cefbf2d169a', 'DRAFT') |
||||
|
ON CONFLICT DO NOTHING; |
||||
|
|
||||
|
-- Migrate activities with "isDraft" to the "DRAFT" tag |
||||
|
INSERT INTO "_OrderToTag" ("A", "B") |
||||
|
SELECT |
||||
|
"id", |
||||
|
'0c077abd-eca2-4cbb-818c-6cefbf2d169a' |
||||
|
FROM "Order" |
||||
|
WHERE "isDraft" = true |
||||
|
ON CONFLICT DO NOTHING; |
||||
Loading…
Reference in new issue