Skip to content
Snippets Groups Projects
Commit 674871a6 authored by L4168's avatar L4168
Browse files

initial task settings

parent 368e99dc
No related branches found
No related tags found
3 merge requests!59Development to master,!31Development,!23Faction tasks + Piirto
...@@ -11,6 +11,7 @@ import { LoggingInterceptor } from './shared/logging.interceptor'; ...@@ -11,6 +11,7 @@ import { LoggingInterceptor } from './shared/logging.interceptor';
import { NotificationModule } from './notifications/notifications.module'; import { NotificationModule } from './notifications/notifications.module';
import { GameModule } from './game/game.module'; import { GameModule } from './game/game.module';
import { RolesGuard } from './shared/roles.guard'; import { RolesGuard } from './shared/roles.guard';
import { TaskModule } from './task/task.module';
@Module({ @Module({
imports: [ imports: [
...@@ -18,6 +19,7 @@ import { RolesGuard } from './shared/roles.guard'; ...@@ -18,6 +19,7 @@ import { RolesGuard } from './shared/roles.guard';
UserModule, UserModule,
GameModule, GameModule,
NotificationModule, NotificationModule,
TaskModule,
], ],
controllers: [AppController], controllers: [AppController],
providers: [ providers: [
......
import {
Controller,
Post,
Body,
UsePipes,
Get,
UseGuards,
Param,
} from '@nestjs/common';
import { TaskService } from './task.service';
import { Roles } from '../shared/roles.decorator';
import { ValidationPipe } from '../shared/validation.pipe';
import { TaskDTO } from './task.dto';
@Controller('task')
export class TaskController {
constructor(private taskService: TaskService) {}
/* @Post('new')
@UseGuards(new AuthGuard())
@UsePipes(new ValidationPipe())
async newGame(@User('id') person, @Body() body: GameDTO) {
return this.gameservice.createNewGame(person, body);
}
@Put(':id')
@Roles('admin')
@UsePipes(new ValidationPipe())
async editGame(@Param('id') id: string, @Body() body: GameDTO) {
return this.gameservice.editGame(id, body);
} */
// creates a new task if the user has admin role in the game
// :id is the id of the game
@Post('new-task/:id')
@Roles('admin')
@UsePipes(new ValidationPipe())
async newTask(@Param('id') id: string, @Body() task: TaskDTO) {
return this.taskService.newTask(task);
}
}
import { IsString, Length, IsNumber, IsBoolean } from 'class-validator';
import { FactionEntity } from 'src/game/faction.entity';
export class TaskDTO {
@IsString()
@Length(3, 31)
taskName: string;
@IsString()
@Length(0, 255)
taskDescription: string;
@IsNumber()
@Length(1, 3)
taskScore: number;
@IsString()
@Length(3, 31)
taskWinner?: string;
@IsBoolean()
taskIsActive: boolean;
// faction unique id
@IsString()
faction: FactionEntity;
}
import { PrimaryGeneratedColumn, Column, Entity, ManyToOne } from 'typeorm';
import { FactionEntity } from 'src/game/faction.entity';
@Entity('Task')
export class TaskEntity {
@PrimaryGeneratedColumn('uuid') taskId: string;
@Column({ type: 'text' }) taskName: string;
@Column({ type: 'text' }) taskDescription: string;
@Column({ type: 'float' }) taskScore: number;
@Column({ type: 'text' }) taskWinner: string;
@Column({ type: 'bool' }) taskIsActive: boolean;
@ManyToOne(type => FactionEntity, faction => faction.factionId)
faction: FactionEntity;
}
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { TaskService } from './task.service';
import { TaskController } from './task.controller';
import { TaskEntity } from './task.entity';
@Module({
imports: [TypeOrmModule.forFeature([TaskEntity])],
controllers: [TaskController],
providers: [TaskService],
})
export class TaskModule {}
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { TaskEntity } from './task.entity';
import { TaskDTO } from './task.dto';
@Injectable()
export class TaskService {
constructor(
@InjectRepository(TaskEntity)
private taskRepository: Repository<TaskEntity>,
) {}
async newTask(task: TaskDTO) {
const createdTask = await this.taskRepository.create(task);
await this.taskRepository.insert(createdTask);
return {
message: 'Task added',
};
}
}
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