app.controller.js 748 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
    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
    });
    res.send(result[0])
baesangjune's avatar
baesangjune committed
21
22
23
24
}

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

25
    let responseLatest = await Places.find({}).sort({ updatedAt: -1 })
baesangjune's avatar
baesangjune committed
26
27
28
29
30
31
    res.send(responseLatest[0])


}

export default { searchRecommend, searchLatest }