Skip to content

Commit c12d8bf

Browse files
Merge pull request #339 from lara-learning/feat/split-days
feat: split days
2 parents 3668584 + 78464c4 commit c12d8bf

27 files changed

+442
-150
lines changed

packages/alexa/src/helpers/report.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Report, Day, Entry } from '@lara/api'
22
import { getLaraConfig } from '../graphql/config'
33

4-
type ReducedDay = Pick<Day, 'id' | 'status'> & { entries: Pick<Entry, 'time'>[] }
4+
type ReducedDay = Pick<Day, 'id' | 'status'> & { entries: Pick<Entry, 'time' | 'time_split'>[] }
55

6-
const totalDayMinutes = (day: ReducedDay) => day.entries.reduce((acc, entry) => acc + entry.time, 0)
6+
const totalDayMinutes = (day: ReducedDay) =>
7+
day.entries.reduce((acc, entry) => acc + (entry.time ? entry.time : entry.time_split!), 0)
78

89
export const finishedDays = async (days: ReducedDay[]): Promise<number> => {
910
const config = await getLaraConfig()

packages/api/schema.gql

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Day implements CommentableInterface {
4646
entries: [Entry!]!
4747
id: ID!
4848
status: DayStatusEnum
49+
status_split: DayStatusEnum
4950
}
5051

5152
enum DayStatusEnum {
@@ -87,13 +88,17 @@ type Entry implements CommentableInterface {
8788
createdAt: String!
8889
id: ID!
8990
orderId: Int!
90-
text: String!
91-
time: Int!
91+
text: String
92+
time: Int
93+
text_split: String
94+
time_split: Int
9295
}
9396

9497
input EntryInput {
95-
text: String!
96-
time: Int!
98+
text: String
99+
time: Int
100+
text_split: String
101+
time_split: Int
97102
}
98103

99104
type OAuthPayload {
@@ -212,7 +217,7 @@ type Mutation {
212217
"""
213218
Updates day which is identified by the id argument.
214219
"""
215-
updateDay(status: String, id: ID!): Day
220+
updateDay(status: String, status_split: String, id: ID!): Day
216221
updateEntry(id: ID!, input: EntryInput!): MutateEntryPayload!
217222
updateEntryOrder(entryId: ID!, dayId: ID!, orderId: Int!): MutateEntryPayload!
218223

packages/api/src/graphql.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export type GqlDay = GqlCommentableInterface & {
9393
entries: Array<GqlEntry>;
9494
id: Scalars['ID']['output'];
9595
status?: Maybe<GqlDayStatusEnum>;
96+
status_split?: Maybe<GqlDayStatusEnum>;
9697
};
9798

9899
export type GqlDayStatusEnum =
@@ -125,13 +126,17 @@ export type GqlEntry = GqlCommentableInterface & {
125126
createdAt: Scalars['String']['output'];
126127
id: Scalars['ID']['output'];
127128
orderId: Scalars['Int']['output'];
128-
text: Scalars['String']['output'];
129-
time: Scalars['Int']['output'];
129+
text?: Maybe<Scalars['String']['output']>;
130+
text_split?: Maybe<Scalars['String']['output']>;
131+
time?: Maybe<Scalars['Int']['output']>;
132+
time_split?: Maybe<Scalars['Int']['output']>;
130133
};
131134

132135
export type GqlEntryInput = {
133-
text: Scalars['String']['input'];
134-
time: Scalars['Int']['input'];
136+
text?: InputMaybe<Scalars['String']['input']>;
137+
text_split?: InputMaybe<Scalars['String']['input']>;
138+
time?: InputMaybe<Scalars['Int']['input']>;
139+
time_split?: InputMaybe<Scalars['Int']['input']>;
135140
};
136141

137142
export type GqlLaraConfig = {
@@ -389,6 +394,7 @@ export type GqlMutationUpdateCurrentUserArgs = {
389394
export type GqlMutationUpdateDayArgs = {
390395
id: Scalars['ID']['input'];
391396
status?: InputMaybe<Scalars['String']['input']>;
397+
status_split?: InputMaybe<Scalars['String']['input']>;
392398
};
393399

394400

@@ -854,6 +860,7 @@ export type GqlDayResolvers<ContextType = Context, ParentType extends GqlResolve
854860
entries?: Resolver<Array<GqlResolversTypes['Entry']>, ParentType, ContextType>;
855861
id?: Resolver<GqlResolversTypes['ID'], ParentType, ContextType>;
856862
status?: Resolver<Maybe<GqlResolversTypes['DayStatusEnum']>, ParentType, ContextType>;
863+
status_split?: Resolver<Maybe<GqlResolversTypes['DayStatusEnum']>, ParentType, ContextType>;
857864
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
858865
}>;
859866

@@ -873,8 +880,10 @@ export type GqlEntryResolvers<ContextType = Context, ParentType extends GqlResol
873880
createdAt?: Resolver<GqlResolversTypes['String'], ParentType, ContextType>;
874881
id?: Resolver<GqlResolversTypes['ID'], ParentType, ContextType>;
875882
orderId?: Resolver<GqlResolversTypes['Int'], ParentType, ContextType>;
876-
text?: Resolver<GqlResolversTypes['String'], ParentType, ContextType>;
877-
time?: Resolver<GqlResolversTypes['Int'], ParentType, ContextType>;
883+
text?: Resolver<Maybe<GqlResolversTypes['String']>, ParentType, ContextType>;
884+
text_split?: Resolver<Maybe<GqlResolversTypes['String']>, ParentType, ContextType>;
885+
time?: Resolver<Maybe<GqlResolversTypes['Int']>, ParentType, ContextType>;
886+
time_split?: Resolver<Maybe<GqlResolversTypes['Int']>, ParentType, ContextType>;
878887
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
879888
}>;
880889

packages/backend/src/resolvers/day.resolver.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const dayResolver: GqlResolvers<AuthenticatedContext> = {
1515

1616
export const dayTraineeResolver: GqlResolvers<TraineeContext> = {
1717
Mutation: {
18-
updateDay: async (_parent, { id, status }, { currentUser }) => {
18+
updateDay: async (_parent, { id, status, status_split }, { currentUser }) => {
1919
const reports = await reportsWithinApprenticeship(currentUser)
2020

2121
const { report, day } = reportDayByDayId(id, reports)
@@ -37,15 +37,13 @@ export const dayTraineeResolver: GqlResolvers<TraineeContext> = {
3737
throw new GraphQLError(t('errors.wrongDayStatus'))
3838
}
3939

40-
if (!status || !isDayStatus(status) || status === 'holiday') {
41-
throw new GraphQLError(t('errors.wrongDayStatus'))
42-
}
40+
if (status && isDayStatus(status)) day.status = status
4341

4442
if (status === 'vacation' || status === 'sick') {
4543
day.entries = []
4644
}
4745

48-
day.status = status
46+
if (status_split && isDayStatus(status_split)) day.status_split = status_split
4947

5048
await updateReport(report, { updateKeys: ['days'] })
5149

packages/backend/src/resolvers/entry.resolver.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export const entryTraineeResolver: GqlResolvers<TraineeContext> = {
1818
report.days.forEach((day) => {
1919
day.entries.forEach((entry) => {
2020
const text = entry.text
21-
tmp[text] = tmp[text] ? tmp[text] + 1 : 1
21+
tmp[text ? text : entry.text_split!] = tmp[text ? text : entry.text_split!]
22+
? tmp[text ? text : entry.text_split!] + 1
23+
: 1
2224
})
2325
})
2426
})
@@ -99,6 +101,8 @@ export const entryTraineeResolver: GqlResolvers<TraineeContext> = {
99101

100102
entry.text = input.text
101103
entry.time = input.time
104+
entry.text_split = input.text_split
105+
entry.time_split = input.time_split
102106

103107
await updateReport(report, { updateKeys: ['days'] })
104108

packages/backend/src/resolvers/trainee.resolver.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@ export const traineeTraineeResolver: GqlResolvers<TraineeContext> = {
6565
reports.forEach((report) => {
6666
report.days.forEach((day) => {
6767
day.entries.forEach((entry) => {
68-
const { text, time } = entry
69-
70-
if (!textCountsWithTime[text]) {
71-
textCountsWithTime[text] = { count: 0, duration: time, text: text }
68+
const { text, time, text_split, time_split } = entry
69+
70+
if (!textCountsWithTime[text ? text : text_split!]) {
71+
textCountsWithTime[text ? text : text_split!] = {
72+
count: 0,
73+
duration: time ? time : time_split!,
74+
text: text ? text : text_split!,
75+
}
7276
}
73-
textCountsWithTime[text].count += 1
74-
textCountsWithTime[text].duration = time
77+
textCountsWithTime[text ? text : text_split!].count += 1
78+
textCountsWithTime[text ? text : text_split!].duration = time ? time : time_split!
7579
})
7680
})
7781
})

packages/backend/src/services/day.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const dayMinutes = (day: Day): number => {
9898
const status = dayStatus(day)
9999

100100
if (status === 'education' || status === 'work') {
101-
return day.entries.reduce((accumulator, entry) => accumulator + entry.time, 0)
101+
return day.entries.reduce((accumulator, entry) => accumulator + (entry.time ? entry.time : entry.time_split!), 0)
102102
} else {
103103
return 0
104104
}

packages/backend/src/services/entry.service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,17 @@ export const validateEntryUpdate = (report: Report, day: Day, newEntry: Entry, l
8080
entries: day.entries.filter((d) => d.id !== newEntry.id),
8181
})
8282

83-
if (day.status === 'work' && minutes + newEntry.time > LaraConfig.maxWorkDayMinutes) {
83+
if (
84+
day.status === 'work' &&
85+
minutes + (newEntry.time ? newEntry.time : newEntry.time_split!) > LaraConfig.maxWorkDayMinutes
86+
) {
8487
throw new GraphQLError(t('errors.dayTimeLimit'))
8588
}
8689

87-
if (day.status === 'education' && minutes + newEntry.time > LaraConfig.maxEducationDayMinutes) {
90+
if (
91+
day.status === 'education' &&
92+
minutes + (newEntry.time ? newEntry.time : newEntry.time_split!) > LaraConfig.maxEducationDayMinutes
93+
) {
8894
throw new GraphQLError(t('errors.dayTimeLimit'))
8995
}
9096

packages/backend/src/services/print.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export const createPrintUserData = async (trainee: Trainee): Promise<PrintUserDa
6060
* @returns Entry for print
6161
*/
6262
const transformEntry = (entry: Entry): PrintEntry => ({
63-
text: entry.text,
64-
time: entry.time,
63+
text: entry.text ? entry.text : entry.text_split!,
64+
time: entry.time ? entry.time : entry.time_split!,
6565
orderId: entry.orderId,
6666
})
6767

packages/components/src/entry-input-layout.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ export const EntryInputLayout: React.FC<EntryInputLayoutProps> = ({
199199
clickHandler,
200200
...rest
201201
}) => {
202-
console.log(term)
203202
return (
204203
<>
205204
<StyledEntryContainer {...rest}>

0 commit comments

Comments
 (0)