app.controller.js 999 Bytes
Newer Older
baesangjune's avatar
baesangjune committed
1
2
3
import Places from '../models/Place.js'

const searchRecommend = async (req, res, next,) => {
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    let responseRecommend = await Places.aggregate([
        {
            
            $project: {
                name:1,
                address:1,
                img:1,
                timeslength: { $cond: { if: { $isArray: "$times" }, then: { $size: "$times" }, else: 'NA' } }
            }
        }
    ])


    let result = responseRecommend.sort((a, b) => {
        return b.timeslength-a.timeslength
    });


    //이거는 정렬까지는 아니고 개수 세주는거 같음. 따라서 정렬은 다시해줄 필요 있는듯
    // console.log("aggregate", responseRecommend.find().sort({"timeslength":1}))
    console.log("ddddddddddddd", result[0])

    res.send(result[0])
baesangjune's avatar
baesangjune committed
27
28
29
30
31
32


}

const searchLatest = async (req, res, next) => {

33
    let responseLatest = await Places.find({}).sort({ updatedAt: -1 })
baesangjune's avatar
baesangjune committed
34
35
36
37
38
39
    res.send(responseLatest[0])


}

export default { searchRecommend, searchLatest }