Skip to content

Commit 4a30a9b

Browse files
committed
formatting
1 parent c299a47 commit 4a30a9b

File tree

16 files changed

+178
-108
lines changed

16 files changed

+178
-108
lines changed

script/send-letters.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
const axios = require('axios');
2-
const letterData = require('./catchup.js');
1+
const axios = require('axios')
2+
const letterData = require('./catchup.js')
33

4-
(async () => {
4+
;(async () => {
55
const data = JSON.parse(letterData)
66

77
for (const transaction of data) {
88
try {
9-
const response = await axios.post('https://amplify-hooks-0194518485a8.herokuapp.com/api/checkout/process-transaction',
9+
const response = await axios.post(
10+
'https://amplify-hooks-0194518485a8.herokuapp.com/api/checkout/process-transaction',
1011
{
1112
data: {
1213
object: {
1314
id: transaction.stripe_id
1415
}
1516
},
16-
type: "payment_intent.succeeded"
17+
type: 'payment_intent.succeeded'
1718
}
1819
)
1920

@@ -22,4 +23,4 @@ const letterData = require('./catchup.js');
2223
console.error(error)
2324
}
2425
}
25-
})();
26+
})()

script/stringify.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@ const reps = JSON.stringify([
2626
2727
},
2828
{
29-
name:"Richelle Montoya",
30-
title:"Vice President of the Navajo Nation",
31-
photoUrl:"https://i0.wp.com/opvp.navajo-nsn.gov/wp-content/uploads/2023/12/photo_VP_Montoya.jpg?resize=1080%2C1080&ssl=1",
32-
address_line1:"PO Box 7440",
33-
address_line2:"",
34-
address_city:"Window Rock",
35-
address_state:"AZ",
36-
address_zip:"86515",
37-
address_country:"US",
38-
29+
name: 'Richelle Montoya',
30+
title: 'Vice President of the Navajo Nation',
31+
photoUrl:
32+
'https://i0.wp.com/opvp.navajo-nsn.gov/wp-content/uploads/2023/12/photo_VP_Montoya.jpg?resize=1080%2C1080&ssl=1',
33+
address_line1: 'PO Box 7440',
34+
address_line2: '',
35+
address_city: 'Window Rock',
36+
address_state: 'AZ',
37+
address_zip: '86515',
38+
address_country: 'US',
39+
3940
},
4041
{
4142
name: 'Ethel Branch',
@@ -234,7 +235,8 @@ const reps = JSON.stringify([
234235
},
235236
{
236237
name: 'Byron C. Shorty',
237-
title: 'Telecommunications Regulatory Commission Office, Acting Executive Director',
238+
title:
239+
'Telecommunications Regulatory Commission Office, Acting Executive Director',
238240
photoUrl:
239241
'https://i0.wp.com/opvp.navajo-nsn.gov/wp-content/uploads/2024/09/director_Shorty.jpg?resize=1080%2C1440&ssl=1',
240242
address_line1: 'PO Box 7440',
@@ -309,10 +311,9 @@ const reps = JSON.stringify([
309311
address_zip: '86515',
310312
address_country: 'US',
311313
email: ''
312-
}
314+
}
313315
])
314316

315-
316317
/*
317318
const assets = JSON.stringify({
318319
campaign_logo: 'https://i.imgur.com/o3lxGJD.png',

server/db/migrations/20240817143934_create_letter_templates_table.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ module.exports = {
1212
await knex.schema.alterTable('letters', (table) => {
1313
table.integer('letter_template_id').unsigned().notNullable()
1414
table.foreign('letter_template_id').references('letter_templates.id')
15-
table.enu('delivery_method', ['email', 'snail_mail'], {
16-
useNative: true,
17-
enumName: 'delivery_methods'
18-
}).notNullable()
15+
table
16+
.enu('delivery_method', ['email', 'snail_mail'], {
17+
useNative: true,
18+
enumName: 'delivery_methods'
19+
})
20+
.notNullable()
1921
table.string('email')
2022
})
2123

server/db/models/letter-template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ class LetterTemplate extends BaseModel {
1919
}
2020
}
2121

22-
module.exports = LetterTemplate
22+
module.exports = LetterTemplate

server/db/seeds/development/01-seed-letter_templates-table.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
async seed(knex) {
33
await knex('letter_templates').del()
4-
4+
55
await knex('letter_templates').insert([
66
{
77
id: 1,
@@ -35,4 +35,4 @@ module.exports = {
3535
}
3636
])
3737
}
38-
}
38+
}

server/db/seeds/development/02-seed-campaigns-table.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ module.exports = {
1313
type: 'Grant',
1414
page_url: 'https://example.com',
1515
letter_template_id: 1,
16-
campaign_tagline: 'Protecting our Woodlands and Rivers from the Big Beaver Menace',
17-
campaign_text: '<p>For years, Beavers in the Pacific Northwest have been getting more aggressive about damming rivers and gentrifying our beautiful rivers.</p><p>In recent years, they have started erecting large beaver shopping centers and abducting human children to use as low wage labor in their beaver malls!</p><p>With your help, we can stop the further encroachment of beavers into human habitats.</p>',
18-
supplemental_text: '<p>Did you know that PNW beavers are also all communists? Only with your help can we turn the tide and live in freedom and prosperity.</p>',
16+
campaign_tagline:
17+
'Protecting our Woodlands and Rivers from the Big Beaver Menace',
18+
campaign_text:
19+
'<p>For years, Beavers in the Pacific Northwest have been getting more aggressive about damming rivers and gentrifying our beautiful rivers.</p><p>In recent years, they have started erecting large beaver shopping centers and abducting human children to use as low wage labor in their beaver malls!</p><p>With your help, we can stop the further encroachment of beavers into human habitats.</p>',
20+
supplemental_text:
21+
'<p>Did you know that PNW beavers are also all communists? Only with your help can we turn the tide and live in freedom and prosperity.</p>',
1922
representatives: JSON.stringify([
2023
{
2124
name: 'Velma Dinkley',
2225
title: 'District 1 Supervisor',
23-
photoUrl:
24-
'https://placehold.co/250',
26+
photoUrl: 'https://placehold.co/250',
2527
address_line1: '123 Fake St.',
2628
address_line2: 'Suite 8B',
2729
address_city: 'Portland',
@@ -33,8 +35,7 @@ module.exports = {
3335
{
3436
name: 'Jar Jar Binks',
3537
title: 'District 2 Supervisor',
36-
photoUrl:
37-
'https://placehold.co/250',
38+
photoUrl: 'https://placehold.co/250',
3839
address_line1: '123 Fake St.',
3940
address_line2: 'Suite 9B',
4041
address_city: 'Portland',
@@ -46,8 +47,7 @@ module.exports = {
4647
{
4748
name: 'Fei Fong Wong',
4849
title: 'District 3 Supervisor',
49-
photoUrl:
50-
'https://placehold.co/250',
50+
photoUrl: 'https://placehold.co/250',
5151
address_line1: '123 Fake St.',
5252
address_line2: 'Suite 8B',
5353
address_city: 'Portland',
@@ -59,8 +59,7 @@ module.exports = {
5959
{
6060
name: 'Buccee Beaver',
6161
title: 'District 1 Supervisor',
62-
photoUrl:
63-
'https://placehold.co/250',
62+
photoUrl: 'https://placehold.co/250',
6463
address_line1: '123 Fake St.',
6564
address_line2: 'Suite 7F',
6665
address_city: 'Portland',
@@ -84,16 +83,11 @@ module.exports = {
8483
}
8584
]),
8685
assets: JSON.stringify({
87-
campaign_logo:
88-
'https://placehold.co/600x400',
89-
campaign_background:
90-
'https://placehold.co/1500x600',
91-
'campaign-img-1':
92-
'https://placehold.co/600x400',
93-
'campaign-img-2':
94-
'https://placehold.co/600x400',
95-
'campaign-img-3':
96-
'https://placehold.co/600x400'
86+
campaign_logo: 'https://placehold.co/600x400',
87+
campaign_background: 'https://placehold.co/1500x600',
88+
'campaign-img-1': 'https://placehold.co/600x400',
89+
'campaign-img-2': 'https://placehold.co/600x400',
90+
'campaign-img-3': 'https://placehold.co/600x400'
9791
})
9892
},
9993
{

server/lib/handlebars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ class Handlebars {
2020
}
2121
}
2222

23-
module.exports = Handlebars
23+
module.exports = Handlebars

server/lib/lob.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,29 @@ class Lob {
1515
constructor() {
1616
this.apiKey = process.env.LOB_API_KEY
1717
this.lobUrl = process.env.LOB_BASE_URL
18-
this.env = process.env.NODE_ENV
18+
this.env = process.env.NODE_ENV
1919
}
2020

2121
// auth headers
2222
authHeaders() {
2323
const encodedKey = btoa(`${this.apiKey}:`)
2424
console.log(encodedKey)
25-
25+
2626
return {
2727
Authorization: `Basic ${encodedKey}`
2828
}
2929
}
3030

3131
// Merges all headers
3232
headers() {
33-
return {...this.authHeaders()}
33+
return { ...this.authHeaders() }
3434
}
3535

3636
async template(id) {
3737
try {
38-
const letters = await axios.get(
39-
`${this.lobUrl}/templates/${id}`,
40-
{
41-
headers: this.headers()
42-
}
43-
)
38+
const letters = await axios.get(`${this.lobUrl}/templates/${id}`, {
39+
headers: this.headers()
40+
})
4441

4542
return letters.data.published_version
4643
} catch (err) {
@@ -63,7 +60,6 @@ class Lob {
6360
return { response: 200, payload }
6461
}
6562

66-
6763
const response = await axios.post({
6864
url: `${this.lobUrl}/letters}`,
6965
headers: this.headers(),
@@ -72,7 +68,7 @@ class Lob {
7268
})
7369

7470
return response.data
75-
} catch(err) {
71+
} catch (err) {
7672
throw new LobError(err.message)
7773
}
7874
}
@@ -95,7 +91,7 @@ class Lob {
9591
})
9692

9793
return addr.data
98-
} catch(err) {
94+
} catch (err) {
9995
throw new LobError(err.message)
10096
}
10197
}
@@ -110,7 +106,7 @@ class Lob {
110106
address_line2: verifiedAddress.secondary_line,
111107
address_city: verifiedAddress.components.city,
112108
address_state: verifiedAddress.components.state,
113-
address_zip: verifiedAddress.components.zip_code,
109+
address_zip: verifiedAddress.components.zip_code
114110
}
115111

116112
try {
@@ -121,11 +117,10 @@ class Lob {
121117
})
122118

123119
return addr.data
124-
} catch(err) {
120+
} catch (err) {
125121
throw new LobError(err.message)
126122
}
127123
}
128124
}
129125

130-
131-
module.exports = { Lob, LobError }
126+
module.exports = { Lob, LobError }

server/lib/sendgrid.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ class Sendgrid {
1717
this.env = process.env.NODE_ENV
1818

1919
this.sgMail = sgMail
20-
this.sgClient = sgClient
20+
this.sgClient = sgClient
2121
this.sgMail.setApiKey(this.apiKey)
2222
this.sgClient.setApiKey(this.apiKey)
2323
}
2424

2525
async template(id) {
26-
const params = { method: 'GET', url: `/v3/templates/${id}`}
26+
const params = { method: 'GET', url: `/v3/templates/${id}` }
2727

2828
try {
2929
const response = await this.sgClient.request(params)
@@ -39,9 +39,7 @@ class Sendgrid {
3939
if (this.env != 'production') {
4040
return { response: 200, payload }
4141
}
42-
43-
4442
}
4543
}
4644

47-
module.exports = { Sendgrid, SendgridError}
45+
module.exports = { Sendgrid, SendgridError }

server/routes/api/checkout.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,16 @@ router.post('/create-checkout-session', async (req, res) => {
5656

5757
// Using a temporary mapping here also
5858
// Re-render the letter html, merging user data to be saved in case that's in the template.
59-
letter.merge_variables = { ...letter.merge_variables, firstName: user.firstName, lastName: user.lastName }
60-
const template = await LetterTemplate.query().findById(letter.letter_template_id)
59+
letter.merge_variables = {
60+
...letter.merge_variables,
61+
firstName: user.firstName,
62+
lastName: user.lastName
63+
}
64+
const template = await LetterTemplate.query().findById(
65+
letter.letter_template_id
66+
)
6167
const html = Handlebars.render(letter.merge_variables, template.html)
62-
68+
6369
// Using a temporary mapping here also
6470
for (const method of deliveryMethods) {
6571
// Generate a uuid so letters are idempotent
@@ -114,10 +120,16 @@ router.post('/create-checkout-session', async (req, res) => {
114120
})
115121

116122
// Re-render the letter html, merging user data to be saved in case that's in the template.
117-
letter.merge_variables = { ...letter.merge_variables, firstName: user.firstName, lastName: user.lastName }
118-
const template = await LetterTemplate.query().findById(letter.letter_template_id)
123+
letter.merge_variables = {
124+
...letter.merge_variables,
125+
firstName: user.firstName,
126+
lastName: user.lastName
127+
}
128+
const template = await LetterTemplate.query().findById(
129+
letter.letter_template_id
130+
)
119131
const html = Handlebars.render(letter.merge_variables, template.html)
120-
132+
121133
// Using a temporary mapping here also
122134
for (const method of deliveryMethods) {
123135
// Generate a uuid so letters are idempotent
@@ -188,19 +200,23 @@ router.post('/process-transaction', async (req, res) => {
188200
)
189201
}
190202

191-
const transaction = await Transaction.query().findOne({ stripe_transaction_id: paymentIntent })
203+
const transaction = await Transaction.query().findOne({
204+
stripe_transaction_id: paymentIntent
205+
})
192206
await transaction.$query().patch({ status: eventOutcome })
193207

194-
const letter = await Letter.query().where({ transaction_id: transaction.id }).first()
208+
const letter = await Letter.query()
209+
.where({ transaction_id: transaction.id })
210+
.first()
195211
letter.trackingNumber = uuidv4()
196212
const letterTemplate = JSON.parse(letter.letterTemplate)
197-
213+
198214
const lobApiKey = process.env.LOB_API_KEY
199215
const lobCredentials = btoa(`${lobApiKey}:`)
200216

201217
console.log(letter.mergeVariables)
202218
const lobResponse = await axios.post(
203-
'https://api.lob.com/v1/letters',
219+
'https://api.lob.com/v1/letters',
204220
{
205221
to: {
206222
name: letter.addressee,
@@ -226,7 +242,7 @@ router.post('/process-transaction', async (req, res) => {
226242

227243
if (!lobResponse.statusCode === 200) throw new CheckoutError(lobResponse)
228244

229-
await letter.$query().patch({ sent: true})
245+
await letter.$query().patch({ sent: true })
230246

231247
return res.status(201).end()
232248
} catch (error) {

0 commit comments

Comments
 (0)