You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update constituent table to include a notifications table of preferences
Background info
Data types in constituent table:
name is a string
Street address, City, and State are strings
Zipcode is a string
Letters sent holds an array of ids of letter that was successfully posted with - Lob (payment and address verification went through)
User agreement is a boolean that they abide by the platforms outlined = community safety and protection guidelines
Updates is sending campaign_id so that we can send to advocacy groups so they can follow up and by our user education team
Notifications table from Updates field in constituent table:
string message
date to be sent out
campaign id (we'll draw the letter from here)
Directions:
*Note that you will need to import the knex object and the express middleware in your Express app for this code to work.
To create a table for updates in the constituent table that includes a string message, date, and campaign id, you can create a new migration file using Knex. Here are the steps you can follow:
1.Create a new migration file using the Knex CLI: npx knex migrate:make create_updates_table
2. In the new migration file, create a new table called updates with columns for the message, date, and campaign id:
This code creates a new table called updates with columns for the message, date, campaign id, constituent id, and timestamps.
3. Run the migration to create the updates table: npx knex migrate:latest
4. In your Express app, modify the route that updates the constituent table to also insert a new row into the updates table:
router.post('/update-constituent', async (req, res) => {
const { id, message, campaign_id } = req.body
try {
// Update the constituent table
await knex('constituent').where({ id }).update({ message })
// Insert a new row into the updates table
await knex('updates').insert({
message,
date: new Date(),
campaign_id,
constituent_id: id
})
res.sendStatus(200)
} catch (error) {
console.error(error)
res.status(500).send('Internal server error')
}
})
This code updates the constituent table with the new message, and then inserts a new row into the updates table with the message, current date, campaign id, and constituent id.
The text was updated successfully, but these errors were encountered:
Update constituent table to include a notifications table of preferences
Background info
Data types in constituent table:
Notifications table from Updates field in constituent table:
Directions:
*Note that you will need to import the knex object and the express middleware in your Express app for this code to work.
To create a table for updates in the constituent table that includes a string message, date, and campaign id, you can create a new migration file using Knex. Here are the steps you can follow:
npx knex migrate:make create_updates_table
This code creates a new table called updates with columns for the message, date, campaign id, constituent id, and timestamps.
npx knex migrate:latest
This code updates the constituent table with the new message, and then inserts a new row into the updates table with the message, current date, campaign id, and constituent id.
The text was updated successfully, but these errors were encountered: