Skip to content

Conversation

@manuelurenah
Copy link
Contributor

@manuelurenah manuelurenah commented Jun 18, 2019

Description

  • Adds page events columns (publishedAt, republishedAt, archivedAt and unpublishedAt) to the public pages table in postgres
  • Adds migration script to populate these values from previous entries
  • Modifies putMeta method to send the data when meta is modified
  • This is part of Additional Columns #33

QA

In order to be able to test this feature, you should link this package and #49 in a clay project. I've been using https://github.com/clay/clay-starter to develop this feature, that's a good starting point.

Testing steps

  1. Go inside a clay project directory (i.e.: clay-starter)
  2. Spin up an instance of clay with make
  3. Open another terminal window or tab and make sure adminer is up and running using docker-compose up -d adminer
  4. Bootstrap the starter data with make bootstrap (where the Makefile is located)
  5. Make your way into the app directory (or where the package.json file is located) and link the previously mentioned packages with npm link amphora-storage-postgres (make sure the packages are in the correct branch and linked)
  6. Restart the clay instance with rs. After it's done, you should see a message stating Migrations Complete
  7. Go into http://localhost:8080 and login the db (system, server, username and database are all postgres; password is example)
  8. Check that the schema of the pages table have the following columns: published_at, unpublished_at, archive_at and republished_at
  9. You should be able to see in the pages table entries with all the previous columns plus the new ones.
  10. You should be able to update, publish, archive and everything else without any problems


// If we have history data, then find the unpublish and archive events
if (parsedValue.history && parsedValue.history.length) {
const latestUnpublish = parsedValue.history
Copy link

@pedro-rosario pedro-rosario Jun 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could abstract this logic into a small function

Suggested change
const latestUnpublish = parsedValue.history
const latestUnpublish = getLatestActionByName(parsedValue.history, 'unpublish'),
latestArchived = getLatestActionByName(parsedValue.history, 'archive')
function getLatestActionByName(history = [], action) {
  return history
    .filter(event => event.action === action)
    .pop() || {};
}

/**
* Gets the latest entry in the history based on the action
* @param {Object[]} history
* @param {String} action

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param {String} action
* @param {string} action

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convention is to have String capitalize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants