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

add createHistory helper function

parent ea344780
No related branches found
No related tags found
3 merge requests!59Development to master,!58Development to testing,!55Flagbox replay
...@@ -30,13 +30,7 @@ export class DrawService { ...@@ -30,13 +30,7 @@ export class DrawService {
drawing.faction = gameperson.faction; drawing.faction = gameperson.faction;
const mapDrawing = await this.mapDrawingRepository.insert(drawing); const mapDrawing = await this.mapDrawingRepository.insert(drawing);
// create a history entity and insert it // create a history entity and insert it
const history = await this.mapDrawHistoryRepository.create({ await this.createHistory(data, gameperson, mapDrawing);
data: data.data,
drawingIsActive: data.drawingIsActive,
mapdrawing: mapDrawing.identifiers[0]['mapDrawingId'],
timestamp: Date.now(),
});
await this.mapDrawHistoryRepository.insert(history);
return mapDrawing.identifiers; return mapDrawing.identifiers;
} }
// get ref from db // get ref from db
...@@ -46,13 +40,7 @@ export class DrawService { ...@@ -46,13 +40,7 @@ export class DrawService {
}); });
if (await draw.ownershipCheck(gameperson.faction, gameperson.role)) { if (await draw.ownershipCheck(gameperson.faction, gameperson.role)) {
// else update the existing instance // else update the existing instance
const history = await this.mapDrawHistoryRepository.create({ await this.createHistory(data, gameperson);
data: data.data,
drawingIsActive: data.drawingIsActive,
mapdrawing: data.mapDrawingId,
timestamp: Date.now(),
});
await this.mapDrawHistoryRepository.insert(history);
return await this.mapDrawingRepository.save(drawing); return await this.mapDrawingRepository.save(drawing);
} }
...@@ -62,6 +50,22 @@ export class DrawService { ...@@ -62,6 +50,22 @@ export class DrawService {
); );
} }
// used to create mapDrawing history entity entry
private async createHistory(data, gameperson, mapDrawing?) {
// create a history entity and insert it
const history = await this.mapDrawHistoryRepository.create({
data: data.data,
drawingIsActive: data.drawingIsActive,
mapdrawing:
data.mapDrawingId || mapDrawing.identifiers[0]['mapDrawingId'],
timestamp: Date.now(),
});
history.data['faction'] = gameperson.faction
? gameperson.faction.factionName
: 'admin';
await this.mapDrawHistoryRepository.insert(history);
}
// draw map based on game and gameperson faction // draw map based on game and gameperson faction
async drawMap(gameperson, gameId) { async drawMap(gameperson, gameId) {
// return all active drawings if admin // return all active drawings if admin
......
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