@@ -85,20 +85,19 @@ export async function applicationTextPresenter (doc: Doc, control: TriggerContro
8585 * @public
8686 */
8787export async function OnRecruitUpdate ( tx : Tx , control : TriggerControl ) : Promise < Tx [ ] > {
88- const actualTx = TxProcessor . extractTx ( tx )
89- const cud = actualTx as TxCUD < Doc >
90- if ( ! control . hierarchy . isDerived ( cud . objectClass , recruit . class . Vacancy ) ) {
88+ const actualTx = TxProcessor . extractTx ( tx ) as TxCUD < Doc >
89+ if ( ! control . hierarchy . isDerived ( actualTx . objectClass , recruit . class . Vacancy ) ) {
9190 return [ ]
9291 }
9392
9493 const res : Tx [ ] = [ ]
9594
9695 if ( actualTx . _class === core . class . TxCreateDoc ) {
97- handleVacancyCreate ( control , cud , actualTx , res )
96+ handleVacancyCreate ( control , actualTx , res )
9897 } else if ( actualTx . _class === core . class . TxUpdateDoc ) {
99- await handleVacancyUpdate ( control , cud , res )
98+ await handleVacancyUpdate ( control , actualTx , res )
10099 } else if ( actualTx . _class === core . class . TxRemoveDoc ) {
101- await handleVacancyRemove ( control , cud , actualTx )
100+ handleVacancyRemove ( control , actualTx , res )
102101 }
103102 return res
104103}
@@ -156,16 +155,13 @@ async function handleVacancyUpdate (control: TriggerControl, cud: TxCUD<Doc>, re
156155 }
157156}
158157
159- async function handleVacancyRemove ( control : TriggerControl , cud : TxCUD < Doc > , actualTx : Tx ) : Promise < void > {
160- const removeTx = actualTx as TxRemoveDoc < Vacancy >
158+ function handleVacancyRemove ( control : TriggerControl , cud : TxCUD < Doc > , res : Tx [ ] ) : void {
159+ const removeTx = cud as TxRemoveDoc < Vacancy >
161160 // It could be null or new value
162- const txes = (
163- await control . findAll ( control . ctx , core . class . TxCUD , {
164- objectId : removeTx . objectId
165- } )
166- ) . filter ( ( it ) => it . _id !== removeTx . _id )
167- const vacancy = TxProcessor . buildDoc2Doc ( txes ) as Vacancy
168- const res : Tx [ ] = [ ]
161+ const vacancy = control . removedMap . get ( removeTx . objectId ) as Vacancy
162+ if ( vacancy === undefined ) {
163+ return
164+ }
169165 if ( vacancy . company != null ) {
170166 // We have old value
171167 res . push (
@@ -182,8 +178,8 @@ async function handleVacancyRemove (control: TriggerControl, cud: TxCUD<Doc>, ac
182178 }
183179}
184180
185- function handleVacancyCreate ( control : TriggerControl , cud : TxCUD < Doc > , actualTx : Tx , res : Tx [ ] ) : void {
186- const createTx = actualTx as TxCreateDoc < Vacancy >
181+ function handleVacancyCreate ( control : TriggerControl , cud : TxCUD < Doc > , res : Tx [ ] ) : void {
182+ const createTx = cud as TxCreateDoc < Vacancy >
187183 const vacancy = TxProcessor . createDoc2Doc ( createTx )
188184 if ( vacancy . company !== undefined ) {
189185 res . push (
0 commit comments