Initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export class CreateGameDto {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateGameDto } from './create-game.dto';
|
||||
|
||||
export class UpdateGameDto extends PartialType(CreateGameDto) {}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { GamesController } from './games.controller';
|
||||
import { GamesService } from './games.service';
|
||||
|
||||
describe('GamesController', () => {
|
||||
let controller: GamesController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [GamesController],
|
||||
providers: [GamesService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<GamesController>(GamesController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Body,
|
||||
Patch,
|
||||
Param,
|
||||
Delete,
|
||||
} from '@nestjs/common';
|
||||
import { GamesService } from './games.service';
|
||||
import { CreateGameDto } from './dto/create-game.dto';
|
||||
import { UpdateGameDto } from './dto/update-game.dto';
|
||||
|
||||
@Controller('games')
|
||||
export class GamesController {
|
||||
constructor(private readonly gamesService: GamesService) {}
|
||||
|
||||
@Post()
|
||||
create() {
|
||||
return this.gamesService.create();
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.gamesService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.gamesService.findOne(id);
|
||||
}
|
||||
|
||||
// @Patch(':id')
|
||||
// update(@Param('id') id: string, @Body() updateGameDto: UpdateGameDto) {
|
||||
// return this.gamesService.update(+id, updateGameDto);
|
||||
// }
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.gamesService.remove(+id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { GamesService } from './games.service';
|
||||
import { GamesController } from './games.controller';
|
||||
import { Game, GameSchema } from './schemas/game.schema';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { UsersModule } from 'src/users/users.module';
|
||||
import { CardsModule } from 'src/cards/cards.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
CardsModule,
|
||||
UsersModule,
|
||||
MongooseModule.forFeature([{ name: Game.name, schema: GameSchema }]),
|
||||
],
|
||||
controllers: [GamesController],
|
||||
providers: [GamesService],
|
||||
})
|
||||
export class GamesModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { GamesService } from './games.service';
|
||||
|
||||
describe('GamesService', () => {
|
||||
let service: GamesService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [GamesService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<GamesService>(GamesService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateGameDto } from './dto/create-game.dto';
|
||||
import { UpdateGameDto } from './dto/update-game.dto';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Game } from './schemas/game.schema';
|
||||
import { Model } from 'mongoose';
|
||||
|
||||
@Injectable()
|
||||
export class GamesService {
|
||||
constructor(@InjectModel(Game.name) private gameModel: Model<Game>) {}
|
||||
async create(): Promise<Game> {
|
||||
const createdGame = new this.gameModel();
|
||||
return createdGame.save();
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.gameModel.find();
|
||||
}
|
||||
|
||||
findOne(id: string) {
|
||||
return this.gameModel.find({ _id: id }).exec();
|
||||
}
|
||||
|
||||
// update(id: number, updateGameDto: UpdateGameDto) {
|
||||
// return `This action updates a #${id} game`;
|
||||
// }
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} game`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
||||
import mongoose, { HydratedDocument } from 'mongoose';
|
||||
import { Card } from 'src/cards/schemas/cards.schema';
|
||||
import { User } from 'src/users/schemas/user.entity';
|
||||
|
||||
export type GameDocument = HydratedDocument<Game>;
|
||||
|
||||
@Schema()
|
||||
class GameObject {}
|
||||
|
||||
@Schema()
|
||||
export class Team extends GameObject {}
|
||||
|
||||
export const TeamSchema = SchemaFactory.createForClass(Team);
|
||||
|
||||
@Schema()
|
||||
export class Container extends GameObject {
|
||||
@Prop([{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }])
|
||||
cards: Card[];
|
||||
}
|
||||
|
||||
export const ContainerSchema = SchemaFactory.createForClass(Container);
|
||||
|
||||
@Schema()
|
||||
export class Game extends GameObject {
|
||||
@Prop([Team])
|
||||
teams: Team[];
|
||||
|
||||
@Prop({ type: ContainerSchema, default: {} })
|
||||
market: Container;
|
||||
|
||||
@Prop({ type: ContainerSchema, default: {} })
|
||||
marketStack: Container;
|
||||
|
||||
@Prop({ type: ContainerSchema, default: {} })
|
||||
fireGems: Container;
|
||||
|
||||
@Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'Game.teams' })
|
||||
currentTurn?: Team;
|
||||
|
||||
@Prop({ default: false })
|
||||
started: boolean;
|
||||
|
||||
@Prop({ default: false })
|
||||
private ended: boolean;
|
||||
|
||||
@Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'User' })
|
||||
owner: User;
|
||||
}
|
||||
|
||||
export const GameSchema = SchemaFactory.createForClass(Game);
|
||||
Reference in New Issue
Block a user