membership

This commit is contained in:
Anton Schegg 2025-01-02 18:40:46 +01:00
parent c7b0adee07
commit c8b45512c5

View file

@ -153,6 +153,21 @@ router.get("/", async (req, res) => {
nameAffix = "sen.";
nn = nn.substring(0, nn.length - 6);
}
// before 1.7.2003: Altersobergrenze für Aktive: 60
const limit60 = moment('2003-07-01');
// 1.7.2003 bis 10.12.2011: 63
const limit63 = moment('2011-12-10');
// from 10.12.2011: 65
const alter60 = moment(queryResultElement.Geboren).add(60, 'years');
const alter63 = moment(queryResultElement.Geboren).add(63, 'years');
const alter65 = moment(queryResultElement.Geboren).add(65, 'years');
const eintritt = moment(queryResultElement.Eingetreten);
const verstorben = moment(queryResultElement.verstorben);
let newMember: CreateMemberCommand = {
salutation: queryResultElement.Anrede.trim(),
firstname: queryResultElement.Vorname.trim(),
@ -163,8 +178,14 @@ router.get("/", async (req, res) => {
const memberId = await MemberCommandHandler.create(newMember);
console.log(`Created member ${newMember.firstname} ${newMember.lastname} with id ${memberId}`);
if (queryResultElement.ID === 567) {
console.log('jetzt');
}
let stateId = sStatesByName["aktiv"];
if (queryResultElement["Übergang Passiv"] === queryResultElement.Eingetreten) {
if (!queryResultElement.Eingetreten) {
throw new Error('Eingetreten missing');
}
if (queryResultElement["Übergang Passiv"] && moment(queryResultElement["Übergang Passiv"]).format('L') === moment(queryResultElement.Eingetreten).format('L')) {
stateId = sStatesByName["fördernd"];
}
let start = queryResultElement.Eingetreten;
@ -173,12 +194,12 @@ router.get("/", async (req, res) => {
};
let ms1 = await MembershipCommandHandler.create(createMembership);
if (queryResultElement["Übergang Passiv"] && queryResultElement["Übergang Passiv"] !== queryResultElement.Eingetreten) {
if (queryResultElement["Übergang Passiv"] && moment(queryResultElement["Übergang Passiv"]).format('L') !== moment(queryResultElement.Eingetreten).format('L')) {
// membership transitioned to passiv
// no knowledge about active time => assume active until age of 60 or 65
let end: Date = queryResultElement["Übergang Passiv"];
let terminationReason : string = "aktiv >> passiv";
let newStart = queryResultElement["Übergang Passiv"];
let terminationReason: string = "aktiv >> passiv";
let newStart = queryResultElement["Übergang Passiv"];
let newStateId = sStatesByName["passiv"];
if (queryResultElement.Geboren == null && queryResultElement.verzogenDatum) {
@ -186,16 +207,6 @@ router.get("/", async (req, res) => {
end = queryResultElement.verzogenDatum
} else {
if (queryResultElement["Übergang Passiv"] < queryResultElement.Eingetreten) {
// before 1.7.2003: Altersobergrenze für Aktive: 60
const limit60 = moment('2003-07-01');
// 1.7.2003 bis 10.12.2011: 63
const limit63 = moment('2011-12-10');
// from 10.12.2011: 65
const alter60 = moment(queryResultElement.Geboren).add(60, 'years');
const alter63 = moment(queryResultElement.Geboren).add(63, 'years');
const alter65 = moment(queryResultElement.Geboren).add(65, 'years');
if (alter60.isBefore(limit60)) {
terminationReason = "passiv (Altersobergrenze: 60)";
end = alter60.toDate();
@ -210,31 +221,106 @@ router.get("/", async (req, res) => {
}
}
}
newStart = end;
// finish current membership
let updateMembership: UpdateMembershipCommand = {
end: end,
id: ms1,
internalId: queryResultElement.ID,
memberId: memberId,
start: start,
statusId: stateId,
terminationReason: terminationReason,
};
await MembershipCommandHandler.update(updateMembership);
if (end) {
newStart = end;
// create new membership with passiv state
stateId = newStateId;
start = newStart;
let createMembership: CreateMembershipCommand = {
// internalId: queryResultElement.ID,
memberId: memberId,
start: start,
statusId: stateId,
};
ms1 = await MembershipCommandHandler.create(createMembership);
if (!(queryResultElement.verstorben && moment(queryResultElement.verstorben).isBefore(moment(end)))) {
// finish current membership (but only if member was alive at this time)
let updateMembership: UpdateMembershipCommand = {
end: end,
id: ms1,
internalId: queryResultElement.ID,
memberId: memberId,
start: start,
statusId: stateId,
terminationReason: terminationReason,
};
await MembershipCommandHandler.update(updateMembership);
// create new membership with passiv state
stateId = newStateId;
start = newStart;
let createMembership: CreateMembershipCommand = {
// internalId: queryResultElement.ID,
memberId: memberId,
start: start,
statusId: stateId,
};
ms1 = await MembershipCommandHandler.create(createMembership);
}
}
}
if (!queryResultElement["Übergang Passiv"] && queryResultElement.verstorben) {
let terminationReason;
let end;
let newStart;
let newStateId;
if (alter60.isBefore(limit60) && alter60.isBefore(verstorben)) {
if (alter60.isBefore(eintritt)) {
stateId = sStatesByName["passiv"];
} else {
terminationReason = "passiv (Altersobergrenze: 60)";
end = alter60.toDate();
newStart = end;
newStateId = sStatesByName["passiv"];
}
} else {
if (alter63.isBefore(limit63) && alter63.isBefore(verstorben)) {
if (alter63.isBefore(eintritt)) {
stateId = sStatesByName["passiv"];
} else {
terminationReason = "passiv (Altersobergrenze: 63)";
end = alter63.toDate();
newStart = end;
newStateId = sStatesByName["passiv"];
}
} else {
if (alter65.isBefore(verstorben)) {
if (alter65.isBefore(eintritt)) {
stateId = sStatesByName["passiv"];
} else {
terminationReason = "passiv (Altersobergrenze: 65)";
end = alter65.toDate();
newStart = end;
newStateId = sStatesByName["passiv"];
}
} else {
end = queryResultElement.verstorben;
terminationReason = "verstorben";
}
}
}
if (end) {
let updateMembership: UpdateMembershipCommand = {
end: end,
id: ms1,
internalId: queryResultElement.ID,
memberId: memberId,
start: start,
statusId: stateId,
terminationReason: terminationReason,
};
await MembershipCommandHandler.update(updateMembership);
if (newStart) {
// create new membership with passiv state
stateId = newStateId;
start = newStart;
let createMembership: CreateMembershipCommand = {
// internalId: queryResultElement.ID,
memberId: memberId,
start: start,
statusId: stateId,
};
ms1 = await MembershipCommandHandler.create(createMembership);
}
}
}
if (queryResultElement.Ausgetreten) {
let updateMembership: UpdateMembershipCommand = {
end: queryResultElement.Ausgetreten,