draft-redmine_users_from_csv/src/create_users.ts

35 lines
835 B
TypeScript
Raw Normal View History

2024-01-15 21:05:44 +01:00
import { Redmine } from 'bluemine'
import { CsvEntry } from '../type.ts'
2024-01-15 20:46:54 +01:00
async function createUsers(redmine: Redmine, csv: CsvEntry[]) {
2024-01-15 21:05:44 +01:00
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 })
2024-01-15 20:46:54 +01:00
}