48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
|
import * as CSV from 'std:csv';
|
||
|
import { Redmine } from 'bluemine';
|
||
|
|
||
|
const endpoint = 'https://projets.cohabit.fr/redmine';
|
||
|
const apiKey = '';
|
||
|
const redmine = new Redmine({ endpoint, apiKey });
|
||
|
|
||
|
type CsvEntry = {
|
||
|
firstname: string;
|
||
|
lastname: string;
|
||
|
mail: string;
|
||
|
};
|
||
|
|
||
|
const file = await Deno.readTextFile(
|
||
|
'C:/Users/Julien/Documents/Stage/FabLab/entrepreneur_full.csv',
|
||
|
);
|
||
|
const csv = CSV.parse(file.replaceAll(';', ','), {
|
||
|
skipFirstRow: true,
|
||
|
}) as CsvEntry[];
|
||
|
|
||
|
const userIds: number[] = [];
|
||
|
|
||
|
function capitalize(str: string): string {
|
||
|
const [first, ...tail] = str.split('');
|
||
|
return `${first.toLocaleUpperCase()}${tail.join('').toLocaleLowerCase()}`;
|
||
|
}
|
||
|
|
||
|
for (const { firstname, lastname, mail } of csv) {
|
||
|
const login = `${firstname.toLowerCase()}.${lastname.toLowerCase()}`;
|
||
|
|
||
|
try {
|
||
|
const { user } = await redmine.users.create({
|
||
|
firstname: capitalize(firstname),
|
||
|
lastname: capitalize(lastname),
|
||
|
mail: mail,
|
||
|
login,
|
||
|
sendCreationMail: true,
|
||
|
generatePassword: true,
|
||
|
});
|
||
|
|
||
|
userIds.push(user.id);
|
||
|
} catch {
|
||
|
console.error(login);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
await redmine.unstableGroups.create({ name: 'entrepreneur-01-24', userIds });
|