Fixed some behaviour in Elo calculation. Began implement match logic.
This commit is contained in:
43
src/endpoints/matches.ts
Normal file
43
src/endpoints/matches.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { orm } from '../orm/orm';
|
||||
import { UnwrappedRequest } from '../utilities/guard';
|
||||
import { CreatedResponse, ErrorResponse, OkResponse } from '../utilities/responseHelper';
|
||||
import { CreateMatchRequest } from '../utilities/requestModels';
|
||||
import { GameId, MatchId, PlayerId, UserId } from '../utilities/secureIds';
|
||||
import { MatchParticipant } from '../orm/matches';
|
||||
|
||||
async function create(request: UnwrappedRequest<CreateMatchRequest>): Promise<Response> {
|
||||
try {
|
||||
const newUser = await orm.matches.create({
|
||||
gameId: GameId.fromHash(request.body.gameId),
|
||||
ownerId: request.claims.userId as UserId,
|
||||
participants: request.body.participants.map(
|
||||
(x) => new MatchParticipant(PlayerId.fromHash(x.playerId), x.standing),
|
||||
),
|
||||
});
|
||||
return new CreatedResponse(newUser);
|
||||
} catch (error: any) {
|
||||
return new ErrorResponse(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
async function get(request: UnwrappedRequest): Promise<Response> {
|
||||
try {
|
||||
return new OkResponse(await orm.matches.get(MatchId.fromHash(request.params.id), request.claims));
|
||||
} catch (error: any) {
|
||||
return new ErrorResponse(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
async function drop(request: UnwrappedRequest): Promise<Response> {
|
||||
try {
|
||||
return new OkResponse(await orm.matches.drop(UserId.fromHash(request.params.id), request.claims));
|
||||
} catch (error: any) {
|
||||
return new ErrorResponse(error as Error);
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
create,
|
||||
get,
|
||||
drop,
|
||||
};
|
||||
Reference in New Issue
Block a user