import from old database

This commit is contained in:
Anton Schegg 2024-12-29 21:50:22 +01:00
parent 3b584767f3
commit 3ea7c423c9
3 changed files with 109 additions and 0 deletions

View file

@ -30,8 +30,10 @@
"handlebars": "^4.7.8",
"ics": "^3.8.1",
"jsonwebtoken": "^9.0.2",
"knex": "^3.1.0",
"moment": "^2.30.1",
"ms": "^2.1.3",
"mssql": "^10.0.4",
"mysql": "^2.18.1",
"node-schedule": "^2.1.1",
"nodemailer": "^6.9.14",

105
src/routes/fillfromold.ts Normal file
View file

@ -0,0 +1,105 @@
import express from "express";
import knex from 'knex';
import AwardService from "../service/awardService";
import { CreateAwardCommand, DeleteAwardCommand } from "../command/awardCommand";
import AwardCommandHandler from "../command/awardCommandHandler";
import { award } from "../entity/award";
import MemberService from "../service/memberService";
import { CreateMemberCommand, DeleteMemberCommand } from "../command/memberCommand";
import { member } from "../entity/member";
import MemberCommandHandler from "../command/memberCommandHandler";
import { Salutation } from "../enums/salutation";
var router = express.Router({ mergeParams: true });
router.get("/", async (req, res) => {
const dbhost = process.env.OLD_DB_HOST;
const dbport = Number(process.env.OLD_DB_PORT);
const dbuser = process.env.OLD_DB_USER;
const dbuserpass = process.env.OLD_DB_USERPASS;
const dbname = process.env.OLD_DB_NAME;
const db = knex({
client: 'mssql',
connection: {
host: dbhost,
port: dbport,
user: dbuser,
password: dbuserpass,
database: dbname,
options: {
trustServerCertificate: true,
enableArithAbort: true,
encrypt: true
}
},
debug: false,
pool: {
min: 0, max: 30
}
});
let queryResult = await db('Mitglieder');
console.log(`Read ${queryResult.length} Mitglieder`);
// Delete members
let [members, total] = await MemberService.getAll(0, 9999);
for (const m of members) {
let deleteMember: DeleteMemberCommand = {
id: m.id,
};
console.log(`Delete member ${m.id}`);
await MemberCommandHandler.delete(deleteMember);
}
// Delete awards
let awards = await AwardService.getAll();
for (const award of awards) {
let deleteAward: DeleteAwardCommand = {
id: award.id,
};
console.log(`Delete award ${award.id}`);
await AwardCommandHandler.delete(deleteAward);
}
const sAwardsById :any = {};
// Create Awards
const awardNames = ['Ehrennadel Silber', 'Ehrennadel Gold', 'Ehrenkreuz Silber', 'Ehrenkreuz Gold', 'Ehrenmitgliedschaft', '25 Jahre aktiv', '40 Jahre aktiv'];
for (const awardName of awardNames) {
let createAward: CreateAwardCommand = {
award: awardName,
};
const awardId = await AwardCommandHandler.create(createAward);
console.log(`Created award ${awardName} with id ${awardId}`);
sAwardsById[awardId] = awardName;
}
for (const queryResultElement of queryResult) {
let nameAffix :string = '';
let nn = queryResultElement.Nachname.trim();
if (nn.endsWith(', jun.')) {
nameAffix = 'jun.';
nn = nn.substring(0, nn.length - 6);
}
if (nn.endsWith(', sen.')) {
nameAffix = 'sen.';
nn = nn.substring(0, nn.length - 6);
}
let newMember: CreateMemberCommand = {
salutation: queryResultElement.Anrede.trim(),
firstname: queryResultElement.Vorname.trim(),
lastname: nn,
nameaffix: nameAffix,
birthdate: queryResultElement.Geboren ? queryResultElement.Geboren : '1900-01-01',
}
const memberId = await MemberCommandHandler.create(newMember);
console.log(`Created member ${newMember.firstname} ${newMember.lastname} with id ${memberId}`);
}
res.sendStatus(200);
});
export default router;

View file

@ -13,6 +13,7 @@ import reset from "./reset";
import auth from "./auth";
import admin from "./admin/index";
import user from "./user";
import fillfromold from "./fillfromold";
export default (app: Express) => {
app.set("query parser", "extended");
@ -27,6 +28,7 @@ export default (app: Express) => {
app.use("/api/public", publicAvailable);
app.use("/api/setup", allowSetup, setup);
app.use("/api/fillfromold", fillfromold);
app.use("/api/reset", reset);
app.use("/api/invite", invite);
app.use("/api/auth", auth);