|
|
@@ -0,0 +1,37 @@
|
|
|
+const pengunjungModel = require('../model/pengunjung.model')
|
|
|
+const handleError = require('../utils/handleError')
|
|
|
+const response = require('../utils/responseHandler')
|
|
|
+const { validate } = require('../utils/validation')
|
|
|
+
|
|
|
+exports.create = handleError(async (req, res) => {
|
|
|
+ const { os, ipv4, location } = req.body
|
|
|
+ const isValid = validate(res, req.body, {
|
|
|
+ os: 'string',
|
|
|
+ ipv4: 'string',
|
|
|
+ location: {
|
|
|
+ $$type: 'object',
|
|
|
+ country: 'string',
|
|
|
+ region: 'string',
|
|
|
+ city: 'string',
|
|
|
+ lat: 'number',
|
|
|
+ lon: 'number',
|
|
|
+ timezone: 'string',
|
|
|
+ },
|
|
|
+ })
|
|
|
+ if (!isValid) return
|
|
|
+
|
|
|
+ await pengunjungModel.create({ os, ipv4, location })
|
|
|
+
|
|
|
+ return response.success(res, {
|
|
|
+ message: 'data pengunjung berhasil dibuat',
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+exports.getPengunjung = handleError(async (req, res) => {
|
|
|
+ const pengunjung = await pengunjungModel.find()
|
|
|
+
|
|
|
+ return response.success(res, {
|
|
|
+ message: 'data pengunjung berhasil dibuat',
|
|
|
+ data: pengunjung,
|
|
|
+ })
|
|
|
+})
|