Skip to content

Commit a18a198

Browse files
committed
fix(resolvers): improve create rule data validation
1 parent b09de06 commit a18a198

3 files changed

Lines changed: 8 additions & 28 deletions

File tree

src/resolvers/projectNotifications.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export default {
107107
{ user, factories }: ResolverContextWithUser
108108
): Promise<ProjectNotificationsRuleDBScheme> {
109109
const project = await factories.projectsFactory.findById(input.projectId);
110+
const validThresholdPeriods = [60_000, 3_600_000, 86_400_000, 604_800_000]
110111

111112
if (!project) {
112113
throw new ApolloError('No project with such id');
@@ -116,6 +117,10 @@ export default {
116117
throw new UserInputError('At least one channel is required');
117118
}
118119

120+
if (!validThresholdPeriods.includes(input.thresholdPeriod)) {
121+
throw new UserInputError('Threshold period should be one of the following: 60000, 3600000, 86400000, 604800000');
122+
}
123+
119124
return project.createNotificationsRule({
120125
...input,
121126
uidAdded: user.id,

src/typeDefs/projectNotifications.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,6 @@ export default gql`
1616
SEEN_MORE
1717
}
1818
19-
"""
20-
Allowed threshold periods in milliseconds
21-
"""
22-
enum ThresholdPeriod {
23-
"""
24-
One minute in milliseconds
25-
"""
26-
MINUTE = 60000
27-
28-
"""
29-
One hour in milliseconds
30-
"""
31-
HOUR = 3600000
32-
33-
"""
34-
One day in milliseconds
35-
"""
36-
DAY = 86400000
37-
38-
"""
39-
One week in milliseconds
40-
"""
41-
WEEK = 604800000
42-
}
43-
4419
"""
4520
Project notify settings
4621
"""
@@ -83,6 +58,6 @@ export default gql`
8358
"""
8459
Period to receive notification
8560
"""
86-
thresholdPeriod: ThresholdPeriod
61+
thresholdPeriod: Int
8762
}
8863
`;

src/typeDefs/projectNotificationsMutations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default gql`
4343
"""
4444
Period to receive notification
4545
"""
46-
thresholdPeriod: ThresholdPeriod
46+
thresholdPeriod: Int
4747
}
4848
4949
"""
@@ -93,7 +93,7 @@ export default gql`
9393
"""
9494
Period to receive notification
9595
"""
96-
thresholdPeriod: ThresholdPeriod
96+
thresholdPeriod: Int
9797
}
9898
9999
"""

0 commit comments

Comments
 (0)