Skip to content

Commit

Permalink
fix: e2e and lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mefjus committed Jun 26, 2021
1 parent 789f648 commit e3752cb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/continous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ jobs:
TEST_USER_LASTNAME: 'Doe'
ETHEREAL_USER: ${{ secrets.ETHEREAL_USER }}
ETHEREAL_PASSWORD: ${{ secrets.ETHEREAL_PASSWORD }}
DEVICE_TICKET: 'ticket'

services:
postgres:
Expand Down
17 changes: 17 additions & 0 deletions packages/api/src/modules/ticket/ticket.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Controller, Get } from '@nestjs/common';

import { BasePayload } from '../../interfaces/token-types';
import { Auth } from '../auth/decorators/auth.decorator';
import { CookiePayload } from '../auth/decorators/cookiePayload.decorator';
import { TicketService } from './ticket.service';

@Auth()
@Controller('ticket')
export class TicketController {
constructor(private readonly ticketService: TicketService) {}

@Get('generate')
async generate(@CookiePayload() payload: BasePayload) {
return this.ticketService.generate(payload.sub);
}
}
15 changes: 15 additions & 0 deletions packages/api/src/modules/ticket/ticket.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { CacheModule, Module } from '@nestjs/common';

import { AuthModule } from '../auth/auth.module';
import { TokenModule } from '../auth/token/token.module';
import { RepositoryModule } from '../repository/repository.module';
import { TicketController } from './ticket.controller';
import { TicketService } from './ticket.service';

@Module({
imports: [RepositoryModule, AuthModule, TokenModule, CacheModule.register()],
controllers: [TicketController],
providers: [TicketService],
exports: [TicketService],
})
export class TicketModule {}
18 changes: 18 additions & 0 deletions packages/api/src/modules/ticket/ticket.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common';
import { Cache } from 'cache-manager';
import { v4 as uuidV4 } from 'uuid';

@Injectable()
export class TicketService {
constructor(@Inject(CACHE_MANAGER) private readonly cacheManager: Cache) {}

async generate(userId: string): Promise<string> {
const ticket = uuidV4();
await this.cacheManager.set(ticket, userId, { ttl: 60 });
return ticket;
}

async check(ticket: string): Promise<string | undefined> {
return this.cacheManager.get(ticket);
}
}

0 comments on commit e3752cb

Please sign in to comment.