feat: add reject QR gate
continuous-integration/drone/tag Build is passing
Details
continuous-integration/drone/tag Build is passing
Details
parent
9d98003a2d
commit
665eacd39f
|
@ -1,4 +1,5 @@
|
|||
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Param, Post, Res } from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { Public } from 'src/core/guards';
|
||||
import { GateScanEntity } from '../domain/entity/gate-request.entity';
|
||||
|
@ -21,16 +22,24 @@ const masterGates = [
|
|||
'4c0e6924-baf5-47fb-a15b-fd1cd0958cc0',
|
||||
];
|
||||
|
||||
const failedGates = [
|
||||
'b3c3ae7b-daf5-4340-998b-ee35ed41323d',
|
||||
'be157609-92b8-4989-920d-a81769bcb05a',
|
||||
];
|
||||
|
||||
const gateResponses = [
|
||||
{
|
||||
statusCode: 200,
|
||||
code: 1,
|
||||
message: 'Berhasil Check In',
|
||||
},
|
||||
{
|
||||
statusCode: 403,
|
||||
code: 2,
|
||||
message: 'Gagal melakukan Check In. Karena tiket telah kadaluarsa',
|
||||
},
|
||||
{
|
||||
statusCode: 403,
|
||||
code: 3,
|
||||
message: 'Gagal melakukan Check In. Tiket tidak tersedia',
|
||||
},
|
||||
|
@ -42,11 +51,25 @@ const gateResponses = [
|
|||
@Gate()
|
||||
export class GateController {
|
||||
@Post('scan')
|
||||
async scan(@Body() data: GateScanEntity): Promise<GateResponseEntity> {
|
||||
if (masterGates.includes(data.uuid)) return gateResponses[0];
|
||||
async scan(
|
||||
@Body() data: GateScanEntity,
|
||||
@Res({ passthrough: true }) res: Response,
|
||||
): Promise<GateResponseEntity> {
|
||||
console.log(data);
|
||||
if (masterGates.includes(data.uuid)) {
|
||||
res.status(200);
|
||||
return gateResponses[0];
|
||||
}
|
||||
if (failedGates.includes(data.uuid)) {
|
||||
res.status(403);
|
||||
return gateResponses[2];
|
||||
}
|
||||
|
||||
const response = Math.floor(Math.random() * 3);
|
||||
return gateResponses[response];
|
||||
const responseValue = gateResponses[response];
|
||||
|
||||
res.status(responseValue.statusCode);
|
||||
return responseValue;
|
||||
}
|
||||
|
||||
@Get(':id/master')
|
||||
|
|
Loading…
Reference in New Issue