123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- import db from '../db'
- import { DataTypes } from 'sequelize'
- const Member = db.define('member', {
- id: {
- type: DataTypes.INTEGER,
- primaryKey: true,
- },
- createdAt: DataTypes.INTEGER,
- handle: DataTypes.STRING,
- about: DataTypes.TEXT,
- })
- Member.findAllWithIncludes = function () {
- return this.findAll({
- include: [
- { model: db.models.post, include: [{ model: db.models.thread }] },
- { model: db.models.thread, include: [{ model: db.models.category }] },
- { model: db.models.proposal, include: [{ association: 'votes' }] },
- {
- model: db.models.account,
- include: [
- { association: 'validated', attributes: ['id', 'timestamp'] },
- ],
- },
- {
- association: 'terms',
- include: [
- {
- association: 'votes',
- include: [
- {
- model: db.models.proposal,
- include: [{ association: 'author' }],
- },
- ],
- },
- { association: 'voters', include: [{ model: db.models.member }] },
- ],
- },
- {
- association: 'votes',
- include: [
- {
- model: db.models.consul,
- include: [{ model: db.models.member }],
- },
- ],
- },
- ],
- })
- }
- Member.findByIdWithIncludes = function (id: number, args?: { where: any }) {
- return this.findByPk(id, {
- ...args,
- include: [
- { model: db.models.post, include: [{ model: db.models.thread }] },
- { model: db.models.proposal, include: [{ association: 'votes' }] },
- {
- model: db.models.account,
- include: [
- { association: 'validated', attributes: ['id', 'timestamp'] },
- ],
- },
- {
- association: 'terms',
- include: [
- {
- association: 'votes',
- include: [
- {
- model: db.models.proposal,
- include: [{ association: 'author' }],
- },
- ],
- },
- { association: 'voters', include: [{ model: db.models.member }] },
- ],
- },
- {
- association: 'votes',
- include: [
- {
- model: db.models.consul,
- include: [{ model: db.models.member }],
- },
- ],
- },
- ],
- })
- }
- Member.findWithIncludes = function (args: { where: any }) {
- return this.findAll({
- ...args,
- include: [
- { model: db.models.post, include: [{ model: db.models.thread }] },
- { model: db.models.proposal, include: [{ association: 'votes' }] },
- {
- model: db.models.account,
- include: [
- { association: 'validated', attributes: ['id', 'timestamp'] },
- ],
- },
- {
- association: 'terms',
- include: [
- {
- association: 'votes',
- include: [
- {
- model: db.models.proposal,
- include: [{ association: 'author' }],
- },
- ],
- },
- { association: 'voters', include: [{ model: db.models.member }] },
- ],
- },
- {
- association: 'votes',
- include: [
- {
- model: db.models.consul,
- include: [{ model: db.models.member }],
- },
- ],
- },
- {
- model: db.models.account,
- include: [
- { association: 'validated', attributes: ['id', 'timestamp'] },
- ],
- },
- ],
- })
- }
- export default Member
|