log.js 838 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. let routes = [
  2. 'index',
  3. 'search',
  4. 'settingsAccount',
  5. 'settingsGeneral',
  6. 'thread',
  7. 'threadNew',
  8. 'userPosts',
  9. 'userThreads'
  10. ]
  11. module.exports = (sequelize, DataTypes) => {
  12. let Log = sequelize.define('Log', {
  13. route: {
  14. type: DataTypes.ENUM(routes),
  15. validate: {
  16. isIn: {
  17. args: [routes],
  18. msg: "route does not exist"
  19. }
  20. }
  21. }
  22. }, {
  23. classMethods: {
  24. associate (models) {
  25. //Resources corresponding to the route
  26. //I.e. route userPosts and UserId 3
  27. //Corresponds to /user/[username for id 3]/posts
  28. Log.belongsTo(models.Thread)
  29. Log.belongsTo(models.User)
  30. //Rather than id corresponding to the route resource
  31. //Id corresponding to the user behind the session
  32. //(If session is from logged in user)
  33. Log.belongsTo(models.User, { as: 'SessionUser' })
  34. }
  35. }
  36. })
  37. return Log
  38. }