Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
ikit committed Feb 13, 2022
1 parent 00ff028 commit eacd4de
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 59 deletions.
8 changes: 0 additions & 8 deletions absg-core/src/controllers/AgendaController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,6 @@ export class AgendaController {
return agendaService.savePlace(body, image, session);
}

/**
* Récupère la liste complète des photos du trombinoscope
*/
@Get("/trombi")
async listTrombi() {
return await agendaService.listTrombi();
}

/**
* Crée ou modifie (si l'id et la date sotn les mêmes) une photo du trombinoscope
* @param image l'image uploadé si défini
Expand Down
51 changes: 0 additions & 51 deletions absg-core/src/services/AgendaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,57 +120,6 @@ class AgendaService {
};
}

/**
* Récupère la liste complète des photos du trombinoscope
*/
async listTrombi() {
// On récupère la liste des personnes du répertoire
const personsData = await this.personsRepo
.createQueryBuilder("p")
.orderBy("p.lastname")
.addOrderBy("p.firstname")
.getMany();


const persons = {};
for (const p of personsData) {
// On ignore les personnes qui n'ont pas de date de naissance (Zaffa par exemple)
if (!!p.dateOfBirth) {
persons[p.id] = p;
persons[p.id].trombis = [];
const maxDate = persons[p.id].dateOfDeath ? new Date(persons[p.id].dateOfDeath) : new Date();
persons[p.id].max = maxDate.getFullYear() - new Date(persons[p.id].dateOfBirth).getFullYear();
}
}

const folderPath = path.join(process.env.PATH_FILES, "trombi");
const files = await fs.readdirSync(folderPath);
files.forEach(file => {
if (fs.statSync(path.join(folderPath, file)).isFile() && file.endsWith("jpg")) {
const tokens = file.substring(0, file.length - 4).split("_");
if (tokens.length === 2 && persons.hasOwnProperty(tokens[0])) {
const pid = tokens[0];
const year = Number.parseInt(tokens[1]);
const p = persons[pid];
p.trombis.push({
date: year,
title: `${p.getFullname()} - ${year} - ${p.getAge(year)}`,
thumb: `${process.env.URL_FILES}trombi/mini/${file}`,
url: `${process.env.URL_FILES}trombi/${file}`
})
}
}
});

await this.personsRepo.save(personsData);
// On retourne la liste
return Object.keys(persons).map(e => persons[e]).sort((a, b) => {
const fn = a.firstname.localeCompare(b.firstname);
const ln = a.lastname.localeCompare(b.lastname);
return ln !== 0 ? ln : fn;
});
}

async saveTrombi(trombiData: any, image: any, user: User) {
if (image && trombiData && trombiData.person && trombiData.date) {
const p = await this.personsRepo.findOne(trombiData.person.id);
Expand Down

0 comments on commit eacd4de

Please sign in to comment.