|  | @@ -59,6 +59,84 @@ exports.getPengunjung = handleError(async (req, res) => {
 | 
	
		
			
				|  |  |          },
 | 
	
		
			
				|  |  |        },
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      $sort: {
 | 
	
		
			
				|  |  | +        ['_id.bulan']: 1,
 | 
	
		
			
				|  |  | +      },
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +  ])
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  return response.success(res, {
 | 
	
		
			
				|  |  | +    message: 'data pengunjung',
 | 
	
		
			
				|  |  | +    data: pengunjung,
 | 
	
		
			
				|  |  | +  })
 | 
	
		
			
				|  |  | +})
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +exports.getPengunjungPublic = handleError(async (req, res) => {
 | 
	
		
			
				|  |  | +  const { tahun, bulan } = req.query
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  let date = {}
 | 
	
		
			
				|  |  | +  if (tahun || bulan) {
 | 
	
		
			
				|  |  | +    date = {
 | 
	
		
			
				|  |  | +      $expr: {
 | 
	
		
			
				|  |  | +        $and: [
 | 
	
		
			
				|  |  | +          {
 | 
	
		
			
				|  |  | +            $eq: [
 | 
	
		
			
				|  |  | +              { $year: '$createdAt' },
 | 
	
		
			
				|  |  | +              parseInt(tahun) || new Date().getFullYear(),
 | 
	
		
			
				|  |  | +            ],
 | 
	
		
			
				|  |  | +          },
 | 
	
		
			
				|  |  | +          {
 | 
	
		
			
				|  |  | +            $eq: [
 | 
	
		
			
				|  |  | +              { $month: '$createdAt' },
 | 
	
		
			
				|  |  | +              parseInt(bulan) || new Date().getMonth() + 1,
 | 
	
		
			
				|  |  | +            ],
 | 
	
		
			
				|  |  | +          },
 | 
	
		
			
				|  |  | +        ],
 | 
	
		
			
				|  |  | +      },
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  const pengunjung = await pengunjungModel.aggregate([
 | 
	
		
			
				|  |  | +    { $match: date },
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      $group: {
 | 
	
		
			
				|  |  | +        _id: {
 | 
	
		
			
				|  |  | +          tanggal: {
 | 
	
		
			
				|  |  | +            $dayOfMonth: '$createdAt',
 | 
	
		
			
				|  |  | +          },
 | 
	
		
			
				|  |  | +          bulan: {
 | 
	
		
			
				|  |  | +            $month: '$createdAt',
 | 
	
		
			
				|  |  | +          },
 | 
	
		
			
				|  |  | +          tahun: {
 | 
	
		
			
				|  |  | +            $year: '$createdAt',
 | 
	
		
			
				|  |  | +          },
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        jumlah_pengunjung: {
 | 
	
		
			
				|  |  | +          $sum: 1,
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +        data_ip: {
 | 
	
		
			
				|  |  | +          $addToSet: '$ipv4',
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +      },
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      $addFields: {
 | 
	
		
			
				|  |  | +        jumlah_pengunjung: {
 | 
	
		
			
				|  |  | +          $size: '$data_ip',
 | 
	
		
			
				|  |  | +        },
 | 
	
		
			
				|  |  | +      },
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      $project: {
 | 
	
		
			
				|  |  | +        data_ip: 0,
 | 
	
		
			
				|  |  | +      },
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      $sort: {
 | 
	
		
			
				|  |  | +        ['_id.tanggal']: 1,
 | 
	
		
			
				|  |  | +      },
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  |    ])
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    return response.success(res, {
 |