Compare commits
3 Commits
main
...
ce5b3c7285
| Author | SHA1 | Date | |
|---|---|---|---|
| ce5b3c7285 | |||
| 3ccb4a867c | |||
| 06e082b11c |
@@ -31,9 +31,7 @@ jobs:
|
|||||||
- name: Restart pm2
|
- name: Restart pm2
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||||
run: |
|
run: |
|
||||||
pm2 describe tetardpg-backend >/dev/null 2>&1 \
|
su - tetardtek-brain -c 'pm2 reload tetardpg-backend --update-env'
|
||||||
&& pm2 reload tetardpg-backend --update-env \
|
|
||||||
|| (cd /var/www/tetardpg/backend && pm2 start dist/main.js --name tetardpg-backend && pm2 save)
|
|
||||||
|
|
||||||
# ── Frontend ─────────────────────────────────────────────────────────────
|
# ── Frontend ─────────────────────────────────────────────────────────────
|
||||||
- name: Install & build frontend
|
- name: Install & build frontend
|
||||||
|
|||||||
@@ -1,36 +1,23 @@
|
|||||||
import { Controller, Get, Query, Req, UseGuards, BadRequestException } from '@nestjs/common';
|
import { Controller, Get, Query, Req, UseGuards } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
import { Repository } from 'typeorm';
|
|
||||||
import { NpcService } from './npc.service';
|
import { NpcService } from './npc.service';
|
||||||
import { AuthGuard } from '../auth/guards/auth.guard';
|
import { AuthGuard } from '../auth/guards/auth.guard';
|
||||||
import { Character } from '../character/entities/character.entity';
|
|
||||||
|
|
||||||
@Controller('npcs')
|
@Controller('npcs')
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
export class NpcController {
|
export class NpcController {
|
||||||
constructor(
|
constructor(private readonly npcService: NpcService) {}
|
||||||
private readonly npcService: NpcService,
|
|
||||||
@InjectRepository(Character)
|
|
||||||
private readonly characterRepo: Repository<Character>,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
private async getCharacter(req: any) {
|
|
||||||
const character = await this.characterRepo.findOne({ where: { userId: req.user.id } });
|
|
||||||
if (!character) throw new BadRequestException('Aucun personnage trouvé');
|
|
||||||
return character;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** GET /api/npcs — tous les PNJ visibles pour le joueur */
|
/** GET /api/npcs — tous les PNJ visibles pour le joueur */
|
||||||
@Get()
|
@Get()
|
||||||
async getAll(@Req() req: any) {
|
async getAll(@Req() req: any) {
|
||||||
const char = await this.getCharacter(req);
|
const { characterId, level } = req.character;
|
||||||
return this.npcService.getVisibleNpcs(char.id, char.level);
|
return this.npcService.getVisibleNpcs(characterId, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** GET /api/npcs/location?location=village_plaza — PNJ d'un emplacement */
|
/** GET /api/npcs?location=village_plaza — PNJ d'un emplacement */
|
||||||
@Get('location')
|
@Get('location')
|
||||||
async getByLocation(@Req() req: any, @Query('location') location: string) {
|
async getByLocation(@Req() req: any, @Query('location') location: string) {
|
||||||
const char = await this.getCharacter(req);
|
const { characterId, level } = req.character;
|
||||||
return this.npcService.getNpcsByLocation(char.id, char.level, location);
|
return this.npcService.getNpcsByLocation(characterId, level, location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ import { Npc } from './npc.entity';
|
|||||||
import { NpcController } from './npc.controller';
|
import { NpcController } from './npc.controller';
|
||||||
import { NpcService } from './npc.service';
|
import { NpcService } from './npc.service';
|
||||||
import { PlayerQuestArc } from '../quest/player-quest-arc.entity';
|
import { PlayerQuestArc } from '../quest/player-quest-arc.entity';
|
||||||
import { Character } from '../character/entities/character.entity';
|
|
||||||
import { AuthModule } from '../auth/auth.module';
|
import { AuthModule } from '../auth/auth.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([Npc, PlayerQuestArc, Character]), AuthModule],
|
imports: [TypeOrmModule.forFeature([Npc, PlayerQuestArc]), AuthModule],
|
||||||
controllers: [NpcController],
|
controllers: [NpcController],
|
||||||
providers: [NpcService],
|
providers: [NpcService],
|
||||||
exports: [NpcService],
|
exports: [NpcService],
|
||||||
|
|||||||
Reference in New Issue
Block a user