|
@@ -0,0 +1,32 @@
|
|
|
|
|
+import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
|
|
|
|
+import PaginationService from 'App/Services/PaginationService'
|
|
|
|
|
+import { schema } from '@ioc:Adonis/Core/Validator'
|
|
|
|
|
+import OcrDevice from 'App/Models/OcrDevice'
|
|
|
|
|
+export default class OcrDevicesController {
|
|
|
|
|
+ private paginationService = new PaginationService(OcrDevice)
|
|
|
|
|
+
|
|
|
|
|
+ public async index({ request }: HttpContextContract) {
|
|
|
|
|
+ return await this.paginationService.paginate(request.all())
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public async store({ request, bouncer }: HttpContextContract) {
|
|
|
|
|
+ // await bouncer.authorize('admin')
|
|
|
|
|
+ const data = await request.validate({
|
|
|
|
|
+ schema: schema.create({
|
|
|
|
|
+ id: schema.string(),
|
|
|
|
|
+ platform: schema.string(),
|
|
|
|
|
+ channel: schema.string(),
|
|
|
|
|
+ deviceInfo: schema.string.optional(),
|
|
|
|
|
+ total: schema.number(),
|
|
|
|
|
+ scanned: schema.number()
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ const device = await OcrDevice.findBy('id', data.id)
|
|
|
|
|
+ if (device) {
|
|
|
|
|
+ device.merge(data)
|
|
|
|
|
+ return await device.save()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return await OcrDevice.create(data)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|