Initial commit
This commit is contained in:
74
src/pipelines/vote.ts
Normal file
74
src/pipelines/vote.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { PipelineStage, Types } from "mongoose";
|
||||
|
||||
function vote(date: Date, userId: Types.ObjectId) {
|
||||
var pipeline: PipelineStage[] = [
|
||||
{
|
||||
'$match': {
|
||||
'day': date
|
||||
}
|
||||
}, {
|
||||
'$lookup': {
|
||||
'from': 'votes',
|
||||
'localField': 'day',
|
||||
'foreignField': 'dom',
|
||||
'as': 'result',
|
||||
'pipeline': [
|
||||
{
|
||||
'$match': {
|
||||
'tom': 'ob',
|
||||
'user': new Types.ObjectId(userId)
|
||||
}
|
||||
}, {
|
||||
'$project': {
|
||||
'_id': 0,
|
||||
'vote': 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}, {
|
||||
'$unwind': {
|
||||
'path': '$result',
|
||||
'preserveNullAndEmptyArrays': true
|
||||
}
|
||||
}, {
|
||||
'$set': {
|
||||
'obv': '$result.vote'
|
||||
}
|
||||
}, {
|
||||
'$lookup': {
|
||||
'from': 'votes',
|
||||
'localField': 'day',
|
||||
'foreignField': 'dom',
|
||||
'as': 'result',
|
||||
'pipeline': [
|
||||
{
|
||||
'$match': {
|
||||
'tom': 'kol',
|
||||
'user': new Types.ObjectId(userId)
|
||||
}
|
||||
}, {
|
||||
'$project': {
|
||||
'_id': 0,
|
||||
'vote': 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}, {
|
||||
'$unwind': {
|
||||
'path': '$result',
|
||||
'preserveNullAndEmptyArrays': true
|
||||
}
|
||||
}, {
|
||||
'$set': {
|
||||
'kolv': '$result.vote'
|
||||
}
|
||||
}, {
|
||||
'$unset': 'result'
|
||||
}
|
||||
]
|
||||
return pipeline
|
||||
}
|
||||
|
||||
export { vote }
|
||||
Reference in New Issue
Block a user