mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
wip: models/commands analytics
This commit is contained in:
1 parent
ceb9416fab
commit
8c634c8115
7 files changed
+52
-40
No files matched your search
@@ -1,16 +1,26 @@
|
||||
import { Command } from '@linux-odyssey/models'
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export async function errorCommands(pageNumber, itemsPerPage) {
|
||||
const skipAmount = (pageNumber - 1) * itemsPerPage
|
||||
export async function errorCommands({ nextKey, itemsPerPage }) {
|
||||
const key = new mongoose.Types.ObjectId(nextKey)
|
||||
const matchStage = nextKey ? { _id: { $lt: key } } : {}
|
||||
|
||||
const commands = await Command.find({
|
||||
$and: [
|
||||
{ error: { $exists: true } },
|
||||
{ error: { $ne: null } },
|
||||
{ error: { $ne: '' } },
|
||||
],
|
||||
})
|
||||
const commands = await Command.aggregate([
|
||||
{
|
||||
$match: matchStage,
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
$and: [
|
||||
{ error: { $exists: true } },
|
||||
{ error: { $ne: null } },
|
||||
{ error: { $ne: '' } },
|
||||
],
|
||||
}
|
||||
}
|
||||
{ $limit: itemsPerPage },
|
||||
])
|
||||
.populate({
|
||||
path: 'session',
|
||||
populate: { path: 'user' },
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Command, Session } from '@linux-odyssey/models'
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
export function sessionCount() {
|
||||
return Session.find().count()
|
||||
@@ -30,10 +31,14 @@ function formatTime(time) {
|
||||
return `${hours}h ${minutes % 60}m ${seconds % 60}s`
|
||||
}
|
||||
|
||||
export async function sessionList(pageNumber, itemsPerPage) {
|
||||
const skipAmount = (pageNumber - 1) * itemsPerPage
|
||||
export async function sessionList({ nextKey, itemsPerPage }) {
|
||||
const key = new mongoose.Types.ObjectId(nextKey)
|
||||
const matchStage = nextKey ? { _id: { $lt: key } } : {}
|
||||
|
||||
const sessions = await Session.aggregate([
|
||||
{
|
||||
$match: matchStage,
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 'users',
|
||||
@@ -51,9 +56,10 @@ export async function sessionList(pageNumber, itemsPerPage) {
|
||||
as: 'commands',
|
||||
},
|
||||
},
|
||||
{ $sort: { _id: -1 } },
|
||||
{ $limit: itemsPerPage },
|
||||
])
|
||||
.skip(skipAmount)
|
||||
.limit(itemsPerPage)
|
||||
|
||||
return sessions.map(
|
||||
({
|
||||
_id,
|
||||
|
||||
Reference in new issue
Block a user