feat(bisaya-course): update German course creation script to support default owner retrieval
All checks were successful
Deploy to production / deploy (push) Successful in 3m12s
All checks were successful
Deploy to production / deploy (push) Successful in 3m12s
- Modified the create-german-for-bisaya-course.js script to allow optional ownerHashedId parameter.
- Implemented a new function to find a default owner ('system' or 'admin') if no ownerHashedId is provided.
- Updated documentation to reflect the change in usage for the script.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* Erstellt den Phase-1-Deutschkurs für Bisaya-Lernende.
|
||||
*
|
||||
* Verwendung:
|
||||
* node backend/scripts/create-german-for-bisaya-course.js <ownerHashedId>
|
||||
* node backend/scripts/create-german-for-bisaya-course.js [ownerHashedId]
|
||||
*/
|
||||
|
||||
import crypto from 'crypto';
|
||||
@@ -56,10 +56,23 @@ async function getOwnerByHashedId(ownerHashedId) {
|
||||
return user;
|
||||
}
|
||||
|
||||
async function findDefaultOwner() {
|
||||
let user = await User.findOne({ where: { username: 'system' } });
|
||||
if (!user) {
|
||||
user = await User.findOne({ where: { username: 'admin' } });
|
||||
}
|
||||
if (!user) {
|
||||
throw new Error('Weder system- noch admin-Benutzer gefunden');
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
async function createGermanForBisayaCourse(ownerHashedId) {
|
||||
await sequelize.authenticate();
|
||||
|
||||
const owner = await getOwnerByHashedId(ownerHashedId);
|
||||
const owner = ownerHashedId
|
||||
? await getOwnerByHashedId(ownerHashedId)
|
||||
: await findDefaultOwner();
|
||||
const germanLanguageId = await getLanguageId('Deutsch');
|
||||
const bisayaLanguageId = await getLanguageId('Bisaya');
|
||||
|
||||
@@ -131,11 +144,6 @@ async function createGermanForBisayaCourse(ownerHashedId) {
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
const ownerHashedId = process.argv[2];
|
||||
|
||||
if (!ownerHashedId) {
|
||||
console.error('Verwendung: node backend/scripts/create-german-for-bisaya-course.js <ownerHashedId>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
createGermanForBisayaCourse(ownerHashedId)
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
|
||||
@@ -463,10 +463,12 @@ Die Phasen 1 bis 5 sind jetzt als technische Struktur angelegt:
|
||||
### Neuer Kurs von Grund auf
|
||||
|
||||
```bash
|
||||
node backend/scripts/create-german-for-bisaya-course.js <ownerHashedId>
|
||||
node backend/scripts/create-german-for-bisaya-course.js [ownerHashedId]
|
||||
node backend/scripts/create-german-for-bisaya-course-content.js
|
||||
```
|
||||
|
||||
Ohne `ownerHashedId` nutzt das Skript automatisch zuerst `system`, sonst `admin` als Kursbesitzer.
|
||||
|
||||
### Bestehenden Kurs stufenweise erweitern
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user