| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- const { default: initModels } = require('./models/init-models')
-
- module.exports = {
- /**
- * Grabs the actual row information as JSON
- * and packs it up into an array
- *
- * @param {array} postList
- * @param {string} typeToFind
- * @returns array
- */
- getPostData: (postList, typeToFind) => {
- return postList.reduce((data, post) => {
- /**
- * Double-check our post matches the type
- */
- if(typeToFind && post.dataValues.post_type != typeToFind) {
- return data
- }
-
- /**
- * ONLY add matching postData to our data array
- * and omit all the extra sequelize meta data
- * by pushing the dataValues key
- */
- data.push(post.dataValues)
- return data
- }, [])
- },
-
- /**
- * Helper to find post descendants
- *
- * @param {array} parentList
- * @param {object} db - sequelize instance
- * @param {function} getParams - lambda returning param object { rule: 'example' }
- * @returns array
- */
- findDescendants: async (parentList, db, getParams) => {
- const matchList = []
- for(let post of parentList) {
- const match = await db.findAll({ where: getParams(post) })
- match.forEach(entity => matchList.push(entity))
- }
- return matchList
- },
-
- /**
- * The keys we want from the postmeta table
- */
- metakeys: [
- '_wp_attached_file',
- '_wp_attachment_metadata',
- '_thumbnail_id',
- ...process.env.METAKEYS
- ],
-
- /**
- * The post type names we're interested in
- *
- * 1. Status types we migrate
- */
- types: {
- ...process.env.POST_TYPES,
- /* 1 */
- status: ['publish']
- },
-
- /**
- * dB creation helper
- * !: Don't touch
- *
- * @param {object} models - sequelize instance
- * @returns object - all models associated with instance
- */
- db: models => initModels(models),
- }
|