<commit_before>const Sequelize = require('sequelize')
const db = require('../db')

const User = require('./user')
const Task = require('./task')

const List = db.define('list', {
  id: {
    primaryKey: true,
    type: Sequelize.UUID,
    defaultValue: Sequelize.UUIDV4,
  },
  name: Sequelize.STRING,
  // unlimited. Might have to truncate in the controller.
  notes: Sequelize.TEXT,

  // only works in postgres? do we want to support other databases?
  order: {
    type: Sequelize.ARRAY(Sequelize.UUID),
    defaultValue: []
  }
}, {
  hooks: {
    beforeBulkDestroy: function(options) {
      options.individualHooks = true
      return options
    },
    beforeDestroy: async function(list) {
      // for whatever reason, cascade doesn't work
      await list.setUsers(null)
      await Task.destroy({
        where: {
          listId: list.id
        }
      })
    }
  }
})

User.hook('afterCreate', async function(user, options) {
  const inbox = await List.create({
    name: 'nitrosys-inbox'
  })
  await inbox.addUser(user)
})

// for the future when we can have shared lists
List.belongsToMany(User, {through: 'listaccess'})
List.hasMany(Task)

module.exports = List<commit_msg>Change .hook to .addHook<commit_after>const Sequelize = require('sequelize')
const db = require('../db')

const User = require('./user')
const Task = require('./task')

const List = db.define(
  'list',
  {
    id: {
      primaryKey: true,
      type: Sequelize.UUID,
      defaultValue: Sequelize.UUIDV4
    },
    name: Sequelize.STRING,
    // unlimited. Might have to truncate in the controller.
    notes: Sequelize.TEXT,

    // only works in postgres? do we want to support other databases?
    order: {
      type: Sequelize.ARRAY(Sequelize.UUID),
      defaultValue: []
    }
  },
  {
    hooks: {
      beforeBulkDestroy: function(options) {
        options.individualHooks = true
        return options
      },
      beforeDestroy: async function(list) {
        // for whatever reason, cascade doesn't work
        await list.setUsers(null)
        await Task.destroy({
          where: {
            listId: list.id
          }
        })
      }
    }
  }
)

User.addHook('afterCreate', async function(user, options) {
  const inbox = await List.create({
    name: 'nitrosys-inbox'
  })
  await inbox.addUser(user)
})

// for the future when we can have shared lists
List.belongsToMany(User, { through: 'listaccess' })
List.hasMany(Task)

module.exports = List

{'fraction_non_alphanumeric': 0.1242914979757085, 'fraction_numerical': 0.0008097165991902834, 'mean_word_length': 2.649926144756278, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6842759', 'n_tokens_mistral': 793, 'n_tokens_neox': 786, 'n_words': 201}