11package pro.qyoga.app.publc.surverys
22
3+ import org.slf4j.LoggerFactory
34import org.springframework.stereotype.Component
45import org.springframework.transaction.annotation.Transactional
56import pro.qyoga.core.clients.cards.ClientsRepo
67import pro.qyoga.core.clients.cards.findByPhone
78import pro.qyoga.core.clients.cards.model.PhoneNumber
9+ import pro.qyoga.core.clients.cards.model.toLogString
810import pro.qyoga.core.survey_forms.settings.model.SurveyFormsSettingsRepo
911import pro.qyoga.core.survey_forms.settings.model.findByYandexAdminEmail
1012import java.time.LocalDate
@@ -16,15 +18,24 @@ class ProcessSurveyOp(
1618 private val surveyFormsSettingsRepo : SurveyFormsSettingsRepo
1719) : (SurveyRq ) -> Unit {
1820
21+ private val log = LoggerFactory .getLogger(javaClass)
22+
1923 @Transactional
2024 override operator fun invoke (surveyRq : SurveyRq ) {
25+ log.debug(" Processing survey: {}" , surveyRq)
2126 val therapistRef = surveyFormsSettingsRepo.findByYandexAdminEmail(surveyRq.yandexAdminEmail)
2227 ?.therapistRef
2328 ? : throw InvalidSurveyException .surveySettingsNotFoundForAdminEmail()
2429
2530 var client = clientsRepo.findByPhone(therapistRef, PhoneNumber .of(surveyRq.survey.phone))
2631 ? : surveyRq.survey.toClient(therapistRef)
2732
33+ if (client.version > 0 ) {
34+ log.info(" Updating client: {} from survey" , client.toLogString())
35+ } else {
36+ log.info(" Creating client: {} from survey" , client.toLogString())
37+ }
38+
2839 val today = LocalDate .now()
2940 client = client
3041 .prependComplaints(formatComplaintsEntry(surveyRq, today))
0 commit comments