-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from p-society/crudapi
review
- Loading branch information
Showing
43 changed files
with
1,140 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export enum Branches { | ||
Cse = 'CSE', | ||
Etc = 'ETC', | ||
Eee = 'EEE', | ||
It = 'IT', | ||
Ce = 'CE', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { z } from 'zod'; | ||
import { Types } from 'mongoose'; | ||
import { | ||
MatchIncompletionReason, | ||
MatchOutcome, | ||
MatchStage, | ||
MatchStatus, | ||
} from '../constants/MatchEnums'; | ||
|
||
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(), | ||
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().refine((val) => Types.ObjectId.isValid(val), { | ||
message: 'Invalid sport ID', | ||
}), | ||
stage: StageEnum, | ||
status: StatusEnum, | ||
outcome: OutcomeEnum.optional(), | ||
reasonForIncompletion: IncompletionReasonEnum.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({ | ||
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() | ||
.refine((val) => Types.ObjectId.isValid(val), { | ||
message: 'Invalid sport ID', | ||
}) | ||
.optional(), | ||
stage: StageEnum.optional(), | ||
status: StatusEnum.optional(), | ||
outcome: OutcomeEnum.optional(), | ||
reasonForIncompletion: IncompletionReasonEnum.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 matches ID', | ||
}), | ||
deletedBy: z | ||
.string() | ||
.refine((val) => Types.ObjectId.isValid(val), { | ||
message: 'Invalid deleter ID', | ||
}) | ||
.optional(), | ||
deletedAt: z.date().optional(), | ||
}); | ||
|
||
export type CreateMatchesDto = z.infer<typeof CreateMatchesValidation>; | ||
export type PatchMatchesDto = z.infer<typeof PatchMatchesValidation>; | ||
export type RemoveMatchesDto = z.infer<typeof RemoveMatchesValidation>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>(MatchesController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string, any>) { | ||
return await this.matchesService._find(query); | ||
} | ||
|
||
@Get('/:id?') | ||
async get(@Query() query: Record<string, any>, @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<Matches>, | ||
@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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>(MatchesService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Matches, MatchesDocument> { | ||
constructor( | ||
@InjectModel(Matches.name) | ||
private readonly matchesModel: Model<MatchesDocument>, | ||
) { | ||
super(matchesModel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
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<Matches>; | ||
|
||
@Schema({ | ||
timestamps: true, | ||
}) | ||
export class Matches { | ||
@Prop({ type: Date, required: true }) | ||
scheduledFor: Date; | ||
|
||
@Prop({ type: Date }) | ||
concludedAt: Date; | ||
|
||
@Prop({ | ||
type: Types.ObjectId, | ||
ref: Teams.name, | ||
required: true, | ||
}) | ||
team1: Types.ObjectId; | ||
|
||
@Prop({ | ||
type: Types.ObjectId, | ||
ref: Teams.name, | ||
required: true, | ||
}) | ||
team2: Types.ObjectId; | ||
|
||
@Prop({ | ||
type: Types.ObjectId, | ||
// ref: Sports.name // Include when sports entity is defined | ||
required: true, | ||
}) | ||
sport: Types.ObjectId; | ||
|
||
@Prop({ | ||
type: String, | ||
enum: Object.values(MatchStage), | ||
required: true, | ||
}) | ||
stage: MatchStage; | ||
|
||
@Prop({ | ||
type: String, | ||
enum: Object.values(MatchStatus), | ||
default: MatchStatus.Upcoming, | ||
}) | ||
status: MatchStatus; | ||
|
||
@Prop({ | ||
type: String, | ||
enum: Object.values(MatchOutcome), | ||
}) | ||
outcome: MatchOutcome; | ||
|
||
@Prop({ | ||
type: String, | ||
enum: Object.values(MatchIncompletionReason), | ||
}) | ||
reasonForIncompletion: MatchIncompletionReason; | ||
} | ||
|
||
export const MatchesSchema = SchemaFactory.createForClass(Matches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.