-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create PhaseHistory entity and rework on the UI for phase managers
- Loading branch information
Showing
10 changed files
with
191 additions
and
59 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,47 @@ | ||
import { PhaseHistory } from '../entities/phaseHistory'; | ||
import { Village } from '../entities/village'; | ||
import { AppDataSource } from '../utils/data-source'; | ||
import { Controller } from './controller'; | ||
|
||
export const phaseHistoryController = new Controller('/phase-history'); | ||
|
||
phaseHistoryController.post({ path: '/' }, async (_req, res) => { | ||
const data = _req.body; | ||
try { | ||
//Find village wit ha given id | ||
const villageRepository = AppDataSource.getRepository(Village); | ||
const village = await villageRepository.findOne({ where: { id: data.villageId } }); | ||
if (!village) throw new Error('Village Not found'); | ||
|
||
// Create a PhaseHistory instance and fill it with data | ||
const phaseHistory = new PhaseHistory(); | ||
phaseHistory.village = village; | ||
phaseHistory.phase = data.phase; | ||
|
||
// Save phase history in db | ||
const phaseHistoryRepository = AppDataSource.getRepository(PhaseHistory); | ||
await phaseHistoryRepository.save(phaseHistory); | ||
res.sendStatus(200); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}); | ||
|
||
phaseHistoryController.delete({ path: '/soft-delete/:villageId/:phase' }, async (_req, res) => { | ||
const { villageId, phase } = _req.params; | ||
const phaseHistoryRepository = AppDataSource.getRepository(PhaseHistory); | ||
console.log('SOFT DELETE'); | ||
console.log(villageId, phase); | ||
const query = phaseHistoryRepository | ||
.createQueryBuilder() | ||
.softDelete() | ||
.where('villageId = :villageId', { villageId }) | ||
.andWhere('phase = :phase', { phase }); | ||
|
||
try { | ||
await query.execute(); | ||
res.sendStatus(202); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
}); |
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,25 @@ | ||
import { Column, CreateDateColumn, DeleteDateColumn, Entity, Index, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; | ||
|
||
import type { VillagePhase } from './village'; | ||
import { Village } from './village'; | ||
|
||
@Entity() | ||
@Index(['village', 'phase'], { unique: true }) | ||
export class PhaseHistory { | ||
@PrimaryGeneratedColumn() | ||
public id: number; | ||
|
||
@ManyToOne(() => Village, (village) => village.phaseHistories) | ||
village: Village; | ||
|
||
@Column({ | ||
type: 'tinyint', | ||
}) | ||
phase: VillagePhase; | ||
|
||
@CreateDateColumn() | ||
public startingOn: Date; | ||
|
||
@DeleteDateColumn() | ||
public endingOn: Date; | ||
} |
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
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 type { PhaseHistory } from 'server/entities/phaseHistory'; | ||
|
||
import { axiosRequest } from 'src/utils/axiosRequest'; | ||
|
||
export async function softDeletePhaseHistory(villageId: number, phase: number): Promise<PhaseHistory> { | ||
const response = await axiosRequest<PhaseHistory>({ | ||
method: 'DELETE', | ||
url: `/phase-history/soft-delete/${villageId}/${phase}`, | ||
}); | ||
if (response.error) { | ||
throw new Error("Erreur lors de la suppresion de l'historique des phases. Veuillez réessayer."); | ||
} | ||
// inviladate le cache de la liste des jeux | ||
return response.data; | ||
} |
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,16 @@ | ||
import type { PhaseHistory } from 'server/entities/phaseHistory'; | ||
|
||
import { axiosRequest } from 'src/utils/axiosRequest'; | ||
|
||
export async function postPhaseHistory(data: Partial<PhaseHistory> & { villageId: number }): Promise<PhaseHistory> { | ||
const response = await axiosRequest<PhaseHistory>({ | ||
method: 'POST', | ||
url: '/phase-history', | ||
data, | ||
}); | ||
if (response.error) { | ||
throw new Error("Erreur lors de la création de l'historique des phases. Veuillez réessayer."); | ||
} | ||
// inviladate le cache de la liste des jeux | ||
return response.data; | ||
} |
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
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