import from old database
This commit is contained in:
parent
3ea7c423c9
commit
1f95f8f64d
1 changed files with 49 additions and 2 deletions
|
@ -9,6 +9,9 @@ import { CreateMemberCommand, DeleteMemberCommand } from "../command/memberComma
|
||||||
import { member } from "../entity/member";
|
import { member } from "../entity/member";
|
||||||
import MemberCommandHandler from "../command/memberCommandHandler";
|
import MemberCommandHandler from "../command/memberCommandHandler";
|
||||||
import { Salutation } from "../enums/salutation";
|
import { Salutation } from "../enums/salutation";
|
||||||
|
import MemberAwardCommandHandler from "../command/memberAwardCommandHandler";
|
||||||
|
import { CreateMemberAwardCommand, DeleteMemberAwardCommand } from "../command/memberAwardCommand";
|
||||||
|
import MemberAwardService from "../service/memberAwardService";
|
||||||
|
|
||||||
var router = express.Router({ mergeParams: true });
|
var router = express.Router({ mergeParams: true });
|
||||||
|
|
||||||
|
@ -43,10 +46,20 @@ router.get("/", async (req, res) => {
|
||||||
let queryResult = await db('Mitglieder');
|
let queryResult = await db('Mitglieder');
|
||||||
console.log(`Read ${queryResult.length} Mitglieder`);
|
console.log(`Read ${queryResult.length} Mitglieder`);
|
||||||
|
|
||||||
|
|
||||||
// Delete members
|
// Delete members
|
||||||
let [members, total] = await MemberService.getAll(0, 9999);
|
let [members, total] = await MemberService.getAll(0, 9999);
|
||||||
for (const m of members) {
|
for (const m of members) {
|
||||||
|
|
||||||
|
// delete all member awards of this member
|
||||||
|
let memberAwards = await MemberAwardService.getAll(m.id);
|
||||||
|
for (const award of memberAwards) {
|
||||||
|
let deleteMemberAward: DeleteMemberAwardCommand = {
|
||||||
|
id: award.id, memberId: m.id
|
||||||
|
};
|
||||||
|
console.log(`Deleting award ${award.id} from member ${m.id}`);
|
||||||
|
await MemberAwardCommandHandler.delete(deleteMemberAward)
|
||||||
|
}
|
||||||
|
|
||||||
let deleteMember: DeleteMemberCommand = {
|
let deleteMember: DeleteMemberCommand = {
|
||||||
id: m.id,
|
id: m.id,
|
||||||
};
|
};
|
||||||
|
@ -65,9 +78,10 @@ router.get("/", async (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const sAwardsById :any = {};
|
const sAwardsById :any = {};
|
||||||
|
const sAwardsByName :any = {};
|
||||||
|
|
||||||
// Create Awards
|
// Create Awards
|
||||||
const awardNames = ['Ehrennadel Silber', 'Ehrennadel Gold', 'Ehrenkreuz Silber', 'Ehrenkreuz Gold', 'Ehrenmitgliedschaft', '25 Jahre aktiv', '40 Jahre aktiv'];
|
const awardNames = ['Ehrennadel Silber', 'Ehrennadel Gold', 'Ehrenkreuz Silber', 'Ehrenkreuz Gold', 'Ehrenmitgliedschaft', 'Ehrung 25 Jahre aktiv', 'Ehrung 40 Jahre aktiv'];
|
||||||
for (const awardName of awardNames) {
|
for (const awardName of awardNames) {
|
||||||
let createAward: CreateAwardCommand = {
|
let createAward: CreateAwardCommand = {
|
||||||
award: awardName,
|
award: awardName,
|
||||||
|
@ -75,6 +89,7 @@ router.get("/", async (req, res) => {
|
||||||
const awardId = await AwardCommandHandler.create(createAward);
|
const awardId = await AwardCommandHandler.create(createAward);
|
||||||
console.log(`Created award ${awardName} with id ${awardId}`);
|
console.log(`Created award ${awardName} with id ${awardId}`);
|
||||||
sAwardsById[awardId] = awardName;
|
sAwardsById[awardId] = awardName;
|
||||||
|
sAwardsByName[awardName] = awardId;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const queryResultElement of queryResult) {
|
for (const queryResultElement of queryResult) {
|
||||||
|
@ -97,6 +112,38 @@ router.get("/", async (req, res) => {
|
||||||
}
|
}
|
||||||
const memberId = await MemberCommandHandler.create(newMember);
|
const memberId = await MemberCommandHandler.create(newMember);
|
||||||
console.log(`Created member ${newMember.firstname} ${newMember.lastname} with id ${memberId}`);
|
console.log(`Created member ${newMember.firstname} ${newMember.lastname} with id ${memberId}`);
|
||||||
|
|
||||||
|
for (const awardId in sAwardsById) {
|
||||||
|
const awardName = sAwardsById[awardId];
|
||||||
|
|
||||||
|
if (queryResultElement[awardName]) {
|
||||||
|
const awardDate = queryResultElement[awardName];
|
||||||
|
console.log(`Member ${newMember.firstname} ${newMember.lastname} got award ${awardName} at ${awardDate}`);
|
||||||
|
|
||||||
|
let given = true;
|
||||||
|
let note = '';
|
||||||
|
if (awardName === 'Ehrung 25 Jahre aktiv' && queryResultElement['keineEhrung25JahreAktivGrund'] !== null) {
|
||||||
|
given = false;
|
||||||
|
note = queryResultElement['keineEhrung25JahreAktivGrund'].trim();
|
||||||
|
}
|
||||||
|
if (awardName === 'Ehrennadel Silber' && queryResultElement['keineEhrennadelSilberGrund'] !== null) {
|
||||||
|
given = false;
|
||||||
|
note = queryResultElement['keineEhrennadelSilberGrund'].trim();
|
||||||
|
}
|
||||||
|
if (awardName === 'Ehrennadel Gold' && queryResultElement['keineEhrennadelGoldGrund'] !== null) {
|
||||||
|
given = false;
|
||||||
|
note = queryResultElement['keineEhrennadelGoldGrund'].trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
let newMemberAward: CreateMemberAwardCommand = {
|
||||||
|
awardId: parseInt(awardId), date: awardDate, given: given, memberId: memberId, note: note
|
||||||
|
}
|
||||||
|
await MemberAwardCommandHandler.create(newMemberAward);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
|
|
Loading…
Reference in a new issue