feat(file retrieval): add dossier_transfer_log
This commit is contained in:
parent
84398b147d
commit
7e6792c616
2 changed files with 17 additions and 3 deletions
|
@ -16,12 +16,22 @@ class RecoveryService
|
|||
recoverable_procedure_ids = recoverable_procedures(previous_user: previous_user, siret: siret)
|
||||
.map { _1[:procedure_id] }
|
||||
|
||||
procedure_ids
|
||||
.select { |id| id.in?(recoverable_procedure_ids) }
|
||||
dossiers = procedure_ids
|
||||
.filter { |id| id.in?(recoverable_procedure_ids) }
|
||||
.then do |p_ids|
|
||||
previous_user.dossiers.joins(:procedure)
|
||||
.where(procedure: { id: p_ids })
|
||||
.update_all(user_id: next_user.id)
|
||||
end
|
||||
end
|
||||
|
||||
dossiers.pluck(:id).map do |id|
|
||||
{
|
||||
dossier_id: id,
|
||||
from: previous_user.email,
|
||||
from_support: false,
|
||||
to: next_user.email
|
||||
}
|
||||
end.then { |array| DossierTransferLog.create(array) }
|
||||
|
||||
dossiers.update_all(user_id: next_user.id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -70,6 +70,10 @@ RSpec.describe RecoveryService, type: :service do
|
|||
it 'moves the files to the next user' do
|
||||
subject
|
||||
expect(next_user.dossiers.count).to eq(3)
|
||||
|
||||
dossier_transfer_log = next_user.dossiers.first.transfer_logs.first
|
||||
expect(dossier_transfer_log.from).to eq(previous_user.email)
|
||||
expect(dossier_transfer_log.to).to eq(next_user.email)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue