From 63a37bd3a081b942d660147f6068b8f201e3a9fc Mon Sep 17 00:00:00 2001 From: Manish Biswal <146447671+iamanishx@users.noreply.github.com> Date: Sat, 21 Dec 2024 12:10:40 +0530 Subject: [PATCH 1/4] review --- src/app.module.ts | 10 +++ src/services/apis/matches/dto/matches.dto.ts | 53 ++++++++++++++ .../apis/matches/matches.controller.spec.ts | 18 +++++ .../apis/matches/matches.controller.ts | 48 +++++++++++++ src/services/apis/matches/matches.module.ts | 15 ++++ .../apis/matches/matches.service.spec.ts | 18 +++++ src/services/apis/matches/matches.service.ts | 15 ++++ .../apis/matches/schemas/matches.schema.ts | 70 +++++++++++++++++++ src/services/apis/squad/dto/squad.dto.ts | 53 ++++++++++++++ .../apis/squad/schemas/squad.schema.ts | 45 ++++++++++++ .../apis/squad/squad.controller.spec.ts | 18 +++++ src/services/apis/squad/squad.controller.ts | 56 +++++++++++++++ src/services/apis/squad/squad.module.ts | 15 ++++ src/services/apis/squad/squad.service.spec.ts | 18 +++++ src/services/apis/squad/squad.service.ts | 24 +++++++ .../apis/squadPlayer/dto/squadPlayer.dto.ts | 53 ++++++++++++++ .../squadPlayer/schemas/squadPlayer.schema.ts | 60 ++++++++++++++++ .../squadPlayer.controller.spec.ts | 18 +++++ .../squadPlayer/squadPlayer.controller.ts | 48 +++++++++++++ .../apis/squadPlayer/squadPlayer.module.ts | 17 +++++ .../squadPlayer/squadPlayer.service.spec.ts | 18 +++++ .../apis/squadPlayer/squadPlayer.service.ts | 18 +++++ src/services/apis/team/dto/team.dto.ts | 53 ++++++++++++++ src/services/apis/team/schemas/team.schema.ts | 65 +++++++++++++++++ .../apis/team/team.controller.spec.ts | 18 +++++ src/services/apis/team/team.controller.ts | 48 +++++++++++++ src/services/apis/team/team.module.ts | 15 ++++ src/services/apis/team/team.service.spec.ts | 18 +++++ src/services/apis/team/team.service.ts | 15 ++++ .../apis/teamPlayer/dto/teamPlayer.dto.ts | 53 ++++++++++++++ .../teamPlayer/schemas/teamPlayer.schema.ts | 51 ++++++++++++++ .../teamPlayer/teamPlayer.controller.spec.ts | 18 +++++ .../apis/teamPlayer/teamPlayer.controller.ts | 48 +++++++++++++ .../apis/teamPlayer/teamPlayer.module.ts | 17 +++++ .../teamPlayer/teamPlayer.service.spec.ts | 18 +++++ .../apis/teamPlayer/teamPlayer.service.ts | 18 +++++ 36 files changed, 1163 insertions(+) create mode 100644 src/services/apis/matches/dto/matches.dto.ts create mode 100644 src/services/apis/matches/matches.controller.spec.ts create mode 100644 src/services/apis/matches/matches.controller.ts create mode 100644 src/services/apis/matches/matches.module.ts create mode 100644 src/services/apis/matches/matches.service.spec.ts create mode 100644 src/services/apis/matches/matches.service.ts create mode 100644 src/services/apis/matches/schemas/matches.schema.ts create mode 100644 src/services/apis/squad/dto/squad.dto.ts create mode 100644 src/services/apis/squad/schemas/squad.schema.ts create mode 100644 src/services/apis/squad/squad.controller.spec.ts create mode 100644 src/services/apis/squad/squad.controller.ts create mode 100644 src/services/apis/squad/squad.module.ts create mode 100644 src/services/apis/squad/squad.service.spec.ts create mode 100644 src/services/apis/squad/squad.service.ts create mode 100644 src/services/apis/squadPlayer/dto/squadPlayer.dto.ts create mode 100644 src/services/apis/squadPlayer/schemas/squadPlayer.schema.ts create mode 100644 src/services/apis/squadPlayer/squadPlayer.controller.spec.ts create mode 100644 src/services/apis/squadPlayer/squadPlayer.controller.ts create mode 100644 src/services/apis/squadPlayer/squadPlayer.module.ts create mode 100644 src/services/apis/squadPlayer/squadPlayer.service.spec.ts create mode 100644 src/services/apis/squadPlayer/squadPlayer.service.ts create mode 100644 src/services/apis/team/dto/team.dto.ts create mode 100644 src/services/apis/team/schemas/team.schema.ts create mode 100644 src/services/apis/team/team.controller.spec.ts create mode 100644 src/services/apis/team/team.controller.ts create mode 100644 src/services/apis/team/team.module.ts create mode 100644 src/services/apis/team/team.service.spec.ts create mode 100644 src/services/apis/team/team.service.ts create mode 100644 src/services/apis/teamPlayer/dto/teamPlayer.dto.ts create mode 100644 src/services/apis/teamPlayer/schemas/teamPlayer.schema.ts create mode 100644 src/services/apis/teamPlayer/teamPlayer.controller.spec.ts create mode 100644 src/services/apis/teamPlayer/teamPlayer.controller.ts create mode 100644 src/services/apis/teamPlayer/teamPlayer.module.ts create mode 100644 src/services/apis/teamPlayer/teamPlayer.service.spec.ts create mode 100644 src/services/apis/teamPlayer/teamPlayer.service.ts diff --git a/src/app.module.ts b/src/app.module.ts index 04e51a7..cad0724 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -14,6 +14,11 @@ import { ReactionsModule } from './services/apis/reactions/reactions.module'; import { ProfilesModule } from './services/apis/profiles/profiles.module'; import { QueueModule } from './services/bullmq/queue.module'; import { BullModule } from '@nestjs/bullmq'; +import { MatchesModule } from './services/apis/matches/matches.module'; +import { SquadModule } from './services/apis/squad/squad.module'; +import { SquadPlayerModule } from './services/apis/squadPlayer/squadPlayer.module'; +import { TeamModule } from './services/apis/team/team.module'; +import { TeamPlayerModule } from './services/apis/teamPlayer/teamPlayer.module'; @Module({ imports: [ @@ -41,6 +46,11 @@ import { BullModule } from '@nestjs/bullmq'; AuthModule, UsersModule, AdapterModule, + MatchesModule, + SquadModule, + SquadPlayerModule, + TeamModule, + TeamPlayerModule, ProfilesModule, ReactionsModule, ], diff --git a/src/services/apis/matches/dto/matches.dto.ts b/src/services/apis/matches/dto/matches.dto.ts new file mode 100644 index 0000000..edb3513 --- /dev/null +++ b/src/services/apis/matches/dto/matches.dto.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; +import { Types } from 'mongoose'; + +export const CreateMatchesValidation = z.object({ + name: z.string().optional(), + createdBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid creator ID', + }) + .optional(), + createdAt: z.date().optional(), + updatedAt: z.date().optional(), + deleted: z.boolean().optional().default(false), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export const PatchMatchesValidation = z.object({ + name: z.string().optional(), + updatedAt: z.date().optional(), + createdAt: z.date().optional(), + deleted: z.boolean().optional(), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export const RemoveMatchesValidation = z.object({ + id: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid user ID', + }), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export type CreateMatchesDTO = z.infer; +export type PatchMatchesDTO = z.infer; +export type RemoveMatchesDTO = z.infer; diff --git a/src/services/apis/matches/matches.controller.spec.ts b/src/services/apis/matches/matches.controller.spec.ts new file mode 100644 index 0000000..548ffe5 --- /dev/null +++ b/src/services/apis/matches/matches.controller.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { MatchesController } from './matches.controller'; + +describe('MatchesController', () => { + let controller: MatchesController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [MatchesController], + }).compile(); + + controller = module.get(MatchesController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/src/services/apis/matches/matches.controller.ts b/src/services/apis/matches/matches.controller.ts new file mode 100644 index 0000000..174fd49 --- /dev/null +++ b/src/services/apis/matches/matches.controller.ts @@ -0,0 +1,48 @@ +import { + Body, + Controller, + Delete, + Get, + Param, + Patch, + Post, + Query, +} from '@nestjs/common'; +import { MatchesService } from './matches.service'; +import { ModifyBody, setCreatedBy } from 'src/decorators/ModifyBody.decorator'; +import { User } from '../users/decorator/user.decorator'; +import { Matches } from './schemas/matches.schema'; + +@Controller('matches') +export class MatchesController { + constructor(private readonly matchesService: MatchesService) {} + + @Get() + async find(@Query() query: Record) { + return await this.matchesService._find(query); + } + + @Get('/:id?') + async get(@Query() query: Record, @Param('id') id: string) { + return await this.matchesService._get(id, query); + } + + @Post() + async create(@ModifyBody(setCreatedBy()) createMatchesDto: Matches) { + return await this.matchesService._create(createMatchesDto); + } + + @Patch('/:id?') + async patch( + @Query() query, + @Body() patchMatchesDto: Partial, + @Param('id') id, + ) { + return await this.matchesService._patch(id, patchMatchesDto, query); + } + + @Delete('/:id?') + async delete(@Param('id') id, @Query() query, @User() user) { + return await this.matchesService._remove(id, query, user); + } +} diff --git a/src/services/apis/matches/matches.module.ts b/src/services/apis/matches/matches.module.ts new file mode 100644 index 0000000..8922874 --- /dev/null +++ b/src/services/apis/matches/matches.module.ts @@ -0,0 +1,15 @@ +import { Module } from '@nestjs/common'; +import { MongooseModule } from '@nestjs/mongoose'; +import { MatchesController } from './matches.controller'; +import { MatchesService } from './matches.service'; +import { Matches, MatchesSchema } from './schemas/matches.schema'; + +@Module({ + imports: [ + MongooseModule.forFeature([{ name: Matches.name, schema: MatchesSchema }]), + ], + controllers: [MatchesController], + providers: [MatchesService], + exports: [MatchesService], +}) +export class MatchesModule {} diff --git a/src/services/apis/matches/matches.service.spec.ts b/src/services/apis/matches/matches.service.spec.ts new file mode 100644 index 0000000..f78f3ca --- /dev/null +++ b/src/services/apis/matches/matches.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { MatchesService } from './matches.service'; + +describe('MatchesService', () => { + let service: MatchesService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [MatchesService], + }).compile(); + + service = module.get(MatchesService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/src/services/apis/matches/matches.service.ts b/src/services/apis/matches/matches.service.ts new file mode 100644 index 0000000..d082a41 --- /dev/null +++ b/src/services/apis/matches/matches.service.ts @@ -0,0 +1,15 @@ +import { Injectable } from '@nestjs/common'; +import { GlobalService } from 'src/common/global-service'; +import { Matches, MatchesDocument } from './schemas/matches.schema'; +import { InjectModel } from '@nestjs/mongoose'; +import { Model } from 'mongoose'; + +@Injectable() +export class MatchesService extends GlobalService { + constructor( + @InjectModel(Matches.name) + private readonly matchesModel: Model, + ) { + super(matchesModel); + } +} diff --git a/src/services/apis/matches/schemas/matches.schema.ts b/src/services/apis/matches/schemas/matches.schema.ts new file mode 100644 index 0000000..febd6c8 --- /dev/null +++ b/src/services/apis/matches/schemas/matches.schema.ts @@ -0,0 +1,70 @@ +import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; +import { HydratedDocument, Types } from 'mongoose'; +import { Users } from '../../users/schemas/users.schema'; + +export type MatchesDocument = HydratedDocument; + +@Schema({ + timestamps: true, +}) +export class Matches { + @Prop({ trim: true, required: true }) + name: string; + + @Prop({ + type: Types.ObjectId, + ref: 'Squad', + required: true, + }) + squadId: Types.ObjectId; + + @Prop({ + type: Types.ObjectId, + ref: 'Team', + required: true, + }) + teamId: Types.ObjectId; + + @Prop({ + type: Types.ObjectId, + ref: Users.name, + required: true, + }) + captainId: Types.ObjectId; + + @Prop({ + type: Types.ObjectId, + ref: Users.name, + required: true, + }) + createdBy: Types.ObjectId; + + @Prop({ + type: Date, + required: true, + }) + matchDate: Date; + + @Prop({ + type: String, + enum: ['SCHEDULED', 'IN_PROGRESS', 'COMPLETED', 'CANCELLED'], + default: 'SCHEDULED', + }) + status: string; + + @Prop({ default: false }) + deleted: boolean; + + @Prop({ + type: Types.ObjectId, + ref: Users.name, + }) + deletedBy: Types.ObjectId; + + @Prop({ + type: Date, + }) + deletedAt: Date; +} + +export const MatchesSchema = SchemaFactory.createForClass(Matches); diff --git a/src/services/apis/squad/dto/squad.dto.ts b/src/services/apis/squad/dto/squad.dto.ts new file mode 100644 index 0000000..b6f70b4 --- /dev/null +++ b/src/services/apis/squad/dto/squad.dto.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; +import { Types } from 'mongoose'; + +export const CreateSquadValidation = z.object({ + name: z.string().optional(), + createdBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid creator ID', + }) + .optional(), + createdAt: z.date().optional(), + updatedAt: z.date().optional(), + deleted: z.boolean().optional().default(false), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export const PatchSquadValidation = z.object({ + name: z.string().optional(), + updatedAt: z.date().optional(), + createdAt: z.date().optional(), + deleted: z.boolean().optional(), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export const RemoveSquadValidation = z.object({ + id: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid user ID', + }), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export type CreateSquadDTO = z.infer; +export type PatchSquadDTO = z.infer; +export type RemoveSquadDTO = z.infer; diff --git a/src/services/apis/squad/schemas/squad.schema.ts b/src/services/apis/squad/schemas/squad.schema.ts new file mode 100644 index 0000000..8836487 --- /dev/null +++ b/src/services/apis/squad/schemas/squad.schema.ts @@ -0,0 +1,45 @@ +import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; +import { HydratedDocument, Types } from 'mongoose'; +import { Users } from '../../users/schemas/users.schema'; + +export type SquadDocument = HydratedDocument; + +@Schema({ + timestamps: true, +}) +export class Squad { + @Prop({ trim: true, required: true }) + name: string; + + @Prop({ trim: true }) + description?: string; + + @Prop({ + type: Types.ObjectId, + ref: Users.name, + required: true, + }) + createdBy: Types.ObjectId; + + @Prop({ + type: Types.ObjectId, + ref: Users.name, + }) + captainId: Types.ObjectId; + + @Prop({ default: false }) + deleted: boolean; + + @Prop({ + type: Types.ObjectId, + ref: Users.name, + }) + deletedBy: Types.ObjectId; + + @Prop({ + type: Date, + }) + deletedAt: Date; +} + +export const SquadSchema = SchemaFactory.createForClass(Squad); diff --git a/src/services/apis/squad/squad.controller.spec.ts b/src/services/apis/squad/squad.controller.spec.ts new file mode 100644 index 0000000..7dff7ad --- /dev/null +++ b/src/services/apis/squad/squad.controller.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { SquadController } from './squad.controller'; + +describe('SquadController', () => { + let controller: SquadController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [SquadController], + }).compile(); + + controller = module.get(SquadController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/src/services/apis/squad/squad.controller.ts b/src/services/apis/squad/squad.controller.ts new file mode 100644 index 0000000..2a4a7fe --- /dev/null +++ b/src/services/apis/squad/squad.controller.ts @@ -0,0 +1,56 @@ +import { + Body, + Controller, + Delete, + Get, + Param, + Patch, + Post, + Query, +} from '@nestjs/common'; +import { SquadService } from './squad.service'; +import { ModifyBody, setCreatedBy } from 'src/decorators/ModifyBody.decorator'; +import { User } from '../users/decorator/user.decorator'; +import { Squad } from './schemas/squad.schema'; + +@Controller('squad') +export class SquadController { + constructor(private readonly squadService: SquadService) {} + + @Get() + async find(@Query() query: Record) { + return await this.squadService._find(query); + } + + @Get('/:id?') + async get(@Query() query: Record, @Param('id') id: string) { + return await this.squadService._get(id, query); + } + + @Post() + async create(@ModifyBody(setCreatedBy()) createSquadDto: Squad) { + return await this.squadService._create(createSquadDto); + } + + @Patch('/:id?') + async patch( + @Query() query, + @Body() patchSquadDto: Partial, + @Param('id') id, + ) { + return await this.squadService._patch(id, patchSquadDto, query); + } + + @Patch('/:id/assign-captain') + async assignCaptain( + @Param('id') id, + @Body() { captainId }: { captainId: string }, + ) { + return await this.squadService.assignCaptain(id, captainId); + } + + @Delete('/:id?') + async delete(@Param('id') id, @Query() query, @User() user) { + return await this.squadService._remove(id, query, user); + } +} diff --git a/src/services/apis/squad/squad.module.ts b/src/services/apis/squad/squad.module.ts new file mode 100644 index 0000000..c6cab9d --- /dev/null +++ b/src/services/apis/squad/squad.module.ts @@ -0,0 +1,15 @@ +import { Module } from '@nestjs/common'; +import { MongooseModule } from '@nestjs/mongoose'; +import { SquadController } from './squad.controller'; +import { SquadService } from './squad.service'; +import { Squad, SquadSchema } from './schemas/squad.schema'; + +@Module({ + imports: [ + MongooseModule.forFeature([{ name: Squad.name, schema: SquadSchema }]), + ], + controllers: [SquadController], + providers: [SquadService], + exports: [SquadService], +}) +export class SquadModule {} diff --git a/src/services/apis/squad/squad.service.spec.ts b/src/services/apis/squad/squad.service.spec.ts new file mode 100644 index 0000000..25bef36 --- /dev/null +++ b/src/services/apis/squad/squad.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { SquadService } from './squad.service'; + +describe('SquadService', () => { + let service: SquadService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [SquadService], + }).compile(); + + service = module.get(SquadService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/src/services/apis/squad/squad.service.ts b/src/services/apis/squad/squad.service.ts new file mode 100644 index 0000000..9b8e3bc --- /dev/null +++ b/src/services/apis/squad/squad.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@nestjs/common'; +import { GlobalService } from 'src/common/global-service'; +import { Squad, SquadDocument } from './schemas/squad.schema'; +import { InjectModel } from '@nestjs/mongoose'; +import { Model } from 'mongoose'; + +@Injectable() +export class SquadService extends GlobalService { + constructor( + @InjectModel(Squad.name) + private readonly squadModel: Model, + ) { + super(squadModel); + } + + // Assign a captain to a squad + async assignCaptain(squadId: string, captainId: string): Promise { + return this.squadModel.findByIdAndUpdate( + squadId, + { captainId }, + { new: true }, + ); + } +} diff --git a/src/services/apis/squadPlayer/dto/squadPlayer.dto.ts b/src/services/apis/squadPlayer/dto/squadPlayer.dto.ts new file mode 100644 index 0000000..7b45096 --- /dev/null +++ b/src/services/apis/squadPlayer/dto/squadPlayer.dto.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; +import { Types } from 'mongoose'; + +export const CreateSquadPlayerValidation = z.object({ + name: z.string().optional(), + createdBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid creator ID', + }) + .optional(), + createdAt: z.date().optional(), + updatedAt: z.date().optional(), + deleted: z.boolean().optional().default(false), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export const PatchSquadPlayerValidation = z.object({ + name: z.string().optional(), + updatedAt: z.date().optional(), + createdAt: z.date().optional(), + deleted: z.boolean().optional(), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export const RemoveSquadPlayerValidation = z.object({ + id: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid user ID', + }), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export type CreateSquadPlayerDTO = z.infer; +export type PatchSquadPlayerDTO = z.infer; +export type RemoveSquadPlayerDTO = z.infer; diff --git a/src/services/apis/squadPlayer/schemas/squadPlayer.schema.ts b/src/services/apis/squadPlayer/schemas/squadPlayer.schema.ts new file mode 100644 index 0000000..2f6cfac --- /dev/null +++ b/src/services/apis/squadPlayer/schemas/squadPlayer.schema.ts @@ -0,0 +1,60 @@ +import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; +import { HydratedDocument, Types } from 'mongoose'; +import { Users } from '../../users/schemas/users.schema'; +import { Squad } from '../../squad/schemas/squad.schema'; // Import Squad schema for relationships. + +export type SquadPlayerDocument = HydratedDocument; + +@Schema({ + timestamps: true, +}) +export class SquadPlayer { + @Prop({ + type: Types.ObjectId, + ref: Squad.name, + required: true, + }) + squadId: Types.ObjectId; // Relationship: Links to Squad. + + @Prop({ + type: Types.ObjectId, + ref: Users.name, + required: true, + }) + playerId: Types.ObjectId; // Relationship: Links to User (player). + + @Prop({ + type: String, + enum: ['pending', 'approved', 'rejected'], + default: 'pending', + }) + status: string; // Player request status: pending, approved, or rejected. + + @Prop({ + type: Date, + default: null, + }) + requestedAt: Date; // Timestamp for when the player requested to join. + + @Prop({ + type: Date, + default: null, + }) + approvedAt: Date; // Timestamp for when the player request was approved. + + @Prop({ default: false }) + deleted: boolean; // Soft delete flag. + + @Prop({ + type: Types.ObjectId, + ref: Users.name, + }) + deletedBy: Types.ObjectId; // Who deleted this record? + + @Prop({ + type: Date, + }) + deletedAt: Date; // When it was deleted. +} + +export const SquadPlayerSchema = SchemaFactory.createForClass(SquadPlayer); diff --git a/src/services/apis/squadPlayer/squadPlayer.controller.spec.ts b/src/services/apis/squadPlayer/squadPlayer.controller.spec.ts new file mode 100644 index 0000000..7f3bf4c --- /dev/null +++ b/src/services/apis/squadPlayer/squadPlayer.controller.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { SquadPlayerController } from './squadPlayer.controller'; + +describe('SquadPlayerController', () => { + let controller: SquadPlayerController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [SquadPlayerController], + }).compile(); + + controller = module.get(SquadPlayerController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/src/services/apis/squadPlayer/squadPlayer.controller.ts b/src/services/apis/squadPlayer/squadPlayer.controller.ts new file mode 100644 index 0000000..5ef38ab --- /dev/null +++ b/src/services/apis/squadPlayer/squadPlayer.controller.ts @@ -0,0 +1,48 @@ +import { + Body, + Controller, + Delete, + Get, + Param, + Patch, + Post, + Query, +} from '@nestjs/common'; +import { SquadPlayerService } from './squadPlayer.service'; +import { ModifyBody, setCreatedBy } from 'src/decorators/ModifyBody.decorator'; +import { User } from '../users/decorator/user.decorator'; +import { SquadPlayer } from './schemas/squadPlayer.schema'; + +@Controller('squad-player') +export class SquadPlayerController { + constructor(private readonly squadPlayerService: SquadPlayerService) {} + + @Get() + async find(@Query() query: Record) { + return await this.squadPlayerService._find(query); + } + + @Get('/:id?') + async get(@Query() query: Record, @Param('id') id: string) { + return await this.squadPlayerService._get(id, query); + } + + @Post() + async create(@ModifyBody(setCreatedBy()) createSquadPlayerDto: SquadPlayer) { + return await this.squadPlayerService._create(createSquadPlayerDto); + } + + @Patch('/:id?') + async patch( + @Query() query, + @Body() patchSquadPlayerDto: Partial, + @Param('id') id, + ) { + return await this.squadPlayerService._patch(id, patchSquadPlayerDto, query); + } + + @Delete('/:id?') + async delete(@Param('id') id, @Query() query, @User() user) { + return await this.squadPlayerService._remove(id, query, user); + } +} diff --git a/src/services/apis/squadPlayer/squadPlayer.module.ts b/src/services/apis/squadPlayer/squadPlayer.module.ts new file mode 100644 index 0000000..de4e0ae --- /dev/null +++ b/src/services/apis/squadPlayer/squadPlayer.module.ts @@ -0,0 +1,17 @@ +import { Module } from '@nestjs/common'; +import { MongooseModule } from '@nestjs/mongoose'; +import { SquadPlayerController } from './squadPlayer.controller'; +import { SquadPlayerService } from './squadPlayer.service'; +import { SquadPlayer, SquadPlayerSchema } from './schemas/squadPlayer.schema'; + +@Module({ + imports: [ + MongooseModule.forFeature([ + { name: SquadPlayer.name, schema: SquadPlayerSchema }, + ]), + ], + controllers: [SquadPlayerController], + providers: [SquadPlayerService], + exports: [SquadPlayerService], +}) +export class SquadPlayerModule {} diff --git a/src/services/apis/squadPlayer/squadPlayer.service.spec.ts b/src/services/apis/squadPlayer/squadPlayer.service.spec.ts new file mode 100644 index 0000000..81efc9e --- /dev/null +++ b/src/services/apis/squadPlayer/squadPlayer.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { SquadPlayerService } from './squadPlayer.service'; + +describe('SquadPlayerService', () => { + let service: SquadPlayerService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [SquadPlayerService], + }).compile(); + + service = module.get(SquadPlayerService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/src/services/apis/squadPlayer/squadPlayer.service.ts b/src/services/apis/squadPlayer/squadPlayer.service.ts new file mode 100644 index 0000000..29e171b --- /dev/null +++ b/src/services/apis/squadPlayer/squadPlayer.service.ts @@ -0,0 +1,18 @@ +import { Injectable } from '@nestjs/common'; +import { GlobalService } from 'src/common/global-service'; +import { SquadPlayer, SquadPlayerDocument } from './schemas/squadPlayer.schema'; +import { InjectModel } from '@nestjs/mongoose'; +import { Model } from 'mongoose'; + +@Injectable() +export class SquadPlayerService extends GlobalService< + SquadPlayer, + SquadPlayerDocument +> { + constructor( + @InjectModel(SquadPlayer.name) + private readonly squadPlayerModel: Model, + ) { + super(squadPlayerModel); + } +} diff --git a/src/services/apis/team/dto/team.dto.ts b/src/services/apis/team/dto/team.dto.ts new file mode 100644 index 0000000..ecb21cb --- /dev/null +++ b/src/services/apis/team/dto/team.dto.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; +import { Types } from 'mongoose'; + +export const CreateTeamValidation = z.object({ + name: z.string().optional(), + createdBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid creator ID', + }) + .optional(), + createdAt: z.date().optional(), + updatedAt: z.date().optional(), + deleted: z.boolean().optional().default(false), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export const PatchTeamValidation = z.object({ + name: z.string().optional(), + updatedAt: z.date().optional(), + createdAt: z.date().optional(), + deleted: z.boolean().optional(), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export const RemoveTeamValidation = z.object({ + id: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid user ID', + }), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export type CreateTeamDTO = z.infer; +export type PatchTeamDTO = z.infer; +export type RemoveTeamDTO = z.infer; diff --git a/src/services/apis/team/schemas/team.schema.ts b/src/services/apis/team/schemas/team.schema.ts new file mode 100644 index 0000000..d558a16 --- /dev/null +++ b/src/services/apis/team/schemas/team.schema.ts @@ -0,0 +1,65 @@ +import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; +import { HydratedDocument, Types } from 'mongoose'; +import { Users } from '../../users/schemas/users.schema'; + +@Schema({ + timestamps: true, +}) +export class Team { + @Prop({ + trim: true, + required: true, + }) + name: string; + + @Prop({ + type: Types.ObjectId, + ref: 'Squad', + required: true, + }) + squadId: Types.ObjectId; + + @Prop({ + type: Types.ObjectId, + ref: 'Match', + required: true, + }) + matchId: Types.ObjectId; + + @Prop({ + type: Types.ObjectId, + ref: Users.name, + required: true, + }) + captainId: Types.ObjectId; + + @Prop({ + type: Number, + required: true, + min: 1, + }) + maxPlayers: number; // e.g., 11 for cricket + + @Prop({ + type: Types.ObjectId, + ref: Users.name, + required: true, + }) + createdBy: Types.ObjectId; + + @Prop({ default: false }) + deleted: boolean; + + @Prop({ + type: Types.ObjectId, + ref: Users.name, + }) + deletedBy: Types.ObjectId; + + @Prop({ + type: Date, + }) + deletedAt: Date; +} + +export const TeamSchema = SchemaFactory.createForClass(Team); diff --git a/src/services/apis/team/team.controller.spec.ts b/src/services/apis/team/team.controller.spec.ts new file mode 100644 index 0000000..44a56e7 --- /dev/null +++ b/src/services/apis/team/team.controller.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { TeamController } from './team.controller'; + +describe('TeamController', () => { + let controller: TeamController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [TeamController], + }).compile(); + + controller = module.get(TeamController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/src/services/apis/team/team.controller.ts b/src/services/apis/team/team.controller.ts new file mode 100644 index 0000000..85fc473 --- /dev/null +++ b/src/services/apis/team/team.controller.ts @@ -0,0 +1,48 @@ +import { + Body, + Controller, + Delete, + Get, + Param, + Patch, + Post, + Query, +} from '@nestjs/common'; +import { TeamService } from './team.service'; +import { ModifyBody, setCreatedBy } from 'src/decorators/ModifyBody.decorator'; +import { User } from '../users/decorator/user.decorator'; +import { Team } from './schemas/team.schema'; + +@Controller('team') +export class TeamController { + constructor(private readonly teamService: TeamService) {} + + @Get() + async find(@Query() query: Record) { + return await this.teamService._find(query); + } + + @Get('/:id?') + async get(@Query() query: Record, @Param('id') id: string) { + return await this.teamService._get(id, query); + } + + @Post() + async create(@ModifyBody(setCreatedBy()) createTeamDto: Team) { + return await this.teamService._create(createTeamDto); + } + + @Patch('/:id?') + async patch( + @Query() query, + @Body() patchTeamDto: Partial, + @Param('id') id, + ) { + return await this.teamService._patch(id, patchTeamDto, query); + } + + @Delete('/:id?') + async delete(@Param('id') id, @Query() query, @User() user) { + return await this.teamService._remove(id, query, user); + } +} diff --git a/src/services/apis/team/team.module.ts b/src/services/apis/team/team.module.ts new file mode 100644 index 0000000..1736851 --- /dev/null +++ b/src/services/apis/team/team.module.ts @@ -0,0 +1,15 @@ +import { Module } from '@nestjs/common'; +import { MongooseModule } from '@nestjs/mongoose'; +import { TeamController } from './team.controller'; +import { TeamService } from './team.service'; +import { Team, TeamSchema } from './schemas/team.schema'; + +@Module({ + imports: [ + MongooseModule.forFeature([{ name: Team.name, schema: TeamSchema }]), + ], + controllers: [TeamController], + providers: [TeamService], + exports: [TeamService], +}) +export class TeamModule {} diff --git a/src/services/apis/team/team.service.spec.ts b/src/services/apis/team/team.service.spec.ts new file mode 100644 index 0000000..608ca5a --- /dev/null +++ b/src/services/apis/team/team.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { TeamService } from './team.service'; + +describe('TeamService', () => { + let service: TeamService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [TeamService], + }).compile(); + + service = module.get(TeamService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/src/services/apis/team/team.service.ts b/src/services/apis/team/team.service.ts new file mode 100644 index 0000000..4be126a --- /dev/null +++ b/src/services/apis/team/team.service.ts @@ -0,0 +1,15 @@ +import { Injectable } from '@nestjs/common'; +import { GlobalService } from 'src/common/global-service'; +import { Team, TeamDocument } from './schemas/team.schema'; +import { InjectModel } from '@nestjs/mongoose'; +import { Model } from 'mongoose'; + +@Injectable() +export class TeamService extends GlobalService { + constructor( + @InjectModel(Team.name) + private readonly teamModel: Model, + ) { + super(teamModel); + } +} diff --git a/src/services/apis/teamPlayer/dto/teamPlayer.dto.ts b/src/services/apis/teamPlayer/dto/teamPlayer.dto.ts new file mode 100644 index 0000000..8ee4054 --- /dev/null +++ b/src/services/apis/teamPlayer/dto/teamPlayer.dto.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; +import { Types } from 'mongoose'; + +export const CreateTeamPlayerValidation = z.object({ + name: z.string().optional(), + createdBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid creator ID', + }) + .optional(), + createdAt: z.date().optional(), + updatedAt: z.date().optional(), + deleted: z.boolean().optional().default(false), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export const PatchTeamPlayerValidation = z.object({ + name: z.string().optional(), + updatedAt: z.date().optional(), + createdAt: z.date().optional(), + deleted: z.boolean().optional(), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export const RemoveTeamPlayerValidation = z.object({ + id: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid user ID', + }), + deletedBy: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid deleter ID', + }) + .optional(), + deletedAt: z.date().optional(), +}); + +export type CreateTeamPlayerDTO = z.infer; +export type PatchTeamPlayerDTO = z.infer; +export type RemoveTeamPlayerDTO = z.infer; diff --git a/src/services/apis/teamPlayer/schemas/teamPlayer.schema.ts b/src/services/apis/teamPlayer/schemas/teamPlayer.schema.ts new file mode 100644 index 0000000..1e34057 --- /dev/null +++ b/src/services/apis/teamPlayer/schemas/teamPlayer.schema.ts @@ -0,0 +1,51 @@ +import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; +import { HydratedDocument, Types } from 'mongoose'; +import { Users } from '../../users/schemas/users.schema'; +import { Team } from '../../team/schemas/team.schema'; + +export type TeamPlayerDocument = HydratedDocument; + +@Schema({ + timestamps: true, +}) +export class TeamPlayer { + @Prop({ + type: Types.ObjectId, + ref: Team.name, + required: true, + }) + teamId: Types.ObjectId; + + @Prop({ + type: Types.ObjectId, + ref: Users.name, + required: true, + }) + playerId: Types.ObjectId; + + @Prop({ trim: true }) + role?: string; // e.g., "batsman", "bowler", "goalkeeper" + + @Prop({ + type: Types.ObjectId, + ref: Users.name, + required: true, + }) + createdBy: Types.ObjectId; + + @Prop({ default: false }) + deleted: boolean; + + @Prop({ + type: Types.ObjectId, + ref: Users.name, + }) + deletedBy: Types.ObjectId; + + @Prop({ + type: Date, + }) + deletedAt: Date; +} + +export const TeamPlayerSchema = SchemaFactory.createForClass(TeamPlayer); diff --git a/src/services/apis/teamPlayer/teamPlayer.controller.spec.ts b/src/services/apis/teamPlayer/teamPlayer.controller.spec.ts new file mode 100644 index 0000000..ce8dfe6 --- /dev/null +++ b/src/services/apis/teamPlayer/teamPlayer.controller.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { TeamPlayerController } from './teamPlayer.controller'; + +describe('TeamPlayerController', () => { + let controller: TeamPlayerController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [TeamPlayerController], + }).compile(); + + controller = module.get(TeamPlayerController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/src/services/apis/teamPlayer/teamPlayer.controller.ts b/src/services/apis/teamPlayer/teamPlayer.controller.ts new file mode 100644 index 0000000..edfe9fe --- /dev/null +++ b/src/services/apis/teamPlayer/teamPlayer.controller.ts @@ -0,0 +1,48 @@ +import { + Body, + Controller, + Delete, + Get, + Param, + Patch, + Post, + Query, +} from '@nestjs/common'; +import { TeamPlayerService } from './teamPlayer.service'; +import { ModifyBody, setCreatedBy } from 'src/decorators/ModifyBody.decorator'; +import { User } from '../users/decorator/user.decorator'; +import { TeamPlayer } from './schemas/teamPlayer.schema'; + +@Controller('team-player') +export class TeamPlayerController { + constructor(private readonly teamPlayerService: TeamPlayerService) {} + + @Get() + async find(@Query() query: Record) { + return await this.teamPlayerService._find(query); + } + + @Get('/:id?') + async get(@Query() query: Record, @Param('id') id: string) { + return await this.teamPlayerService._get(id, query); + } + + @Post() + async create(@ModifyBody(setCreatedBy()) createTeamPlayerDto: TeamPlayer) { + return await this.teamPlayerService._create(createTeamPlayerDto); + } + + @Patch('/:id?') + async patch( + @Query() query, + @Body() patchTeamPlayerDto: Partial, + @Param('id') id, + ) { + return await this.teamPlayerService._patch(id, patchTeamPlayerDto, query); + } + + @Delete('/:id?') + async delete(@Param('id') id, @Query() query, @User() user) { + return await this.teamPlayerService._remove(id, query, user); + } +} diff --git a/src/services/apis/teamPlayer/teamPlayer.module.ts b/src/services/apis/teamPlayer/teamPlayer.module.ts new file mode 100644 index 0000000..1431d9c --- /dev/null +++ b/src/services/apis/teamPlayer/teamPlayer.module.ts @@ -0,0 +1,17 @@ +import { Module } from '@nestjs/common'; +import { MongooseModule } from '@nestjs/mongoose'; +import { TeamPlayerController } from './teamPlayer.controller'; +import { TeamPlayerService } from './teamPlayer.service'; +import { TeamPlayer, TeamPlayerSchema } from './schemas/teamPlayer.schema'; + +@Module({ + imports: [ + MongooseModule.forFeature([ + { name: TeamPlayer.name, schema: TeamPlayerSchema }, + ]), + ], + controllers: [TeamPlayerController], + providers: [TeamPlayerService], + exports: [TeamPlayerService], +}) +export class TeamPlayerModule {} diff --git a/src/services/apis/teamPlayer/teamPlayer.service.spec.ts b/src/services/apis/teamPlayer/teamPlayer.service.spec.ts new file mode 100644 index 0000000..de545e0 --- /dev/null +++ b/src/services/apis/teamPlayer/teamPlayer.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { TeamPlayerService } from './teamPlayer.service'; + +describe('TeamPlayerService', () => { + let service: TeamPlayerService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [TeamPlayerService], + }).compile(); + + service = module.get(TeamPlayerService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/src/services/apis/teamPlayer/teamPlayer.service.ts b/src/services/apis/teamPlayer/teamPlayer.service.ts new file mode 100644 index 0000000..cf11236 --- /dev/null +++ b/src/services/apis/teamPlayer/teamPlayer.service.ts @@ -0,0 +1,18 @@ +import { Injectable } from '@nestjs/common'; +import { GlobalService } from 'src/common/global-service'; +import { TeamPlayer, TeamPlayerDocument } from './schemas/teamPlayer.schema'; +import { InjectModel } from '@nestjs/mongoose'; +import { Model } from 'mongoose'; + +@Injectable() +export class TeamPlayerService extends GlobalService< + TeamPlayer, + TeamPlayerDocument +> { + constructor( + @InjectModel(TeamPlayer.name) + private readonly teamPlayerModel: Model, + ) { + super(teamPlayerModel); + } +} From c578fb540e8a28476f0b0bee2575d846b735d06d Mon Sep 17 00:00:00 2001 From: Manish Biswal <146447671+iamanishx@users.noreply.github.com> Date: Wed, 25 Dec 2024 00:54:43 +0530 Subject: [PATCH 2/4] updated schema and dtos --- src/services/apis/matches/dto/matches.dto.ts | 53 +++++++++++-- .../apis/matches/schemas/matches.schema.ts | 65 +++++++--------- src/services/apis/squad/dto/squad.dto.ts | 52 ++++++------- .../apis/squad/schemas/squad.schema.ts | 39 +++------- .../apis/squadPlayer/dto/squadPlayer.dto.ts | 56 ++++++-------- .../squadPlayer/schemas/squadPlayer.schema.ts | 50 ++----------- src/services/apis/team/dto/team.dto.ts | 74 +++++++++++-------- src/services/apis/team/schemas/team.schema.ts | 62 +++------------- .../apis/teamPlayer/dto/teamPlayer.dto.ts | 61 ++++++++------- .../teamPlayer/schemas/teamPlayer.schema.ts | 43 ++--------- 10 files changed, 227 insertions(+), 328 deletions(-) diff --git a/src/services/apis/matches/dto/matches.dto.ts b/src/services/apis/matches/dto/matches.dto.ts index edb3513..9349f32 100644 --- a/src/services/apis/matches/dto/matches.dto.ts +++ b/src/services/apis/matches/dto/matches.dto.ts @@ -1,8 +1,32 @@ import { z } from 'zod'; import { Types } from 'mongoose'; +// Enums +const StageEnum = z.enum(['league', 'qualifier', 'final']); +const StatusEnum = z.enum([ + 'live', + 'upcoming', + 'concluded', + 'paused', + 'postponed', + 'cancelled', +]); +const OutcomeEnum = z.enum(['team1', 'team2', 'draw', 'no_result']); +const ReasonEnum = z.enum(['bad_weather', 'insufficient_time', 'other']); + export const CreateMatchesValidation = z.object({ - name: z.string().optional(), + scheduledFor: z.string(), + team1: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid team1 ID', + }), + team2: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid team2 ID', + }), + sport: z.string(), + stage: StageEnum, + status: StatusEnum, + outcome: OutcomeEnum.optional(), + reasonForIncompletion: ReasonEnum.optional(), createdBy: z .string() .refine((val) => Types.ObjectId.isValid(val), { @@ -22,7 +46,24 @@ export const CreateMatchesValidation = z.object({ }); export const PatchMatchesValidation = z.object({ - name: z.string().optional(), + scheduledFor: z.string().optional(), + team1: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid team1 ID', + }) + .optional(), + team2: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid team2 ID', + }) + .optional(), + sport: z.string().optional(), + stage: StageEnum.optional(), + status: StatusEnum.optional(), + outcome: OutcomeEnum.optional(), + reasonForIncompletion: ReasonEnum.optional(), updatedAt: z.date().optional(), createdAt: z.date().optional(), deleted: z.boolean().optional(), @@ -37,7 +78,7 @@ export const PatchMatchesValidation = z.object({ export const RemoveMatchesValidation = z.object({ id: z.string().refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid user ID', + message: 'Invalid matches ID', }), deletedBy: z .string() @@ -48,6 +89,6 @@ export const RemoveMatchesValidation = z.object({ deletedAt: z.date().optional(), }); -export type CreateMatchesDTO = z.infer; -export type PatchMatchesDTO = z.infer; -export type RemoveMatchesDTO = z.infer; +export type CreateMatchesDto = z.infer; +export type PatchMatchesDto = z.infer; +export type RemoveMatchesDto = z.infer; diff --git a/src/services/apis/matches/schemas/matches.schema.ts b/src/services/apis/matches/schemas/matches.schema.ts index febd6c8..a6ee69b 100644 --- a/src/services/apis/matches/schemas/matches.schema.ts +++ b/src/services/apis/matches/schemas/matches.schema.ts @@ -1,6 +1,5 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Types } from 'mongoose'; -import { Users } from '../../users/schemas/users.schema'; export type MatchesDocument = HydratedDocument; @@ -8,63 +7,51 @@ export type MatchesDocument = HydratedDocument; timestamps: true, }) export class Matches { - @Prop({ trim: true, required: true }) - name: string; + @Prop({ type: String, required: true }) + id: string; - @Prop({ - type: Types.ObjectId, - ref: 'Squad', - required: true, - }) - squadId: Types.ObjectId; + @Prop({ type: Date, required: true }) + scheduledFor: Date; - @Prop({ - type: Types.ObjectId, - ref: 'Team', - required: true, - }) - teamId: Types.ObjectId; + @Prop({ type: Date }) + concludedAt: Date; - @Prop({ - type: Types.ObjectId, - ref: Users.name, - required: true, - }) - captainId: Types.ObjectId; + @Prop({ type: Types.ObjectId, ref: 'Team', required: true }) + team1: Types.ObjectId; - @Prop({ - type: Types.ObjectId, - ref: Users.name, - required: true, - }) - createdBy: Types.ObjectId; + @Prop({ type: Types.ObjectId, ref: 'Team', required: true }) + team2: Types.ObjectId; + + @Prop({ type: String, required: true }) + sport: string; @Prop({ - type: Date, + type: String, + enum: ['league', 'qualifier', 'final'], required: true, }) - matchDate: Date; + stage: string; @Prop({ type: String, - enum: ['SCHEDULED', 'IN_PROGRESS', 'COMPLETED', 'CANCELLED'], - default: 'SCHEDULED', + enum: ['live', 'upcoming', 'concluded', 'paused', 'postponed', 'cancelled'], + default: 'upcoming', }) status: string; - @Prop({ default: false }) - deleted: boolean; - @Prop({ - type: Types.ObjectId, - ref: Users.name, + type: String, + enum: ['team1', 'team2', 'draw', 'no_result'], + default: 'no_result', }) - deletedBy: Types.ObjectId; + outcome: string; @Prop({ - type: Date, + type: String, + enum: ['bad_weather', 'insufficient_time', 'other'], + default: null, }) - deletedAt: Date; + reasonForIncompletion: string; } export const MatchesSchema = SchemaFactory.createForClass(Matches); diff --git a/src/services/apis/squad/dto/squad.dto.ts b/src/services/apis/squad/dto/squad.dto.ts index b6f70b4..c80f3a1 100644 --- a/src/services/apis/squad/dto/squad.dto.ts +++ b/src/services/apis/squad/dto/squad.dto.ts @@ -2,52 +2,42 @@ import { z } from 'zod'; import { Types } from 'mongoose'; export const CreateSquadValidation = z.object({ - name: z.string().optional(), - createdBy: z - .string() - .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid creator ID', - }) - .optional(), + branch: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid branch ID', + }), + name: z.string(), + season: z.string(), + sport: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid sport ID', + }), createdAt: z.date().optional(), updatedAt: z.date().optional(), - deleted: z.boolean().optional().default(false), - deletedBy: z +}); + +export const PatchSquadValidation = z.object({ + branch: z .string() .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid deleter ID', + message: 'Invalid branch ID', }) .optional(), - deletedAt: z.date().optional(), -}); - -export const PatchSquadValidation = z.object({ name: z.string().optional(), - updatedAt: z.date().optional(), - createdAt: z.date().optional(), - deleted: z.boolean().optional(), - deletedBy: z + season: z.string().optional(), + sport: z .string() .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid deleter ID', + message: 'Invalid sport ID', }) .optional(), - deletedAt: z.date().optional(), + updatedAt: z.date().optional(), }); export const RemoveSquadValidation = z.object({ id: z.string().refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid user ID', + message: 'Invalid squad ID', }), - deletedBy: z - .string() - .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid deleter ID', - }) - .optional(), - deletedAt: z.date().optional(), }); -export type CreateSquadDTO = z.infer; -export type PatchSquadDTO = z.infer; -export type RemoveSquadDTO = z.infer; +export type CreateSquadDto = z.infer; +export type PatchSquadDto = z.infer; +export type RemoveSquadDto = z.infer; diff --git a/src/services/apis/squad/schemas/squad.schema.ts b/src/services/apis/squad/schemas/squad.schema.ts index 8836487..65c23b2 100644 --- a/src/services/apis/squad/schemas/squad.schema.ts +++ b/src/services/apis/squad/schemas/squad.schema.ts @@ -1,6 +1,5 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Types } from 'mongoose'; -import { Users } from '../../users/schemas/users.schema'; export type SquadDocument = HydratedDocument; @@ -8,38 +7,20 @@ export type SquadDocument = HydratedDocument; timestamps: true, }) export class Squad { - @Prop({ trim: true, required: true }) - name: string; - - @Prop({ trim: true }) - description?: string; + @Prop({ required: true }) + id: string; - @Prop({ - type: Types.ObjectId, - ref: Users.name, - required: true, - }) - createdBy: Types.ObjectId; - - @Prop({ - type: Types.ObjectId, - ref: Users.name, - }) - captainId: Types.ObjectId; + @Prop({ type: String, required: true }) + name: string; - @Prop({ default: false }) - deleted: boolean; + @Prop({ type: String, required: true }) + branch: string; - @Prop({ - type: Types.ObjectId, - ref: Users.name, - }) - deletedBy: Types.ObjectId; + @Prop({ type: String }) + season: string; - @Prop({ - type: Date, - }) - deletedAt: Date; + @Prop({ type: String, required: true }) + sport: string; } export const SquadSchema = SchemaFactory.createForClass(Squad); diff --git a/src/services/apis/squadPlayer/dto/squadPlayer.dto.ts b/src/services/apis/squadPlayer/dto/squadPlayer.dto.ts index 7b45096..43bb6d9 100644 --- a/src/services/apis/squadPlayer/dto/squadPlayer.dto.ts +++ b/src/services/apis/squadPlayer/dto/squadPlayer.dto.ts @@ -1,53 +1,45 @@ +// squad_player.dto.ts import { z } from 'zod'; import { Types } from 'mongoose'; +// Enums +const SquadPlayerStatusEnum = z.enum(['approved', 'pending', 'rejected']); + export const CreateSquadPlayerValidation = z.object({ - name: z.string().optional(), - createdBy: z - .string() - .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid creator ID', - }) - .optional(), + squad: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid squad ID', + }), + user: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid user ID', + }), + status: SquadPlayerStatusEnum.default('pending'), createdAt: z.date().optional(), updatedAt: z.date().optional(), - deleted: z.boolean().optional().default(false), - deletedBy: z +}); + +export const PatchSquadPlayerValidation = z.object({ + squad: z .string() .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid deleter ID', + message: 'Invalid squad ID', }) .optional(), - deletedAt: z.date().optional(), -}); - -export const PatchSquadPlayerValidation = z.object({ - name: z.string().optional(), - updatedAt: z.date().optional(), - createdAt: z.date().optional(), - deleted: z.boolean().optional(), - deletedBy: z + user: z .string() .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid deleter ID', + message: 'Invalid user ID', }) .optional(), - deletedAt: z.date().optional(), + status: SquadPlayerStatusEnum.optional(), + updatedAt: z.date().optional(), }); export const RemoveSquadPlayerValidation = z.object({ id: z.string().refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid user ID', + message: 'Invalid squad_player ID', }), - deletedBy: z - .string() - .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid deleter ID', - }) - .optional(), - deletedAt: z.date().optional(), }); -export type CreateSquadPlayerDTO = z.infer; -export type PatchSquadPlayerDTO = z.infer; -export type RemoveSquadPlayerDTO = z.infer; +export type CreateSquadPlayerDto = z.infer; +export type PatchSquadPlayerDto = z.infer; +export type RemoveSquadPlayerDto = z.infer; diff --git a/src/services/apis/squadPlayer/schemas/squadPlayer.schema.ts b/src/services/apis/squadPlayer/schemas/squadPlayer.schema.ts index 2f6cfac..04bbd5e 100644 --- a/src/services/apis/squadPlayer/schemas/squadPlayer.schema.ts +++ b/src/services/apis/squadPlayer/schemas/squadPlayer.schema.ts @@ -1,60 +1,22 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Types } from 'mongoose'; -import { Users } from '../../users/schemas/users.schema'; -import { Squad } from '../../squad/schemas/squad.schema'; // Import Squad schema for relationships. - export type SquadPlayerDocument = HydratedDocument; @Schema({ timestamps: true, }) export class SquadPlayer { - @Prop({ - type: Types.ObjectId, - ref: Squad.name, - required: true, - }) - squadId: Types.ObjectId; // Relationship: Links to Squad. + @Prop({ type: Types.ObjectId, ref: 'Squad', required: true }) + squad: Types.ObjectId; - @Prop({ - type: Types.ObjectId, - ref: Users.name, - required: true, - }) - playerId: Types.ObjectId; // Relationship: Links to User (player). + @Prop({ type: Types.ObjectId, ref: 'User', required: true }) + user: Types.ObjectId; @Prop({ type: String, - enum: ['pending', 'approved', 'rejected'], + enum: ['approved', 'pending', 'rejected'], default: 'pending', }) - status: string; // Player request status: pending, approved, or rejected. - - @Prop({ - type: Date, - default: null, - }) - requestedAt: Date; // Timestamp for when the player requested to join. - - @Prop({ - type: Date, - default: null, - }) - approvedAt: Date; // Timestamp for when the player request was approved. - - @Prop({ default: false }) - deleted: boolean; // Soft delete flag. - - @Prop({ - type: Types.ObjectId, - ref: Users.name, - }) - deletedBy: Types.ObjectId; // Who deleted this record? - - @Prop({ - type: Date, - }) - deletedAt: Date; // When it was deleted. + status: string; } - export const SquadPlayerSchema = SchemaFactory.createForClass(SquadPlayer); diff --git a/src/services/apis/team/dto/team.dto.ts b/src/services/apis/team/dto/team.dto.ts index ecb21cb..aa1e23c 100644 --- a/src/services/apis/team/dto/team.dto.ts +++ b/src/services/apis/team/dto/team.dto.ts @@ -1,53 +1,67 @@ import { z } from 'zod'; import { Types } from 'mongoose'; +// Rename from Teams to Team for consistency export const CreateTeamValidation = z.object({ - name: z.string().optional(), - createdBy: z + match: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid match ID', + }), + captain: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid captain ID', + }), + viceCaptain: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid vice-captain ID', + }), + squad: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid squad ID', + }), + sport: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid sport ID', + }), + createdAt: z.date().optional(), + updatedAt: z.date().optional(), +}); + +export const PatchTeamValidation = z.object({ + match: z .string() .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid creator ID', + message: 'Invalid match ID', }) .optional(), - createdAt: z.date().optional(), - updatedAt: z.date().optional(), - deleted: z.boolean().optional().default(false), - deletedBy: z + captain: z .string() .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid deleter ID', + message: 'Invalid captain ID', }) .optional(), - deletedAt: z.date().optional(), -}); - -export const PatchTeamValidation = z.object({ - name: z.string().optional(), - updatedAt: z.date().optional(), - createdAt: z.date().optional(), - deleted: z.boolean().optional(), - deletedBy: z + viceCaptain: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid vice-captain ID', + }) + .optional(), + squad: z .string() .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid deleter ID', + message: 'Invalid squad ID', }) .optional(), - deletedAt: z.date().optional(), + sport: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid sport ID', + }) + .optional(), + updatedAt: z.date().optional(), }); export const RemoveTeamValidation = z.object({ id: z.string().refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid user ID', + message: 'Invalid team ID', }), - deletedBy: z - .string() - .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid deleter ID', - }) - .optional(), - deletedAt: z.date().optional(), }); -export type CreateTeamDTO = z.infer; -export type PatchTeamDTO = z.infer; -export type RemoveTeamDTO = z.infer; +export type CreateTeamDto = z.infer; +export type PatchTeamDto = z.infer; +export type RemoveTeamDto = z.infer; diff --git a/src/services/apis/team/schemas/team.schema.ts b/src/services/apis/team/schemas/team.schema.ts index d558a16..ec674b2 100644 --- a/src/services/apis/team/schemas/team.schema.ts +++ b/src/services/apis/team/schemas/team.schema.ts @@ -1,65 +1,27 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Types } from 'mongoose'; -import { Users } from '../../users/schemas/users.schema'; @Schema({ timestamps: true, }) export class Team { - @Prop({ - trim: true, - required: true, - }) - name: string; + @Prop({ required: true }) + id: string; - @Prop({ - type: Types.ObjectId, - ref: 'Squad', - required: true, - }) - squadId: Types.ObjectId; + @Prop({ type: Types.ObjectId, ref: 'Squad', required: true }) + squad: Types.ObjectId; - @Prop({ - type: Types.ObjectId, - ref: 'Match', - required: true, - }) - matchId: Types.ObjectId; + @Prop({ type: Types.ObjectId, ref: 'Match', required: true }) + match: Types.ObjectId; - @Prop({ - type: Types.ObjectId, - ref: Users.name, - required: true, - }) - captainId: Types.ObjectId; + @Prop({ type: Types.ObjectId, ref: 'User', required: true }) + captain: Types.ObjectId; - @Prop({ - type: Number, - required: true, - min: 1, - }) - maxPlayers: number; // e.g., 11 for cricket + @Prop({ type: Types.ObjectId, ref: 'User' }) + viceCaptain: Types.ObjectId; - @Prop({ - type: Types.ObjectId, - ref: Users.name, - required: true, - }) - createdBy: Types.ObjectId; - - @Prop({ default: false }) - deleted: boolean; - - @Prop({ - type: Types.ObjectId, - ref: Users.name, - }) - deletedBy: Types.ObjectId; - - @Prop({ - type: Date, - }) - deletedAt: Date; + @Prop({ type: String, required: true }) + sport: string; } export const TeamSchema = SchemaFactory.createForClass(Team); diff --git a/src/services/apis/teamPlayer/dto/teamPlayer.dto.ts b/src/services/apis/teamPlayer/dto/teamPlayer.dto.ts index 8ee4054..26b1c17 100644 --- a/src/services/apis/teamPlayer/dto/teamPlayer.dto.ts +++ b/src/services/apis/teamPlayer/dto/teamPlayer.dto.ts @@ -1,53 +1,50 @@ +// team_player.dto.ts import { z } from 'zod'; import { Types } from 'mongoose'; +// Enums +const TeamPlayerStatusEnum = z.enum([ + 'playing', + 'retired', + 'banned', + 'substituted', +]); + export const CreateTeamPlayerValidation = z.object({ - name: z.string().optional(), - createdBy: z - .string() - .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid creator ID', - }) - .optional(), + team: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid team ID', + }), + user: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid user ID', + }), + status: TeamPlayerStatusEnum.default('playing'), createdAt: z.date().optional(), updatedAt: z.date().optional(), - deleted: z.boolean().optional().default(false), - deletedBy: z +}); + +export const PatchTeamPlayerValidation = z.object({ + team: z .string() .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid deleter ID', + message: 'Invalid team ID', }) .optional(), - deletedAt: z.date().optional(), -}); - -export const PatchTeamPlayerValidation = z.object({ - name: z.string().optional(), - updatedAt: z.date().optional(), - createdAt: z.date().optional(), - deleted: z.boolean().optional(), - deletedBy: z + user: z .string() .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid deleter ID', + message: 'Invalid user ID', }) .optional(), - deletedAt: z.date().optional(), + status: TeamPlayerStatusEnum.optional(), + updatedAt: z.date().optional(), }); export const RemoveTeamPlayerValidation = z.object({ id: z.string().refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid user ID', + message: 'Invalid team_player ID', }), - deletedBy: z - .string() - .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid deleter ID', - }) - .optional(), - deletedAt: z.date().optional(), }); -export type CreateTeamPlayerDTO = z.infer; -export type PatchTeamPlayerDTO = z.infer; -export type RemoveTeamPlayerDTO = z.infer; +export type CreateTeamPlayerDto = z.infer; +export type PatchTeamPlayerDto = z.infer; +export type RemoveTeamPlayerDto = z.infer; diff --git a/src/services/apis/teamPlayer/schemas/teamPlayer.schema.ts b/src/services/apis/teamPlayer/schemas/teamPlayer.schema.ts index 1e34057..43c6cbb 100644 --- a/src/services/apis/teamPlayer/schemas/teamPlayer.schema.ts +++ b/src/services/apis/teamPlayer/schemas/teamPlayer.schema.ts @@ -1,7 +1,5 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Types } from 'mongoose'; -import { Users } from '../../users/schemas/users.schema'; -import { Team } from '../../team/schemas/team.schema'; export type TeamPlayerDocument = HydratedDocument; @@ -9,43 +7,18 @@ export type TeamPlayerDocument = HydratedDocument; timestamps: true, }) export class TeamPlayer { - @Prop({ - type: Types.ObjectId, - ref: Team.name, - required: true, - }) - teamId: Types.ObjectId; - - @Prop({ - type: Types.ObjectId, - ref: Users.name, - required: true, - }) - playerId: Types.ObjectId; - - @Prop({ trim: true }) - role?: string; // e.g., "batsman", "bowler", "goalkeeper" + @Prop({ type: Types.ObjectId, ref: 'Team', required: true }) + team: Types.ObjectId; - @Prop({ - type: Types.ObjectId, - ref: Users.name, - required: true, - }) - createdBy: Types.ObjectId; - - @Prop({ default: false }) - deleted: boolean; - - @Prop({ - type: Types.ObjectId, - ref: Users.name, - }) - deletedBy: Types.ObjectId; + @Prop({ type: Types.ObjectId, ref: 'User', required: true }) + user: Types.ObjectId; @Prop({ - type: Date, + type: String, + enum: ['playing', 'retired', 'banned', 'substituted'], + default: 'playing', }) - deletedAt: Date; + status: string; } export const TeamPlayerSchema = SchemaFactory.createForClass(TeamPlayer); From 63a5dd4e3bddd028b6eec568a1cc7e02e6d17be1 Mon Sep 17 00:00:00 2001 From: majorbruteforce Date: Wed, 25 Dec 2024 13:04:33 +0530 Subject: [PATCH 3/4] Refactor name and types --- src/constants/branches-enum.ts | 7 +++ src/constants/sports-enum.ts | 16 +++--- .../apis/matches/constants/MatchEnums.ts | 27 ++++++++++ src/services/apis/matches/dto/matches.dto.ts | 37 ++++++++------ .../apis/matches/schemas/matches.schema.ts | 50 ++++++++++++------- .../apis/profiles/dto/profiles.dto.ts | 6 +-- .../apis/profiles/schemas/profiles.schema.ts | 4 +- src/services/apis/squad/dto/squad.dto.ts | 3 ++ .../apis/squad/schemas/squad.schema.ts | 21 ++++---- src/services/apis/squad/squad.controller.ts | 6 +-- src/services/apis/squad/squad.module.ts | 4 +- src/services/apis/squad/squad.service.ts | 10 ++-- .../squadPlayer/constants/SquadPlayerEnum.ts | 5 ++ .../apis/squadPlayer/dto/squadPlayer.dto.ts | 5 +- .../squadPlayer/schemas/squadPlayer.schema.ts | 20 +++++--- src/services/apis/team/schemas/team.schema.ts | 27 ++++++---- .../teamPlayer/constants/TeamPlayerEnum.ts | 6 +++ .../apis/teamPlayer/dto/teamPlayer.dto.ts | 10 ++-- .../teamPlayer/schemas/teamPlayer.schema.ts | 13 ++--- 19 files changed, 176 insertions(+), 101 deletions(-) create mode 100644 src/constants/branches-enum.ts create mode 100644 src/services/apis/matches/constants/MatchEnums.ts create mode 100644 src/services/apis/squadPlayer/constants/SquadPlayerEnum.ts create mode 100644 src/services/apis/teamPlayer/constants/TeamPlayerEnum.ts diff --git a/src/constants/branches-enum.ts b/src/constants/branches-enum.ts new file mode 100644 index 0000000..ebdc6e6 --- /dev/null +++ b/src/constants/branches-enum.ts @@ -0,0 +1,7 @@ +export enum Branches { + Cse = 'CSE', + Etc = 'ETC', + Eee = 'EEE', + It = 'IT', + Ce = 'CE', +} diff --git a/src/constants/sports-enum.ts b/src/constants/sports-enum.ts index 2dce22d..178b891 100644 --- a/src/constants/sports-enum.ts +++ b/src/constants/sports-enum.ts @@ -1,4 +1,4 @@ -enum SportsEnum { +enum Sports { Football = 'Football', Cricket = 'Cricket', Badminton = 'Badminton', @@ -7,12 +7,12 @@ enum SportsEnum { } export const SportsEnumList = [ - SportsEnum.Football, - SportsEnum.Badminton, - SportsEnum.Basketball, - SportsEnum.Cricket, - SportsEnum.Football, - SportsEnum.Volleyball, + Sports.Football, + Sports.Badminton, + Sports.Basketball, + Sports.Cricket, + Sports.Football, + Sports.Volleyball, ]; -export default SportsEnum; +export default Sports; diff --git a/src/services/apis/matches/constants/MatchEnums.ts b/src/services/apis/matches/constants/MatchEnums.ts new file mode 100644 index 0000000..ac0b5af --- /dev/null +++ b/src/services/apis/matches/constants/MatchEnums.ts @@ -0,0 +1,27 @@ +export enum MatchStatus { + Live = 'LIVE', + Upcoming = 'UPCOMING', + Concluded = 'CONCLUDED', + Paused = 'PAUSED', + Postponed = 'POSTPONED', + Cancelled = 'CANCELLED', +} + +export enum MatchOutcome { + Team1 = 'TEAM1', + Team2 = 'TEAM2', + Draw = 'DRAW', + NoResult = 'NO_RESULT', +} + +export enum MatchIncompletionReason { + BadWeather = 'BAD_WEATHER', + InsufficientTime = 'INSUFFICIENT_TIME', + Other = 'OTHER', +} + +export enum MatchStage { + LEAGUE = 'LEAGUE', + QUALIFIER = 'QUALIFIER', + FINAL = 'FINAL', +} diff --git a/src/services/apis/matches/dto/matches.dto.ts b/src/services/apis/matches/dto/matches.dto.ts index 9349f32..44cd263 100644 --- a/src/services/apis/matches/dto/matches.dto.ts +++ b/src/services/apis/matches/dto/matches.dto.ts @@ -1,18 +1,16 @@ import { z } from 'zod'; import { Types } from 'mongoose'; +import { + MatchIncompletionReason, + MatchOutcome, + MatchStage, + MatchStatus, +} from '../constants/MatchEnums'; -// Enums -const StageEnum = z.enum(['league', 'qualifier', 'final']); -const StatusEnum = z.enum([ - 'live', - 'upcoming', - 'concluded', - 'paused', - 'postponed', - 'cancelled', -]); -const OutcomeEnum = z.enum(['team1', 'team2', 'draw', 'no_result']); -const ReasonEnum = z.enum(['bad_weather', 'insufficient_time', 'other']); +const StageEnum = z.nativeEnum(MatchStage); +const StatusEnum = z.nativeEnum(MatchStatus); +const OutcomeEnum = z.nativeEnum(MatchOutcome); +const IncompletionReasonEnum = z.nativeEnum(MatchIncompletionReason); export const CreateMatchesValidation = z.object({ scheduledFor: z.string(), @@ -22,11 +20,13 @@ export const CreateMatchesValidation = z.object({ team2: z.string().refine((val) => Types.ObjectId.isValid(val), { message: 'Invalid team2 ID', }), - sport: z.string(), + sport: z.string().refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid sport ID', + }), stage: StageEnum, status: StatusEnum, outcome: OutcomeEnum.optional(), - reasonForIncompletion: ReasonEnum.optional(), + reasonForIncompletion: IncompletionReasonEnum.optional(), createdBy: z .string() .refine((val) => Types.ObjectId.isValid(val), { @@ -59,11 +59,16 @@ export const PatchMatchesValidation = z.object({ message: 'Invalid team2 ID', }) .optional(), - sport: z.string().optional(), + sport: z + .string() + .refine((val) => Types.ObjectId.isValid(val), { + message: 'Invalid sport ID', + }) + .optional(), stage: StageEnum.optional(), status: StatusEnum.optional(), outcome: OutcomeEnum.optional(), - reasonForIncompletion: ReasonEnum.optional(), + reasonForIncompletion: IncompletionReasonEnum.optional(), updatedAt: z.date().optional(), createdAt: z.date().optional(), deleted: z.boolean().optional(), diff --git a/src/services/apis/matches/schemas/matches.schema.ts b/src/services/apis/matches/schemas/matches.schema.ts index a6ee69b..eb49a30 100644 --- a/src/services/apis/matches/schemas/matches.schema.ts +++ b/src/services/apis/matches/schemas/matches.schema.ts @@ -1,5 +1,12 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Types } from 'mongoose'; +import { + MatchIncompletionReason, + MatchOutcome, + MatchStage, + MatchStatus, +} from '../constants/MatchEnums'; +import { Teams } from '../../team/schemas/team.schema'; export type MatchesDocument = HydratedDocument; @@ -7,51 +14,58 @@ export type MatchesDocument = HydratedDocument; timestamps: true, }) export class Matches { - @Prop({ type: String, required: true }) - id: string; - @Prop({ type: Date, required: true }) scheduledFor: Date; @Prop({ type: Date }) concludedAt: Date; - @Prop({ type: Types.ObjectId, ref: 'Team', required: true }) + @Prop({ + type: Types.ObjectId, + ref: Teams.name, + required: true, + }) team1: Types.ObjectId; - @Prop({ type: Types.ObjectId, ref: 'Team', required: true }) + @Prop({ + type: Types.ObjectId, + ref: Teams.name, + required: true, + }) team2: Types.ObjectId; - @Prop({ type: String, required: true }) - sport: string; + @Prop({ + type: Types.ObjectId, + // ref: Sports.name // Include when sports entity is defined + required: true, + }) + sport: Types.ObjectId; @Prop({ type: String, - enum: ['league', 'qualifier', 'final'], + enum: Object.values(MatchStage), required: true, }) - stage: string; + stage: MatchStage; @Prop({ type: String, - enum: ['live', 'upcoming', 'concluded', 'paused', 'postponed', 'cancelled'], - default: 'upcoming', + enum: Object.values(MatchStatus), + default: MatchStatus.Upcoming, }) - status: string; + status: MatchStatus; @Prop({ type: String, - enum: ['team1', 'team2', 'draw', 'no_result'], - default: 'no_result', + enum: Object.values(MatchOutcome), }) - outcome: string; + outcome: MatchOutcome; @Prop({ type: String, - enum: ['bad_weather', 'insufficient_time', 'other'], - default: null, + enum: Object.values(MatchIncompletionReason), }) - reasonForIncompletion: string; + reasonForIncompletion: MatchIncompletionReason; } export const MatchesSchema = SchemaFactory.createForClass(Matches); diff --git a/src/services/apis/profiles/dto/profiles.dto.ts b/src/services/apis/profiles/dto/profiles.dto.ts index 06eeb24..ce8fa44 100644 --- a/src/services/apis/profiles/dto/profiles.dto.ts +++ b/src/services/apis/profiles/dto/profiles.dto.ts @@ -1,9 +1,9 @@ import { date, z } from 'zod'; import { Types } from 'mongoose'; -import SportsEnum from 'src/constants/sports-enum'; +import Sports from 'src/constants/sports-enum'; export const CreateProfilesValidation = z.object({ - sport: z.nativeEnum(SportsEnum), + sport: z.nativeEnum(Sports), user: z.string().refine((val) => Types.ObjectId.isValid(val), { message: 'Invalid user ID', }), @@ -32,7 +32,7 @@ export const CreateProfilesValidation = z.object({ }); export const PatchProfilesValidation = z.object({ - sport: z.nativeEnum(SportsEnum).optional(), + sport: z.nativeEnum(Sports).optional(), user: z .string() .refine((val) => Types.ObjectId.isValid(val), { diff --git a/src/services/apis/profiles/schemas/profiles.schema.ts b/src/services/apis/profiles/schemas/profiles.schema.ts index 8cdc922..2cd8b3c 100644 --- a/src/services/apis/profiles/schemas/profiles.schema.ts +++ b/src/services/apis/profiles/schemas/profiles.schema.ts @@ -3,7 +3,7 @@ import { HydratedDocument, Types } from 'mongoose'; import { SoftDeleteSchema } from 'src/common/soft-delete-schema'; import EnsureObjectId from 'src/common/EnsureObjectId'; import { Users } from '../../users/schemas/users.schema'; -import SportsEnum, { SportsEnumList } from 'src/constants/sports-enum'; +import Sports, { SportsEnumList } from 'src/constants/sports-enum'; export type ProfilesDocument = HydratedDocument; @@ -16,7 +16,7 @@ export class Profiles extends SoftDeleteSchema { enum: SportsEnumList, required: true, }) - sport: SportsEnum; + sport: Sports; @Prop({ type: Types.ObjectId, diff --git a/src/services/apis/squad/dto/squad.dto.ts b/src/services/apis/squad/dto/squad.dto.ts index c80f3a1..c14ab97 100644 --- a/src/services/apis/squad/dto/squad.dto.ts +++ b/src/services/apis/squad/dto/squad.dto.ts @@ -1,5 +1,8 @@ import { z } from 'zod'; import { Types } from 'mongoose'; +import Sports from 'src/constants/sports-enum'; + +const SportsEnum = z.nativeEnum(Sports); export const CreateSquadValidation = z.object({ branch: z.string().refine((val) => Types.ObjectId.isValid(val), { diff --git a/src/services/apis/squad/schemas/squad.schema.ts b/src/services/apis/squad/schemas/squad.schema.ts index 65c23b2..533f29e 100644 --- a/src/services/apis/squad/schemas/squad.schema.ts +++ b/src/services/apis/squad/schemas/squad.schema.ts @@ -1,26 +1,27 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Types } from 'mongoose'; -export type SquadDocument = HydratedDocument; +export type SquadsDocument = HydratedDocument; @Schema({ timestamps: true, }) -export class Squad { - @Prop({ required: true }) - id: string; - +export class Squads { @Prop({ type: String, required: true }) name: string; - @Prop({ type: String, required: true }) - branch: string; + @Prop({ + type: Types.ObjectId, + required: true, + // ref: Branches.name + }) + branch: Types.ObjectId; @Prop({ type: String }) season: string; - @Prop({ type: String, required: true }) - sport: string; + @Prop({ type: Types.ObjectId, required: true }) + sport: Types.ObjectId; } -export const SquadSchema = SchemaFactory.createForClass(Squad); +export const SquadsSchema = SchemaFactory.createForClass(Squads); diff --git a/src/services/apis/squad/squad.controller.ts b/src/services/apis/squad/squad.controller.ts index 2a4a7fe..8e7bfe5 100644 --- a/src/services/apis/squad/squad.controller.ts +++ b/src/services/apis/squad/squad.controller.ts @@ -11,7 +11,7 @@ import { import { SquadService } from './squad.service'; import { ModifyBody, setCreatedBy } from 'src/decorators/ModifyBody.decorator'; import { User } from '../users/decorator/user.decorator'; -import { Squad } from './schemas/squad.schema'; +import { CreateSquadDto, PatchSquadDto } from './dto/squad.dto'; @Controller('squad') export class SquadController { @@ -28,14 +28,14 @@ export class SquadController { } @Post() - async create(@ModifyBody(setCreatedBy()) createSquadDto: Squad) { + async create(@ModifyBody(setCreatedBy()) createSquadDto: CreateSquadDto) { return await this.squadService._create(createSquadDto); } @Patch('/:id?') async patch( @Query() query, - @Body() patchSquadDto: Partial, + @Body() patchSquadDto: PatchSquadDto, @Param('id') id, ) { return await this.squadService._patch(id, patchSquadDto, query); diff --git a/src/services/apis/squad/squad.module.ts b/src/services/apis/squad/squad.module.ts index c6cab9d..b556f1c 100644 --- a/src/services/apis/squad/squad.module.ts +++ b/src/services/apis/squad/squad.module.ts @@ -2,11 +2,11 @@ import { Module } from '@nestjs/common'; import { MongooseModule } from '@nestjs/mongoose'; import { SquadController } from './squad.controller'; import { SquadService } from './squad.service'; -import { Squad, SquadSchema } from './schemas/squad.schema'; +import { Squads, SquadsSchema } from './schemas/squad.schema'; @Module({ imports: [ - MongooseModule.forFeature([{ name: Squad.name, schema: SquadSchema }]), + MongooseModule.forFeature([{ name: Squads.name, schema: SquadsSchema }]), ], controllers: [SquadController], providers: [SquadService], diff --git a/src/services/apis/squad/squad.service.ts b/src/services/apis/squad/squad.service.ts index 9b8e3bc..9a0240b 100644 --- a/src/services/apis/squad/squad.service.ts +++ b/src/services/apis/squad/squad.service.ts @@ -1,20 +1,20 @@ import { Injectable } from '@nestjs/common'; import { GlobalService } from 'src/common/global-service'; -import { Squad, SquadDocument } from './schemas/squad.schema'; +import { Squads, SquadsDocument } from './schemas/squad.schema'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; @Injectable() -export class SquadService extends GlobalService { +export class SquadService extends GlobalService { constructor( - @InjectModel(Squad.name) - private readonly squadModel: Model, + @InjectModel(Squads.name) + private readonly squadModel: Model, ) { super(squadModel); } // Assign a captain to a squad - async assignCaptain(squadId: string, captainId: string): Promise { + async assignCaptain(squadId: string, captainId: string): Promise { return this.squadModel.findByIdAndUpdate( squadId, { captainId }, diff --git a/src/services/apis/squadPlayer/constants/SquadPlayerEnum.ts b/src/services/apis/squadPlayer/constants/SquadPlayerEnum.ts new file mode 100644 index 0000000..dea1eac --- /dev/null +++ b/src/services/apis/squadPlayer/constants/SquadPlayerEnum.ts @@ -0,0 +1,5 @@ +export enum SquadPlayerStatus { + Approved = 'APPROVED', + Pending = 'PENDING', + Rejected = 'REJECTED', +} diff --git a/src/services/apis/squadPlayer/dto/squadPlayer.dto.ts b/src/services/apis/squadPlayer/dto/squadPlayer.dto.ts index 43bb6d9..eaa5278 100644 --- a/src/services/apis/squadPlayer/dto/squadPlayer.dto.ts +++ b/src/services/apis/squadPlayer/dto/squadPlayer.dto.ts @@ -1,9 +1,10 @@ // squad_player.dto.ts import { z } from 'zod'; import { Types } from 'mongoose'; +import { SquadPlayerStatus } from '../constants/SquadPlayerEnum'; // Enums -const SquadPlayerStatusEnum = z.enum(['approved', 'pending', 'rejected']); +const SquadPlayerStatusEnum = z.nativeEnum(SquadPlayerStatus); export const CreateSquadPlayerValidation = z.object({ squad: z.string().refine((val) => Types.ObjectId.isValid(val), { @@ -12,7 +13,7 @@ export const CreateSquadPlayerValidation = z.object({ user: z.string().refine((val) => Types.ObjectId.isValid(val), { message: 'Invalid user ID', }), - status: SquadPlayerStatusEnum.default('pending'), + status: SquadPlayerStatusEnum.default(SquadPlayerStatus.Pending), createdAt: z.date().optional(), updatedAt: z.date().optional(), }); diff --git a/src/services/apis/squadPlayer/schemas/squadPlayer.schema.ts b/src/services/apis/squadPlayer/schemas/squadPlayer.schema.ts index 04bbd5e..81fbbf5 100644 --- a/src/services/apis/squadPlayer/schemas/squadPlayer.schema.ts +++ b/src/services/apis/squadPlayer/schemas/squadPlayer.schema.ts @@ -1,22 +1,26 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Types } from 'mongoose'; -export type SquadPlayerDocument = HydratedDocument; +import { SquadPlayerStatus } from '../constants/SquadPlayerEnum'; +import { Squads } from '../../squad/schemas/squad.schema'; +import { Users } from '../../users/schemas/users.schema'; + +export type SquadPlayersDocument = HydratedDocument; @Schema({ timestamps: true, }) -export class SquadPlayer { - @Prop({ type: Types.ObjectId, ref: 'Squad', required: true }) +export class SquadPlayers { + @Prop({ type: Types.ObjectId, ref: Squads.name, required: true }) squad: Types.ObjectId; - @Prop({ type: Types.ObjectId, ref: 'User', required: true }) + @Prop({ type: Types.ObjectId, ref: Users.name, required: true }) user: Types.ObjectId; @Prop({ type: String, - enum: ['approved', 'pending', 'rejected'], - default: 'pending', + enum: Object.values(SquadPlayerStatus), + default: SquadPlayerStatus.Pending, }) - status: string; + status: SquadPlayerStatus; } -export const SquadPlayerSchema = SchemaFactory.createForClass(SquadPlayer); +export const SquadPlayersSchema = SchemaFactory.createForClass(SquadPlayers); diff --git a/src/services/apis/team/schemas/team.schema.ts b/src/services/apis/team/schemas/team.schema.ts index ec674b2..1381245 100644 --- a/src/services/apis/team/schemas/team.schema.ts +++ b/src/services/apis/team/schemas/team.schema.ts @@ -1,27 +1,32 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Types } from 'mongoose'; +import { Squads } from '../../squad/schemas/squad.schema'; +import { Matches } from '../../matches/schemas/matches.schema'; +import { Users } from '../../users/schemas/users.schema'; +export type TeamsDocument = HydratedDocument; @Schema({ timestamps: true, }) -export class Team { - @Prop({ required: true }) - id: string; - - @Prop({ type: Types.ObjectId, ref: 'Squad', required: true }) +export class Teams { + @Prop({ type: Types.ObjectId, ref: Squads.name, required: true }) squad: Types.ObjectId; - @Prop({ type: Types.ObjectId, ref: 'Match', required: true }) + @Prop({ type: Types.ObjectId, ref: Matches.name, required: true }) match: Types.ObjectId; - @Prop({ type: Types.ObjectId, ref: 'User', required: true }) + @Prop({ type: Types.ObjectId, ref: Users.name, required: true }) captain: Types.ObjectId; - @Prop({ type: Types.ObjectId, ref: 'User' }) + @Prop({ type: Types.ObjectId, ref: Users.name }) viceCaptain: Types.ObjectId; - @Prop({ type: String, required: true }) - sport: string; + @Prop({ + type: String, + required: true, + // ref: Sports.name + }) + sport: Types.ObjectId; } -export const TeamSchema = SchemaFactory.createForClass(Team); +export const TeamsSchema = SchemaFactory.createForClass(Teams); diff --git a/src/services/apis/teamPlayer/constants/TeamPlayerEnum.ts b/src/services/apis/teamPlayer/constants/TeamPlayerEnum.ts new file mode 100644 index 0000000..906aec7 --- /dev/null +++ b/src/services/apis/teamPlayer/constants/TeamPlayerEnum.ts @@ -0,0 +1,6 @@ +export enum TeamPlayerStatus { + Playing = 'PLAYING', + Retired = 'RETIRED', + Banned = 'BANNED', + Substituted = 'SUBSTITUTED', +} diff --git a/src/services/apis/teamPlayer/dto/teamPlayer.dto.ts b/src/services/apis/teamPlayer/dto/teamPlayer.dto.ts index 26b1c17..59d7950 100644 --- a/src/services/apis/teamPlayer/dto/teamPlayer.dto.ts +++ b/src/services/apis/teamPlayer/dto/teamPlayer.dto.ts @@ -1,14 +1,10 @@ // team_player.dto.ts import { z } from 'zod'; import { Types } from 'mongoose'; +import { TeamPlayerStatus } from '../constants/TeamPlayerEnum'; // Enums -const TeamPlayerStatusEnum = z.enum([ - 'playing', - 'retired', - 'banned', - 'substituted', -]); +const TeamPlayerStatusEnum = z.nativeEnum(TeamPlayerStatus); export const CreateTeamPlayerValidation = z.object({ team: z.string().refine((val) => Types.ObjectId.isValid(val), { @@ -17,7 +13,7 @@ export const CreateTeamPlayerValidation = z.object({ user: z.string().refine((val) => Types.ObjectId.isValid(val), { message: 'Invalid user ID', }), - status: TeamPlayerStatusEnum.default('playing'), + status: TeamPlayerStatusEnum.default(TeamPlayerStatus.Playing), createdAt: z.date().optional(), updatedAt: z.date().optional(), }); diff --git a/src/services/apis/teamPlayer/schemas/teamPlayer.schema.ts b/src/services/apis/teamPlayer/schemas/teamPlayer.schema.ts index 43c6cbb..a65b126 100644 --- a/src/services/apis/teamPlayer/schemas/teamPlayer.schema.ts +++ b/src/services/apis/teamPlayer/schemas/teamPlayer.schema.ts @@ -1,12 +1,13 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Types } from 'mongoose'; +import { TeamPlayerStatus } from '../constants/TeamPlayerEnum'; -export type TeamPlayerDocument = HydratedDocument; +export type TeamPlayersDocument = HydratedDocument; @Schema({ timestamps: true, }) -export class TeamPlayer { +export class TeamPlayers { @Prop({ type: Types.ObjectId, ref: 'Team', required: true }) team: Types.ObjectId; @@ -15,10 +16,10 @@ export class TeamPlayer { @Prop({ type: String, - enum: ['playing', 'retired', 'banned', 'substituted'], - default: 'playing', + enum: Object.values(TeamPlayerStatus), + default: TeamPlayerStatus.Playing, }) - status: string; + status: TeamPlayerStatus; } -export const TeamPlayerSchema = SchemaFactory.createForClass(TeamPlayer); +export const TeamPlayersSchema = SchemaFactory.createForClass(TeamPlayers); From 70e798cecc89c762f6339f7a671f0a59928eb7ff Mon Sep 17 00:00:00 2001 From: majorbruteforce Date: Wed, 25 Dec 2024 13:26:10 +0530 Subject: [PATCH 4/4] Change names --- src/services/apis/matches/matches.module.ts | 1 - src/services/apis/squad/squad.controller.ts | 5 +++-- .../apis/squadPlayer/squadPlayer.controller.ts | 6 +++--- src/services/apis/squadPlayer/squadPlayer.module.ts | 4 ++-- .../apis/squadPlayer/squadPlayer.service.ts | 13 ++++++++----- src/services/apis/team/dto/team.dto.ts | 9 --------- src/services/apis/team/schemas/team.schema.ts | 4 ---- src/services/apis/team/team.controller.ts | 6 +++--- src/services/apis/team/team.module.ts | 4 ++-- src/services/apis/team/team.service.ts | 8 ++++---- .../apis/teamPlayer/teamPlayer.controller.ts | 6 +++--- src/services/apis/teamPlayer/teamPlayer.module.ts | 4 ++-- src/services/apis/teamPlayer/teamPlayer.service.ts | 10 +++++----- 13 files changed, 35 insertions(+), 45 deletions(-) diff --git a/src/services/apis/matches/matches.module.ts b/src/services/apis/matches/matches.module.ts index 8922874..06be64e 100644 --- a/src/services/apis/matches/matches.module.ts +++ b/src/services/apis/matches/matches.module.ts @@ -3,7 +3,6 @@ import { MongooseModule } from '@nestjs/mongoose'; import { MatchesController } from './matches.controller'; import { MatchesService } from './matches.service'; import { Matches, MatchesSchema } from './schemas/matches.schema'; - @Module({ imports: [ MongooseModule.forFeature([{ name: Matches.name, schema: MatchesSchema }]), diff --git a/src/services/apis/squad/squad.controller.ts b/src/services/apis/squad/squad.controller.ts index 8e7bfe5..3dd9745 100644 --- a/src/services/apis/squad/squad.controller.ts +++ b/src/services/apis/squad/squad.controller.ts @@ -12,6 +12,7 @@ import { SquadService } from './squad.service'; import { ModifyBody, setCreatedBy } from 'src/decorators/ModifyBody.decorator'; import { User } from '../users/decorator/user.decorator'; import { CreateSquadDto, PatchSquadDto } from './dto/squad.dto'; +import { Squads } from './schemas/squad.schema'; @Controller('squad') export class SquadController { @@ -28,14 +29,14 @@ export class SquadController { } @Post() - async create(@ModifyBody(setCreatedBy()) createSquadDto: CreateSquadDto) { + async create(@ModifyBody(setCreatedBy()) createSquadDto: Squads) { return await this.squadService._create(createSquadDto); } @Patch('/:id?') async patch( @Query() query, - @Body() patchSquadDto: PatchSquadDto, + @Body() patchSquadDto: Partial, @Param('id') id, ) { return await this.squadService._patch(id, patchSquadDto, query); diff --git a/src/services/apis/squadPlayer/squadPlayer.controller.ts b/src/services/apis/squadPlayer/squadPlayer.controller.ts index 5ef38ab..e2b3272 100644 --- a/src/services/apis/squadPlayer/squadPlayer.controller.ts +++ b/src/services/apis/squadPlayer/squadPlayer.controller.ts @@ -11,7 +11,7 @@ import { import { SquadPlayerService } from './squadPlayer.service'; import { ModifyBody, setCreatedBy } from 'src/decorators/ModifyBody.decorator'; import { User } from '../users/decorator/user.decorator'; -import { SquadPlayer } from './schemas/squadPlayer.schema'; +import { SquadPlayers } from './schemas/squadPlayer.schema'; @Controller('squad-player') export class SquadPlayerController { @@ -28,14 +28,14 @@ export class SquadPlayerController { } @Post() - async create(@ModifyBody(setCreatedBy()) createSquadPlayerDto: SquadPlayer) { + async create(@ModifyBody(setCreatedBy()) createSquadPlayerDto: SquadPlayers) { return await this.squadPlayerService._create(createSquadPlayerDto); } @Patch('/:id?') async patch( @Query() query, - @Body() patchSquadPlayerDto: Partial, + @Body() patchSquadPlayerDto: Partial, @Param('id') id, ) { return await this.squadPlayerService._patch(id, patchSquadPlayerDto, query); diff --git a/src/services/apis/squadPlayer/squadPlayer.module.ts b/src/services/apis/squadPlayer/squadPlayer.module.ts index de4e0ae..80daa29 100644 --- a/src/services/apis/squadPlayer/squadPlayer.module.ts +++ b/src/services/apis/squadPlayer/squadPlayer.module.ts @@ -2,12 +2,12 @@ import { Module } from '@nestjs/common'; import { MongooseModule } from '@nestjs/mongoose'; import { SquadPlayerController } from './squadPlayer.controller'; import { SquadPlayerService } from './squadPlayer.service'; -import { SquadPlayer, SquadPlayerSchema } from './schemas/squadPlayer.schema'; +import { SquadPlayers, SquadPlayersSchema } from './schemas/squadPlayer.schema'; @Module({ imports: [ MongooseModule.forFeature([ - { name: SquadPlayer.name, schema: SquadPlayerSchema }, + { name: SquadPlayers.name, schema: SquadPlayersSchema }, ]), ], controllers: [SquadPlayerController], diff --git a/src/services/apis/squadPlayer/squadPlayer.service.ts b/src/services/apis/squadPlayer/squadPlayer.service.ts index 29e171b..b145e90 100644 --- a/src/services/apis/squadPlayer/squadPlayer.service.ts +++ b/src/services/apis/squadPlayer/squadPlayer.service.ts @@ -1,17 +1,20 @@ import { Injectable } from '@nestjs/common'; import { GlobalService } from 'src/common/global-service'; -import { SquadPlayer, SquadPlayerDocument } from './schemas/squadPlayer.schema'; +import { + SquadPlayers, + SquadPlayersDocument, +} from './schemas/squadPlayer.schema'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; @Injectable() export class SquadPlayerService extends GlobalService< - SquadPlayer, - SquadPlayerDocument + SquadPlayers, + SquadPlayersDocument > { constructor( - @InjectModel(SquadPlayer.name) - private readonly squadPlayerModel: Model, + @InjectModel(SquadPlayers.name) + private readonly squadPlayerModel: Model, ) { super(squadPlayerModel); } diff --git a/src/services/apis/team/dto/team.dto.ts b/src/services/apis/team/dto/team.dto.ts index aa1e23c..893139a 100644 --- a/src/services/apis/team/dto/team.dto.ts +++ b/src/services/apis/team/dto/team.dto.ts @@ -3,9 +3,6 @@ import { Types } from 'mongoose'; // Rename from Teams to Team for consistency export const CreateTeamValidation = z.object({ - match: z.string().refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid match ID', - }), captain: z.string().refine((val) => Types.ObjectId.isValid(val), { message: 'Invalid captain ID', }), @@ -23,12 +20,6 @@ export const CreateTeamValidation = z.object({ }); export const PatchTeamValidation = z.object({ - match: z - .string() - .refine((val) => Types.ObjectId.isValid(val), { - message: 'Invalid match ID', - }) - .optional(), captain: z .string() .refine((val) => Types.ObjectId.isValid(val), { diff --git a/src/services/apis/team/schemas/team.schema.ts b/src/services/apis/team/schemas/team.schema.ts index 1381245..b9fd5cd 100644 --- a/src/services/apis/team/schemas/team.schema.ts +++ b/src/services/apis/team/schemas/team.schema.ts @@ -1,7 +1,6 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { HydratedDocument, Types } from 'mongoose'; import { Squads } from '../../squad/schemas/squad.schema'; -import { Matches } from '../../matches/schemas/matches.schema'; import { Users } from '../../users/schemas/users.schema'; export type TeamsDocument = HydratedDocument; @@ -12,9 +11,6 @@ export class Teams { @Prop({ type: Types.ObjectId, ref: Squads.name, required: true }) squad: Types.ObjectId; - @Prop({ type: Types.ObjectId, ref: Matches.name, required: true }) - match: Types.ObjectId; - @Prop({ type: Types.ObjectId, ref: Users.name, required: true }) captain: Types.ObjectId; diff --git a/src/services/apis/team/team.controller.ts b/src/services/apis/team/team.controller.ts index 85fc473..797c6b5 100644 --- a/src/services/apis/team/team.controller.ts +++ b/src/services/apis/team/team.controller.ts @@ -11,7 +11,7 @@ import { import { TeamService } from './team.service'; import { ModifyBody, setCreatedBy } from 'src/decorators/ModifyBody.decorator'; import { User } from '../users/decorator/user.decorator'; -import { Team } from './schemas/team.schema'; +import { Teams } from './schemas/team.schema'; @Controller('team') export class TeamController { @@ -28,14 +28,14 @@ export class TeamController { } @Post() - async create(@ModifyBody(setCreatedBy()) createTeamDto: Team) { + async create(@ModifyBody(setCreatedBy()) createTeamDto: Teams) { return await this.teamService._create(createTeamDto); } @Patch('/:id?') async patch( @Query() query, - @Body() patchTeamDto: Partial, + @Body() patchTeamDto: Partial, @Param('id') id, ) { return await this.teamService._patch(id, patchTeamDto, query); diff --git a/src/services/apis/team/team.module.ts b/src/services/apis/team/team.module.ts index 1736851..d298fdf 100644 --- a/src/services/apis/team/team.module.ts +++ b/src/services/apis/team/team.module.ts @@ -2,11 +2,11 @@ import { Module } from '@nestjs/common'; import { MongooseModule } from '@nestjs/mongoose'; import { TeamController } from './team.controller'; import { TeamService } from './team.service'; -import { Team, TeamSchema } from './schemas/team.schema'; +import { Teams, TeamsSchema } from './schemas/team.schema'; @Module({ imports: [ - MongooseModule.forFeature([{ name: Team.name, schema: TeamSchema }]), + MongooseModule.forFeature([{ name: Teams.name, schema: TeamsSchema }]), ], controllers: [TeamController], providers: [TeamService], diff --git a/src/services/apis/team/team.service.ts b/src/services/apis/team/team.service.ts index 4be126a..370f0cf 100644 --- a/src/services/apis/team/team.service.ts +++ b/src/services/apis/team/team.service.ts @@ -1,14 +1,14 @@ import { Injectable } from '@nestjs/common'; import { GlobalService } from 'src/common/global-service'; -import { Team, TeamDocument } from './schemas/team.schema'; +import { Teams, TeamsDocument } from './schemas/team.schema'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; @Injectable() -export class TeamService extends GlobalService { +export class TeamService extends GlobalService { constructor( - @InjectModel(Team.name) - private readonly teamModel: Model, + @InjectModel(Teams.name) + private readonly teamModel: Model, ) { super(teamModel); } diff --git a/src/services/apis/teamPlayer/teamPlayer.controller.ts b/src/services/apis/teamPlayer/teamPlayer.controller.ts index edfe9fe..b91436e 100644 --- a/src/services/apis/teamPlayer/teamPlayer.controller.ts +++ b/src/services/apis/teamPlayer/teamPlayer.controller.ts @@ -11,7 +11,7 @@ import { import { TeamPlayerService } from './teamPlayer.service'; import { ModifyBody, setCreatedBy } from 'src/decorators/ModifyBody.decorator'; import { User } from '../users/decorator/user.decorator'; -import { TeamPlayer } from './schemas/teamPlayer.schema'; +import { TeamPlayers } from './schemas/teamPlayer.schema'; @Controller('team-player') export class TeamPlayerController { @@ -28,14 +28,14 @@ export class TeamPlayerController { } @Post() - async create(@ModifyBody(setCreatedBy()) createTeamPlayerDto: TeamPlayer) { + async create(@ModifyBody(setCreatedBy()) createTeamPlayerDto: TeamPlayers) { return await this.teamPlayerService._create(createTeamPlayerDto); } @Patch('/:id?') async patch( @Query() query, - @Body() patchTeamPlayerDto: Partial, + @Body() patchTeamPlayerDto: Partial, @Param('id') id, ) { return await this.teamPlayerService._patch(id, patchTeamPlayerDto, query); diff --git a/src/services/apis/teamPlayer/teamPlayer.module.ts b/src/services/apis/teamPlayer/teamPlayer.module.ts index 1431d9c..c4ec36f 100644 --- a/src/services/apis/teamPlayer/teamPlayer.module.ts +++ b/src/services/apis/teamPlayer/teamPlayer.module.ts @@ -2,12 +2,12 @@ import { Module } from '@nestjs/common'; import { MongooseModule } from '@nestjs/mongoose'; import { TeamPlayerController } from './teamPlayer.controller'; import { TeamPlayerService } from './teamPlayer.service'; -import { TeamPlayer, TeamPlayerSchema } from './schemas/teamPlayer.schema'; +import { TeamPlayers, TeamPlayersSchema } from './schemas/teamPlayer.schema'; @Module({ imports: [ MongooseModule.forFeature([ - { name: TeamPlayer.name, schema: TeamPlayerSchema }, + { name: TeamPlayers.name, schema: TeamPlayersSchema }, ]), ], controllers: [TeamPlayerController], diff --git a/src/services/apis/teamPlayer/teamPlayer.service.ts b/src/services/apis/teamPlayer/teamPlayer.service.ts index cf11236..b9a3b5e 100644 --- a/src/services/apis/teamPlayer/teamPlayer.service.ts +++ b/src/services/apis/teamPlayer/teamPlayer.service.ts @@ -1,17 +1,17 @@ import { Injectable } from '@nestjs/common'; import { GlobalService } from 'src/common/global-service'; -import { TeamPlayer, TeamPlayerDocument } from './schemas/teamPlayer.schema'; +import { TeamPlayers, TeamPlayersDocument } from './schemas/teamPlayer.schema'; import { InjectModel } from '@nestjs/mongoose'; import { Model } from 'mongoose'; @Injectable() export class TeamPlayerService extends GlobalService< - TeamPlayer, - TeamPlayerDocument + TeamPlayers, + TeamPlayersDocument > { constructor( - @InjectModel(TeamPlayer.name) - private readonly teamPlayerModel: Model, + @InjectModel(TeamPlayers.name) + private readonly teamPlayerModel: Model, ) { super(teamPlayerModel); }