import { DataTypes, Op } from 'sequelize' import db from './index' const User = db.define('user', { id: { type: DataTypes.INTEGER, primaryKey: true }, nick: DataTypes.STRING, passw: DataTypes.STRING, banned: DataTypes.INTEGER, last_seen: DataTypes.DATE }, { timestamps: false }) export const getMonthlyActiveUsers = async () => { const seenDate = new Date() seenDate.setMonth(seenDate.getMonth() - 1) return await User.count({ where: { banned: { [Op.eq]: 0 }, last_seen: { [Op.gt]: seenDate } } }) } export const getUserByName = async (name = '') => { return await User.findOne({ where: { nick: { [Op.eq]: name }, banned: { [Op.eq]: 0 } } }) }