From 93afdec274ec203ecb132ef3845fb4e453fd276c Mon Sep 17 00:00:00 2001 From: Anton Schegg Date: Sun, 5 Jan 2025 17:46:31 +0100 Subject: [PATCH] member communication --- src/routes/fillfromold.ts | 157 ++++++++++++++++++++------------------ 1 file changed, 81 insertions(+), 76 deletions(-) diff --git a/src/routes/fillfromold.ts b/src/routes/fillfromold.ts index eaa8b9d..7fff06f 100644 --- a/src/routes/fillfromold.ts +++ b/src/routes/fillfromold.ts @@ -462,88 +462,93 @@ router.get("/", async (req, res) => { } // add communications - const createCommunicationCommands:CreateCommunicationCommand[] = []; - let havePreferred = false; - if (queryResultElement.Mobiltelefon && !queryResultElement.verstorben && !queryResultElement.verzogenDatum) { - const createCommunicationMobile: CreateCommunicationCommand = { - memberId: memberId, - typeId: sCommTypesByName['SMS'], - isSMSAlarming: false, - city: "", - email: "", - mobile: queryResultElement.Mobiltelefon.trim(), - preferred: false, - street: "", - streetNumber: 0, - streetNumberAddition: "", + if (!queryResultElement.verzogen) { + const createCommunicationCommands: CreateCommunicationCommand[] = []; + let havePreferred = false; + if (queryResultElement.Mobiltelefon && !queryResultElement.verstorben && !queryResultElement.verzogenDatum) { + const createCommunicationMobile: CreateCommunicationCommand = { + memberId: memberId, + typeId: sCommTypesByName['SMS'], + isSMSAlarming: false, + city: "", + email: "", + mobile: queryResultElement.Mobiltelefon.trim(), + postalCode: "", + preferred: false, + street: "", + streetNumber: 0, + streetNumberAddition: "", + } + createCommunicationCommands.push(createCommunicationMobile); } - createCommunicationCommands.push(createCommunicationMobile); - } - if (queryResultElement.email && !queryResultElement.verstorben && !queryResultElement.verzogenDatum) { - const createCommunicationEmail: CreateCommunicationCommand = { - memberId: memberId, - typeId: sCommTypesByName['Email'], - isSMSAlarming: false, - city: "", - email: queryResultElement.email, - mobile: "", - preferred: queryResultElement.EinladungNurPerEmail, - street: "", - streetNumber: 0, - streetNumberAddition: "", + if (queryResultElement.email && !queryResultElement.verstorben && !queryResultElement.verzogenDatum) { + const createCommunicationEmail: CreateCommunicationCommand = { + memberId: memberId, + typeId: sCommTypesByName['Email'], + isSMSAlarming: false, + city: "", + email: queryResultElement.email, + mobile: "", + preferred: queryResultElement.EinladungNurPerEmail, + postalCode: "", + street: "", + streetNumber: 0, + streetNumberAddition: "", + } + if (createCommunicationEmail.preferred) { + havePreferred = true; + } + createCommunicationCommands.push(createCommunicationEmail); } - if (createCommunicationEmail.preferred) { - havePreferred = true; + if (queryResultElement.Mobiltelefon && queryResultElement.EinladungNurPerEmail && !queryResultElement.email && !queryResultElement.verstorben && !queryResultElement.verzogenDatum) { + const preferred = havePreferred === false; + const createCommunicationWhatsApp: CreateCommunicationCommand = { + memberId: memberId, + typeId: sCommTypesByName['WhatsApp'], + isSMSAlarming: false, + city: "", + email: "", + mobile: queryResultElement.Mobiltelefon.trim(), + postalCode: "", + preferred: preferred, + street: "", + streetNumber: 0, + streetNumberAddition: "", + } + if (createCommunicationWhatsApp.preferred) { + havePreferred = true; + } + createCommunicationCommands.push(createCommunicationWhatsApp); } - createCommunicationCommands.push(createCommunicationEmail); - } - if (queryResultElement.Mobiltelefon && queryResultElement.EinladungNurPerEmail && !queryResultElement.email && !queryResultElement.verstorben && !queryResultElement.verzogenDatum) { - const preferred = havePreferred === false; - const createCommunicationWhatsApp: CreateCommunicationCommand = { - memberId: memberId, - typeId: sCommTypesByName['WhatsApp'], - isSMSAlarming: false, - city: "", - email: "", - mobile: queryResultElement.Mobiltelefon.trim(), - preferred: preferred, - street: "", - streetNumber: 0, - streetNumberAddition: "", + if (queryResultElement.Ort && queryResultElement.street) { + const preferred = havePreferred === false; + const createCommunicationMail: CreateCommunicationCommand = { + memberId: memberId, + typeId: sCommTypesByName['Post'], + isSMSAlarming: false, + city: queryResultElement.Ort, + email: "", + mobile: "", + preferred: preferred, + postalCode: queryResultElement.PLZ, + street: queryResultElement.street.trim(), + streetNumber: queryResultElement.streetnumber, + streetNumberAddition: queryResultElement.streetnumberaddition.trim(), + } + if (createCommunicationMail.preferred) { + havePreferred = true; + } + createCommunicationCommands.push(createCommunicationMail); } - if (createCommunicationWhatsApp.preferred) { - havePreferred = true; - } - createCommunicationCommands.push(createCommunicationWhatsApp); - } - if (queryResultElement.Ort && queryResultElement.street) { - const preferred = havePreferred === false; - const createCommunicationMail: CreateCommunicationCommand = { - memberId: memberId, - typeId: sCommTypesByName['Post'], - isSMSAlarming: false, - city: queryResultElement.Ort, - email: "", - mobile: "", - preferred: preferred, - street: queryResultElement.street.trim(), - streetNumber: queryResultElement.streetnumber, - streetNumberAddition: queryResultElement.streetnumberaddition.trim(), - } - if (createCommunicationMail.preferred) { - havePreferred = true; - } - createCommunicationCommands.push(createCommunicationMail); - } - if (createCommunicationCommands.length > 0 && !havePreferred) { - console.log(`No preferred communication for ${newMember.firstname} ${newMember.lastname}`) + if (createCommunicationCommands.length > 0 && !havePreferred) { + console.log(`No preferred communication for ${newMember.firstname} ${newMember.lastname}`) + } + for (const createCommunicationCommand of createCommunicationCommands) { + console.log(`Adding communication for ${sCommTypesById[createCommunicationCommand.typeId]} to ${newMember.firstname} ${newMember.lastname}`) + await CommunicationCommandHandler.create(createCommunicationCommand); + } } - for (const createCommunicationCommand of createCommunicationCommands) { - console.log(`Adding communication for ${sCommTypesById[createCommunicationCommand.typeId]} to ${newMember.firstname} ${newMember.lastname}`) - await CommunicationCommandHandler.create(createCommunicationCommand); - } - } res.sendStatus(200);