forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdmarc-summary.js
More file actions
83 lines (81 loc) · 2.72 KB
/
dmarc-summary.js
File metadata and controls
83 lines (81 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { GraphQLObjectType } from 'graphql'
import { globalIdField } from 'graphql-relay'
import { categoryPercentagesType } from './category-percentages'
import { categoryTotalsType } from './category-totals'
import { detailTablesType } from './detail-tables'
import { domainType } from '../../domain/objects'
import { PeriodEnums } from '../../enums'
import { Year } from '../../scalars'
import { nodeInterface } from '../../node'
export const dmarcSummaryType = new GraphQLObjectType({
name: 'DmarcSummary',
description: 'Object that contains information for a dmarc summary.',
fields: () => ({
id: globalIdField('dmarcSummary'),
domain: {
type: domainType,
description: 'The domain that the data in this dmarc summary belongs to.',
resolve: async (
{ domainKey },
_args,
{ loaders: { loadDomainByKey } },
) => {
const domain = await loadDomainByKey.load(domainKey)
return domain
},
},
month: {
type: PeriodEnums,
description: 'Start date of data collection.',
resolve: ({ startDate }, _, { moment }) => {
let month
if (startDate === 'thirtyDays') {
month = moment().month()
} else {
month = moment(startDate).month()
}
return String(moment().month(month).format('MMMM')).toLowerCase()
},
},
year: {
type: Year,
description: 'End date of data collection.',
resolve: ({ startDate }, _, { moment }) => {
let year
if (startDate === 'thirtyDays') {
year = String(moment().year())
} else {
year = String(moment(startDate).year())
}
return year
},
},
categoryPercentages: {
type: categoryPercentagesType,
description: 'Category percentages based on the category totals.',
resolve: async ({ _id }, _, { loaders: { loadDmarcSummaryByKey } }) => {
const dmarcSummaryKey = _id.split('/')[1]
const dmarcSummary = await loadDmarcSummaryByKey.load(dmarcSummaryKey)
return {
totalMessages: dmarcSummary.totalMessages,
...dmarcSummary.categoryPercentages,
}
},
},
categoryTotals: {
type: categoryTotalsType,
description: 'Category totals for quick viewing.',
resolve: async ({ _id }, _, { loaders: { loadDmarcSummaryByKey } }) => {
const dmarcSummaryKey = _id.split('/')[1]
const dmarcSummary = await loadDmarcSummaryByKey.load(dmarcSummaryKey)
return dmarcSummary.categoryTotals
},
},
detailTables: {
type: detailTablesType,
description: 'Various senders for each category.',
resolve: ({ _id }) => ({ _id }),
},
}),
interfaces: [nodeInterface],
})