-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlocalFormsService.js
More file actions
56 lines (50 loc) · 1.75 KB
/
localFormsService.js
File metadata and controls
56 lines (50 loc) · 1.75 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
import { config } from '~/src/config/index.js'
import { FileFormService } from '~/src/server/utils/file-form-service.js'
// Create shared form metadata
const now = new Date()
const user = { id: 'user', displayName: 'Username' }
const author = {
createdAt: now,
createdBy: user,
updatedAt: now,
updatedBy: user
}
const metadata = {
organisation: 'Defra',
teamName: 'Team name',
teamEmail: 'team@defra.gov.uk',
submissionGuidance: "Thanks for your submission, we'll be in touch",
notificationEmail: config.get('submissionEmailAddress'),
...author,
live: author
}
/**
* Return an function rather than the service directly. This is to prevent consumer applications
* blowing up as they won't have these files on disk. We can defer the execution until when it's
* needed, i.e. the createServer function of the devtool.
*/
export const formsService = async () => {
// Instantiate the file loader form service
const loader = new FileFormService()
// Add a Json form
await loader.addForm('src/server/forms/register-as-a-unicorn-breeder.json', {
...metadata,
id: '95e92559-968d-44ae-8666-2b1ad3dffd31',
title: 'Register as a unicorn breeder',
slug: 'register-as-a-unicorn-breeder'
})
// Add a Yaml form
await loader.addForm('src/server/forms/register-as-a-unicorn-breeder.yaml', {
...metadata,
id: '641aeafd-13dd-40fa-9186-001703800efb',
title: 'Register as a unicorn breeder (yaml)',
slug: 'register-as-a-unicorn-breeder-yaml' // if we needed to validate any JSON logic, make it available for convenience
})
await loader.addForm('src/server/forms/components.json', {
...metadata,
id: '6a872d3b-13f9e-804ce3e-4830-5c45fb32',
title: 'Components',
slug: 'components'
})
return loader.toFormsService()
}