Ajout initial des fichiers du projet
This commit is contained in:
@@ -0,0 +1,507 @@
|
||||
const queries = {
|
||||
getJumpsByCategoryQuery: (userId) => {
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$expr': {
|
||||
'$eq': [ '$author' , { '$toObjectId': userId } ]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$group': {
|
||||
'_id': {
|
||||
'categorie': '$categorie'
|
||||
},
|
||||
'count': {
|
||||
'$sum': 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$sort': {
|
||||
'_id': 1
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return query;
|
||||
},
|
||||
getJumpsByDateQuery: (userId) => {
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$expr': {
|
||||
'$eq': [ '$author' , { '$toObjectId': userId } ]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$project': {
|
||||
'_id': 0,
|
||||
'year': {
|
||||
'$year': '$date'
|
||||
},
|
||||
'month': {
|
||||
'$month': '$date'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$group': {
|
||||
'_id': {
|
||||
'year': '$year',
|
||||
'month': '$month'
|
||||
},
|
||||
'count': {
|
||||
'$sum': 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$sort': {
|
||||
'_id': 1
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return query;
|
||||
},
|
||||
getJumpsByModuleByDateQuery: (userId) => {
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$expr': {
|
||||
'$eq': [ '$author' , { '$toObjectId': userId } ]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$project': {
|
||||
'_id': 0,
|
||||
'module': 1,
|
||||
'categorie': 1,
|
||||
'year': {
|
||||
'$year': '$date'
|
||||
},
|
||||
'month': {
|
||||
'$month': '$date'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$group': {
|
||||
'_id': {
|
||||
'module': '$module',
|
||||
'categorie': '$categorie',
|
||||
'year': '$year',
|
||||
'month': '$month'
|
||||
},
|
||||
'count': {
|
||||
'$sum': 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$sort': {
|
||||
'_id': 1
|
||||
}
|
||||
}
|
||||
];
|
||||
return query;
|
||||
},
|
||||
getJumpsByModuleQuery: (userId) => {
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$expr': {
|
||||
'$eq': [ '$author' , { '$toObjectId': userId } ]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$project': {
|
||||
'_id': 0,
|
||||
'categorie': 1,
|
||||
'module': 1
|
||||
}
|
||||
}, {
|
||||
'$group': {
|
||||
'_id': {
|
||||
'categorie': '$categorie',
|
||||
'module': '$module'
|
||||
},
|
||||
'count': {
|
||||
'$sum': 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$sort': {
|
||||
'_id': 1
|
||||
}
|
||||
}
|
||||
];
|
||||
return query;
|
||||
},
|
||||
getJumpByYearsQuery: (userId) => {
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$expr': {
|
||||
'$eq': [ '$author' , { '$toObjectId': userId } ]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$project': {
|
||||
'_id': 0,
|
||||
'year': {
|
||||
'$year': '$date'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$group': {
|
||||
'_id': {
|
||||
'year': '$year'
|
||||
},
|
||||
'count': {
|
||||
'$sum': 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$sort': {
|
||||
'_id': 1
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return query;
|
||||
},
|
||||
getAeronefsByImatQuery: (userId) => {
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$expr': {
|
||||
'$eq': [ '$author' , { '$toObjectId': userId } ]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$group': {
|
||||
'_id': {
|
||||
'aeronef': '$aeronef',
|
||||
'imat': '$imat'
|
||||
},
|
||||
'count': {
|
||||
'$sum': 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$sort':
|
||||
{
|
||||
'count': -1
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
return query;
|
||||
},
|
||||
getAeronefsByImatByYearQuery: (userId) => {
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$expr': {
|
||||
'$eq': [ '$author' , { '$toObjectId': userId } ]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$project': {
|
||||
'_id': 0,
|
||||
'aeronef': 1,
|
||||
'imat': 1,
|
||||
'year': {
|
||||
'$year': '$date'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$group': {
|
||||
'_id': {
|
||||
'aeronef': '$aeronef',
|
||||
'imat': '$imat',
|
||||
'year': '$year'
|
||||
},
|
||||
'count': {
|
||||
'$sum': 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$sort': {
|
||||
'_id': 1
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return query;
|
||||
},
|
||||
getCanopiesBySizeQuery: (userId) => {
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$expr': {
|
||||
'$eq': [ '$author' , { '$toObjectId': userId } ]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$group': {
|
||||
'_id': {
|
||||
'taille': '$taille'
|
||||
},
|
||||
'count': {
|
||||
'$sum': 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$sort':
|
||||
{
|
||||
'_id': 1
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
return query;
|
||||
},
|
||||
getCanopiesBySizeByYearQuery: (userId) => {
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$expr': {
|
||||
'$eq': [ '$author' , { '$toObjectId': userId } ]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$project': {
|
||||
'_id': 0,
|
||||
'taille': 1,
|
||||
'year': {
|
||||
'$year': '$date'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$group': {
|
||||
'_id': {
|
||||
'taille': '$taille',
|
||||
'year': '$year'
|
||||
},
|
||||
'count': {
|
||||
'$sum': 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$sort': {
|
||||
'_id': 1
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return query;
|
||||
},
|
||||
getCanopiesBySizeByModelQuery: (userId) => {
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$expr': {
|
||||
'$eq': [ '$author' , { '$toObjectId': userId } ]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$group': {
|
||||
'_id': {
|
||||
'taille': '$taille',
|
||||
'voile': '$voile'
|
||||
},
|
||||
'count': {
|
||||
'$sum': 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$sort':
|
||||
{
|
||||
'_id': 1
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
return query;
|
||||
},
|
||||
getCanopiesBySizeByModelByYearQuery: (userId) => {
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$expr': {
|
||||
'$eq': [ '$author' , { '$toObjectId': userId } ]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$project': {
|
||||
'_id': 0,
|
||||
'voile': 1,
|
||||
'taille': 1,
|
||||
'year': {
|
||||
'$year': '$date'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$group': {
|
||||
'_id': {
|
||||
'taille': '$taille',
|
||||
'voile': '$voile',
|
||||
'year': '$year'
|
||||
},
|
||||
'count': {
|
||||
'$sum': 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$sort': {
|
||||
'_id': 1
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return query;
|
||||
},
|
||||
getDropZonesByOaciQuery: (userId) => {
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$expr': {
|
||||
'$eq': [ '$author' , { '$toObjectId': userId } ]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$group': {
|
||||
'_id': {
|
||||
'lieu': '$lieu',
|
||||
'oaci': '$oaci'
|
||||
},
|
||||
'count': {
|
||||
'$sum': 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$sort':
|
||||
{
|
||||
'_id': 1
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
return query;
|
||||
},
|
||||
getDropZonesByOaciByYearQuery: (userId) => {
|
||||
let query = [
|
||||
{
|
||||
'$match': {
|
||||
'$expr': {
|
||||
'$eq': [ '$author' , { '$toObjectId': userId } ]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$project': {
|
||||
'_id': 0,
|
||||
'lieu': 1,
|
||||
'oaci': 1,
|
||||
'year': {
|
||||
'$year': '$date'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$group': {
|
||||
'_id': {
|
||||
'lieu': '$lieu',
|
||||
'oaci': '$oaci',
|
||||
'year': '$year'
|
||||
},
|
||||
'count': {
|
||||
'$sum': 1
|
||||
}
|
||||
}
|
||||
}, {
|
||||
'$sort': {
|
||||
'_id': 1
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return query;
|
||||
},
|
||||
getJumpsByDayQuery: (userId, dateRangeStart = null, dateRangeEnd = null) => {
|
||||
if (dateRangeStart === null) {
|
||||
dateRangeStart = '1970-01-01 00:00:00';
|
||||
}
|
||||
if (dateRangeEnd === null) {
|
||||
const year = new Date().getFullYear();
|
||||
dateRangeEnd = `${year}-12-31 23:59:59`;
|
||||
}
|
||||
let query = [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [ '$author' , { '$toObjectId': userId } ]
|
||||
},
|
||||
{
|
||||
$gte: ['$date', new Date(dateRangeStart)]
|
||||
},
|
||||
{
|
||||
$lte: ['$date', new Date(dateRangeEnd)]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
$project: {
|
||||
_id: 1,
|
||||
slug: "$slug",
|
||||
numero: "$numero",
|
||||
date: "$date",
|
||||
year: {
|
||||
$year: "$date"
|
||||
},
|
||||
month: {
|
||||
$month: "$date"
|
||||
},
|
||||
day: {
|
||||
$dayOfMonth: "$date"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: {
|
||||
year: "$year",
|
||||
month: "$month",
|
||||
day: "$day"
|
||||
},
|
||||
jumps: {
|
||||
$addToSet: {
|
||||
_id: "$_id",
|
||||
numero: "$numero",
|
||||
slug: "$slug",
|
||||
date: "$date"
|
||||
}
|
||||
},
|
||||
count: {
|
||||
$sum: 1
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
_id: 1,
|
||||
}
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
_id: 0,
|
||||
jumps: 1,
|
||||
count: 1
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return query;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = queries;
|
||||
Reference in New Issue
Block a user