123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- import db from '../db'
- import { DataTypes } from 'sequelize'
- const order = [['round', 'ASC']]
- const Council = db.define('council', {
- round: {
- type: DataTypes.INTEGER,
- primaryKey: true,
- },
- start: DataTypes.INTEGER,
- startDate: DataTypes.DATE,
- end: DataTypes.INTEGER,
- endDate: DataTypes.DATE,
- })
- Council.findAllWithIncludes = function () {
- return this.findAll({
- order,
- include: [
- {
- model: db.models.commitment,
- include: [{ model: db.models.member, attributes: ['handle'] }],
- },
- {
- model: db.models.consul,
- include: [
- { model: db.models.member, attributes: ['handle'] },
- {
- association: 'votes',
- include: [{ model: db.models.proposal, attributes: ['title'] }],
- },
- {
- association: 'voters',
- include: [{ model: db.models.member, attributes: ['handle'] }],
- },
- ],
- },
- ],
- })
- }
- Council.findByIdWithIncludes = function (id: number, args?: { where: any }) {
- return this.findByPk(id, {
- ...args,
- include: [
- {
- model: db.models.commitment,
- include: [{ model: db.models.member, attributes: ['handle'] }],
- },
- {
- model: db.models.consul,
- include: [
- { model: db.models.member, attributes: ['handle'] },
- {
- association: 'votes',
- include: [{ model: db.models.proposal, attributes: ['title'] }],
- },
- {
- association: 'voters',
- include: [{ model: db.models.member, attributes: ['handle'] }],
- },
- ],
- },
- ],
- })
- }
- Council.findWithIncludes = function (args?: { where: any }) {
- return this.findAll({
- ...args,
- order,
- include: [
- {
- model: db.models.commitment,
- include: [{ model: db.models.member, attributes: ['handle'] }],
- },
- {
- model: db.models.consul,
- include: [
- { model: db.models.member, attributes: ['handle'] },
- {
- association: 'votes',
- include: [{ model: db.models.proposal, attributes: ['title'] }],
- },
- {
- association: 'voters',
- include: [{ model: db.models.member, attributes: ['handle'] }],
- },
- ],
- },
- ],
- })
- }
- export default Council
|