1- import dayjs , { Dayjs } from "dayjs" ;
2- import utc from "dayjs/plugin/utc" ;
31import { ObjectId } from "mongodb" ;
42import { RRule } from "rrule" ;
53import { RRULE } from "@core/constants/core.constants" ;
@@ -10,11 +8,10 @@ import {
108 Schema_Event_Recur_Base ,
119 Schema_Event_Recur_Instance ,
1210} from "@core/types/event.types" ;
11+ import dayjs , { Dayjs } from "@core/util/date/dayjs" ;
1312import { GenericError } from "@backend/common/errors/generic/generic.errors" ;
1413import { error } from "@backend/common/errors/handlers/error.handler" ;
1514
16- dayjs . extend ( utc ) ;
17-
1815export const assembleInstances = (
1916 event : Schema_Event_Core ,
2017 baseId ?: string ,
@@ -36,19 +33,32 @@ export const assembleInstances = (
3633 return events ;
3734} ;
3835
39- export const stripBaseProps = ( base : Schema_Event_Recur_Base ) => {
40- const {
41- _id, // preserve existing event
42- gEventId, // strip this so instances remain unique
43- startDate, // dates changed during DB update
44- endDate, // dates changed during DB update
45- order, // preserve order
46- recurrence, // recurrence change during DB update
47- user, // preserve user
48- updatedAt, // changed during DB update
49- ...baseForUpdate // remaining event
50- } = base ;
51- return baseForUpdate ;
36+ export const stripBaseProps = (
37+ base : Schema_Event_Recur_Base ,
38+ ) : Omit <
39+ Schema_Event_Recur_Base ,
40+ | "_id"
41+ | "gEventId"
42+ | "startDate"
43+ | "endDate"
44+ | "order"
45+ | "recurrence"
46+ | "user"
47+ | "updatedAt"
48+ > => {
49+ const { allDayOrder, description, gRecurringEventId, isAllDay } = base ;
50+ const { isSomeday, origin, priority, title } = base ;
51+
52+ return {
53+ allDayOrder,
54+ description,
55+ gRecurringEventId,
56+ isAllDay,
57+ isSomeday,
58+ origin,
59+ priority,
60+ title,
61+ } ;
5262} ;
5363
5464const _generateInstances = (
@@ -221,36 +231,12 @@ const _getRule = (rule: string, startDate: string, endDate: string) => {
221231const _getNextStart = ( rule : string , startDate : string , endDate : string ) => {
222232 switch ( rule ) {
223233 case RRULE . WEEK :
224- return _getNextSunday ( startDate ) ;
234+ return dayjs ( startDate ) . startOfNextWeek ( ) ;
225235 break ;
226236 case RRULE . MONTH :
227- return _getNextMonth ( endDate ) ;
237+ return dayjs ( endDate ) . startOfNextMonth ( ) ;
228238 break ;
229239 default :
230240 throw error ( GenericError . DeveloperError , "Failed to get next start" ) ;
231241 }
232242} ;
233-
234- const _getNextMonth = ( target : string ) => {
235- const date = dayjs ( target , YEAR_MONTH_DAY_FORMAT ) . hour ( 0 ) . minute ( 0 ) . second ( 0 ) ;
236-
237- const firstOfNextMonth = date . add ( 1 , "month" ) . date ( 1 ) ;
238- return firstOfNextMonth ;
239- } ;
240-
241- const _getNextSunday = ( startDate : string ) => {
242- const date = dayjs ( startDate , YEAR_MONTH_DAY_FORMAT )
243- . hour ( 0 )
244- . minute ( 0 )
245- . second ( 0 ) ;
246-
247- const dayOfWeek = date . day ( ) ;
248-
249- let daysUntilNextSunday = ( 7 - dayOfWeek ) % 7 ;
250- if ( daysUntilNextSunday === 0 ) {
251- daysUntilNextSunday = 7 ;
252- }
253-
254- const nextSunday = date . add ( daysUntilNextSunday , "day" ) ;
255- return nextSunday ;
256- } ;
0 commit comments