aboutsummaryrefslogtreecommitdiff
path: root/vnext/server/db/Users.js
diff options
context:
space:
mode:
Diffstat (limited to 'vnext/server/db/Users.js')
-rw-r--r--vnext/server/db/Users.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/vnext/server/db/Users.js b/vnext/server/db/Users.js
new file mode 100644
index 00000000..445b0ff0
--- /dev/null
+++ b/vnext/server/db/Users.js
@@ -0,0 +1,43 @@
+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
+ }
+ }
+ })
+}