Skip to content
Snippets Groups Projects
Commit 02eeccde authored by Ronnie Friman's avatar Ronnie Friman
Browse files

service returns flagbox-events

parent bbcce13a
No related branches found
No related tags found
3 merge requests!59Development to master,!58Development to testing,!55Flagbox replay
......@@ -83,6 +83,14 @@ export class GameService {
HttpStatus.BAD_REQUEST,
);
}
// check that there's location data for each added objective point
gameData.objective_points.forEach(obj => {
if (!obj['data'])
throw new HttpException(
'Objective Point error. Add location for each Objective Point.',
HttpStatus.BAD_REQUEST,
);
});
// get factions that have been added previously
let factions = await this.factionRepository.find({ game: id });
......@@ -121,8 +129,10 @@ export class GameService {
({ objectivePointId }) => objectivePointId,
);
flagboxes.map(async flagbox => {
if (!flagboxIds.includes(flagbox.objectivePointDescription)) {
await this.objectivePointRepository.delete(flagbox);
if (!flagboxIds.includes(flagbox.objectivePointId)) {
await this.objectivePointRepository.delete({
objectivePointId: flagbox.objectivePointId,
});
}
});
gameData.objective_points.map(async flagbox => {
......@@ -136,8 +146,6 @@ export class GameService {
await this.objectivePointRepository.delete({ game: id });
}
// TO DO: ADD FLAGBOX LOCATION TO MAPDRAWING ENTITY
return {
message: 'Game updated',
};
......@@ -209,7 +217,7 @@ export class GameService {
}
// returns information about a game identified by id
async returnGameInfo(id: string) {
async returnGameInfo(id) {
const game = await this.gameRepository.findOne({
where: { id: id },
relations: ['factions', 'objective_points'],
......@@ -221,6 +229,52 @@ export class GameService {
return game;
}
// returns information about game's flagboxes and their most recent event
async returnObjectivePointInfo(gameId) {
const info = await this.objectivePointRepository.find({
where: { game: gameId },
relations: ['history', 'history.owner', 'history.capture'],
});
let response = await Promise.all(
info.map(async obj => {
let history = obj.history.pop();
return await {
objectivePointId: obj.objectivePointId,
objectivePointDescription: obj.objectivePointDescription,
objectivePointMultiplier: obj.objectivePointMultiplier,
action: {
status: history.action,
message: {
0: 'No capture ongoing',
1: `Captured by ${
history.owner ? history.owner.factionName : 'neutral'
}`,
2: `Being captured by ${
history.capture ? history.capture.factionName : 'neutral'
}`,
}[history.action],
},
owner: await this.infoHelper(history.owner),
capture: await this.infoHelper(history.capture),
data: obj.data,
};
}),
);
return response;
}
private async infoHelper(obj) {
return (await obj)
? {
factionName: obj.factionName,
colour: obj.colour,
}
: {
factionName: 'neutral',
colour: '#000000',
};
}
// returns flagbox settings
async flagboxQuery(gameId) {
const game = await this.gameRepository.findOne({ id: gameId });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment