account.ts 969 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import db from '../db'
  2. import { DataTypes } from 'sequelize'
  3. const Account = db.define('account', {
  4. key: {
  5. type: DataTypes.STRING,
  6. primaryKey: true,
  7. },
  8. format: DataTypes.STRING,
  9. about: DataTypes.TEXT,
  10. })
  11. Account.findAllWithIncludes = function () {
  12. return this.findAll({
  13. include: [
  14. { association: 'validated', attributes: ['id', 'timestamp'] },
  15. { model: db.models.member, attributes: ['handle'] },
  16. ],
  17. })
  18. }
  19. Account.findByIdWithIncludes = function (id: number) {
  20. return this.findByPk(id, {
  21. include: [
  22. { association: 'validated', attributes: ['id', 'timestamp'] },
  23. { model: db.models.member, attributes: ['handle'] },
  24. ],
  25. })
  26. }
  27. Account.findWithIncludes = function (args: { where: any }) {
  28. return this.findAll({
  29. ...args,
  30. include: [
  31. { association: 'validated', attributes: ['id', 'timestamp'] },
  32. { model: db.models.member, attributes: ['handle'] },
  33. ],
  34. })
  35. }
  36. export default Account