membership
This commit is contained in:
parent
c7b0adee07
commit
c8b45512c5
1 changed files with 122 additions and 36 deletions
|
@ -153,6 +153,21 @@ router.get("/", async (req, res) => {
|
||||||
nameAffix = "sen.";
|
nameAffix = "sen.";
|
||||||
nn = nn.substring(0, nn.length - 6);
|
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 = {
|
let newMember: CreateMemberCommand = {
|
||||||
salutation: queryResultElement.Anrede.trim(),
|
salutation: queryResultElement.Anrede.trim(),
|
||||||
firstname: queryResultElement.Vorname.trim(),
|
firstname: queryResultElement.Vorname.trim(),
|
||||||
|
@ -163,8 +178,14 @@ 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}`);
|
||||||
|
|
||||||
|
if (queryResultElement.ID === 567) {
|
||||||
|
console.log('jetzt');
|
||||||
|
}
|
||||||
let stateId = sStatesByName["aktiv"];
|
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"];
|
stateId = sStatesByName["fördernd"];
|
||||||
}
|
}
|
||||||
let start = queryResultElement.Eingetreten;
|
let start = queryResultElement.Eingetreten;
|
||||||
|
@ -173,12 +194,12 @@ router.get("/", async (req, res) => {
|
||||||
};
|
};
|
||||||
let ms1 = await MembershipCommandHandler.create(createMembership);
|
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
|
// membership transitioned to passiv
|
||||||
// no knowledge about active time => assume active until age of 60 or 65
|
// no knowledge about active time => assume active until age of 60 or 65
|
||||||
let end: Date = queryResultElement["Übergang Passiv"];
|
let end: Date = queryResultElement["Übergang Passiv"];
|
||||||
let terminationReason : string = "aktiv >> passiv";
|
let terminationReason: string = "aktiv >> passiv";
|
||||||
let newStart = queryResultElement["Übergang Passiv"];
|
let newStart = queryResultElement["Übergang Passiv"];
|
||||||
let newStateId = sStatesByName["passiv"];
|
let newStateId = sStatesByName["passiv"];
|
||||||
|
|
||||||
if (queryResultElement.Geboren == null && queryResultElement.verzogenDatum) {
|
if (queryResultElement.Geboren == null && queryResultElement.verzogenDatum) {
|
||||||
|
@ -186,16 +207,6 @@ router.get("/", async (req, res) => {
|
||||||
end = queryResultElement.verzogenDatum
|
end = queryResultElement.verzogenDatum
|
||||||
} else {
|
} else {
|
||||||
if (queryResultElement["Übergang Passiv"] < queryResultElement.Eingetreten) {
|
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)) {
|
if (alter60.isBefore(limit60)) {
|
||||||
terminationReason = "passiv (Altersobergrenze: 60)";
|
terminationReason = "passiv (Altersobergrenze: 60)";
|
||||||
end = alter60.toDate();
|
end = alter60.toDate();
|
||||||
|
@ -210,31 +221,106 @@ router.get("/", async (req, res) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newStart = end;
|
if (end) {
|
||||||
// finish current membership
|
newStart = end;
|
||||||
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
|
if (!(queryResultElement.verstorben && moment(queryResultElement.verstorben).isBefore(moment(end)))) {
|
||||||
stateId = newStateId;
|
// finish current membership (but only if member was alive at this time)
|
||||||
start = newStart;
|
let updateMembership: UpdateMembershipCommand = {
|
||||||
let createMembership: CreateMembershipCommand = {
|
end: end,
|
||||||
// internalId: queryResultElement.ID,
|
id: ms1,
|
||||||
memberId: memberId,
|
internalId: queryResultElement.ID,
|
||||||
start: start,
|
memberId: memberId,
|
||||||
statusId: stateId,
|
start: start,
|
||||||
};
|
statusId: stateId,
|
||||||
ms1 = await MembershipCommandHandler.create(createMembership);
|
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) {
|
if (queryResultElement.Ausgetreten) {
|
||||||
let updateMembership: UpdateMembershipCommand = {
|
let updateMembership: UpdateMembershipCommand = {
|
||||||
end: queryResultElement.Ausgetreten,
|
end: queryResultElement.Ausgetreten,
|
||||||
|
|
Loading…
Reference in a new issue