mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 15:58:38 +01:00
add admin utils
This commit is contained in:
@@ -4,6 +4,8 @@ export type AdminProjectsList = {
|
|||||||
premium: boolean,
|
premium: boolean,
|
||||||
created_at: Date,
|
created_at: Date,
|
||||||
project_name: string,
|
project_name: string,
|
||||||
|
premium_type: number,
|
||||||
|
_id: string,
|
||||||
user: {
|
user: {
|
||||||
name: string,
|
name: string,
|
||||||
email: string,
|
email: string,
|
||||||
@@ -32,71 +34,26 @@ export default defineEventHandler(async event => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
$lookup: {
|
$lookup: {
|
||||||
from: "visits",
|
from: "project_counts",
|
||||||
let: { projectId: "$_id" },
|
localField: "_id",
|
||||||
pipeline: [
|
foreignField: "project_id",
|
||||||
{
|
as: "counts"
|
||||||
$match: {
|
|
||||||
$expr: {
|
|
||||||
$eq: ["$project_id", "$$projectId"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$count: "total_visits"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
as: "visits"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$lookup: {
|
|
||||||
from: "events",
|
|
||||||
let: { projectId: "$_id" },
|
|
||||||
pipeline: [
|
|
||||||
{
|
|
||||||
$match: {
|
|
||||||
$expr: {
|
|
||||||
$eq: ["$project_id", "$$projectId"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$count: "total_events"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
as: "events"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$project: {
|
$project: {
|
||||||
project_name: "$name",
|
project_name: "$name",
|
||||||
premium: 1,
|
premium: 1,
|
||||||
|
premium_type: 1,
|
||||||
created_at: 1,
|
created_at: 1,
|
||||||
user: {
|
user: {
|
||||||
$first: "$user"
|
$first: "$user"
|
||||||
},
|
},
|
||||||
total_visits: {
|
total_visits: {
|
||||||
$ifNull: [
|
$arrayElemAt: ["$counts.visits", 0]
|
||||||
{
|
|
||||||
$arrayElemAt: [
|
|
||||||
"$visits.total_visits",
|
|
||||||
0
|
|
||||||
]
|
|
||||||
},
|
|
||||||
0
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
total_events: {
|
total_events: {
|
||||||
$ifNull: [
|
$arrayElemAt: ["$counts.visits", 0]
|
||||||
{
|
|
||||||
$arrayElemAt: [
|
|
||||||
"$events.total_events",
|
|
||||||
0
|
|
||||||
]
|
|
||||||
},
|
|
||||||
0
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user