1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import db from '../db'
- import { DataTypes } from 'sequelize'
- const order = [['id', 'ASC']]
- const Proposal = db.define('proposal', {
- id: {
- type: DataTypes.INTEGER,
- primaryKey: true,
- },
- created: DataTypes.INTEGER,
- finalizedAt: DataTypes.INTEGER,
- title: DataTypes.STRING,
- type: DataTypes.STRING,
- stage: DataTypes.STRING,
- result: DataTypes.STRING,
- executed: DataTypes.STRING,
- parameters: DataTypes.STRING,
- description: DataTypes.TEXT,
- })
- Proposal.findAllWithIncludes = function () {
- return this.findAll({
- order,
- include: [
- { association: 'author', attributes: ['handle'] },
- {
- association: 'posts',
- include: [{ association: 'author', attributes: ['handle'] }],
- },
- {
- association: 'votes',
- attributes: ['id', 'vote'],
- include: [{ model: db.models.member, attributes: ['id', 'handle'] }],
- },
- ],
- })
- }
- Proposal.findByIdWithIncludes = function (id: number, args?: { where: any }) {
- return this.findByPk(id, {
- ...args,
- include: [
- { association: 'author', attributes: ['handle'] },
- {
- association: 'posts',
- include: [{ association: 'author', attributes: ['handle'] }],
- },
- {
- association: 'votes',
- attributes: ['id', 'vote'],
- include: [{ model: db.models.member, attributes: ['id', 'handle'] }],
- },
- ],
- })
- }
- Proposal.findWithIncludes = function (args: { where: any }) {
- return this.findAll({
- ...args,
- order,
- include: [
- { association: 'author', attributes: ['handle'] },
- {
- association: 'posts',
- include: [{ association: 'author', attributes: ['handle'] }],
- },
- {
- association: 'votes',
- attributes: ['id', 'vote'],
- include: [{ association: 'author', attributes: ['id', 'handle'] }],
- },
- ],
- })
- }
- export default Proposal
|