Skip to content
Snippets Groups Projects
Commit 151f8478 authored by L4168's avatar L4168
Browse files

added fetch tasks service, updated socket

parent 5a2f2dc4
No related branches found
No related tags found
4 merge requests!59Development to master,!31Development,!25Dto service,!24Faction task edit
......@@ -7,10 +7,13 @@ import {
UseGuards,
Param,
} from '@nestjs/common';
import { TaskService } from './task.service';
import { CreateTaskDTO, EditTaskDTO } from './task.dto';
import { AuthGuard } from '../shared/auth.guard';
import { Roles } from '../shared/roles.decorator';
import { ValidationPipe } from '../shared/validation.pipe';
import { CreateTaskDTO, EditTaskDTO } from './task.dto';
import { User } from 'src/user/user.decorator';
@Controller('task')
export class TaskController {
......@@ -33,4 +36,10 @@ export class TaskController {
async editTask(@Param('id') id: string, @Body() data: EditTaskDTO) {
return this.taskService.editTask(data);
}
@Get('get-tasks/:id')
@UseGuards(new AuthGuard())
async fetchTasks(@User('id') person, @Param('id') id: string) {
return this.taskService.fetchTasks(person, id);
}
}
......@@ -4,10 +4,15 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { TaskService } from './task.service';
import { TaskController } from './task.controller';
import { TaskEntity } from './task.entity';
import { FactionEntity } from 'src/game/faction.entity';
import { FactionEntity } from '../game/faction.entity';
import { Game_PersonEntity } from '../game/game.entity';
import { NotificationModule } from '../notifications/notifications.module';
@Module({
imports: [TypeOrmModule.forFeature([TaskEntity, FactionEntity])],
imports: [
TypeOrmModule.forFeature([TaskEntity, FactionEntity, Game_PersonEntity]),
NotificationModule,
],
controllers: [TaskController],
providers: [TaskService],
})
......
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { TaskEntity } from './task.entity';
import { CreateTaskDTO, EditTaskDTO } from './task.dto';
import { FactionEntity } from '../game/faction.entity';
import { Game_PersonEntity } from '../game/game.entity';
import { NotificationGateway } from '../notifications/notifications.gateway';
@Injectable()
export class TaskService {
......@@ -12,6 +15,9 @@ export class TaskService {
private taskRepository: Repository<TaskEntity>,
@InjectRepository(FactionEntity)
private factionRepository: Repository<FactionEntity>,
@InjectRepository(Game_PersonEntity)
private gamePersonRepository: Repository<Game_PersonEntity>,
private notificationGateway: NotificationGateway,
) {}
async newTask(task: CreateTaskDTO) {
......@@ -28,6 +34,12 @@ export class TaskService {
const createdTask = await this.taskRepository.create(task);
console.log(createdTask);
await this.taskRepository.insert(createdTask);
// notify subscribers about a new task
// if faction was set it notifies only faction members, else everyone
this.notificationGateway.server.emit(
task.faction != null ? task.faction.toString() : 'global',
'new task',
);
return {
message: 'Task added',
};
......@@ -56,4 +68,13 @@ export class TaskService {
message: 'Task updated and closed',
};
}
async fetchTasks(user, taskGame) {
// to do: limit fetch for factions
const gamePerson = await this.gamePersonRepository.findOne({
person: user,
game: taskGame,
});
return await this.taskRepository.find({ taskGame: taskGame });
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment