@@ -2,6 +2,7 @@ import { client, db } from '../../../services/mongo.service';
22import catalog from '../../commons/catalog' ;
33import { BadRequestError , NotFoundError } from '../../commons/http-errors' ;
44import readQuery from '../../commons/queries/structures.query' ;
5+ import identifierTypes from '../identifiers/bulk-import-identifier-types' ;
56import {
67 categoriesRepository ,
78 identifiersRepository ,
@@ -152,88 +153,20 @@ export const fromPayloadToStructure = async (req, res, next) => {
152153 id : await catalog . getUniqueId ( 'weblinks' , 15 ) ,
153154 } ) ;
154155 }
155- const structureIdentifiers = [ ] ;
156- if ( payload . idref ) {
157- structureIdentifiers . push ( {
158- value : payload . idref ,
159- type : 'idref' ,
160- createdBy : req . currentUser . id ,
161- createdAt : new Date ( ) ,
162- id : await catalog . getUniqueId ( 'identifiers' , 15 ) ,
163- } ) ;
164- }
165- if ( payload . wikidata ) {
166- structureIdentifiers . push ( {
167- value : payload . wikidata ,
168- type : 'wikidata' ,
169- createdBy : req . currentUser . id ,
170- createdAt : new Date ( ) ,
171- id : await catalog . getUniqueId ( 'identifiers' , 15 ) ,
172- } ) ;
173- }
174- if ( payload . uai ) {
175- structureIdentifiers . push ( {
176- value : payload . uai ,
177- type : 'uai' ,
178- createdBy : req . currentUser . id ,
179- createdAt : new Date ( ) ,
180- id : await catalog . getUniqueId ( 'identifiers' , 15 ) ,
181- } ) ;
182- }
183- if ( payload . siret ) {
184- structureIdentifiers . push ( {
185- value : payload . siret ,
186- type : 'siret' ,
187- createdBy : req . currentUser . id ,
188- createdAt : new Date ( ) ,
189- id : await catalog . getUniqueId ( 'identifiers' , 15 ) ,
190- } ) ;
191- }
192- if ( payload . rnsr ) {
193- structureIdentifiers . push ( {
194- value : payload . rnsr ,
195- type : 'rnsr' ,
196- createdBy : req . currentUser . id ,
197- createdAt : new Date ( ) ,
198- id : await catalog . getUniqueId ( 'identifiers' , 15 ) ,
199- } ) ;
200- }
201- if ( payload . ed ) {
202- structureIdentifiers . push ( {
203- value : payload . ed ,
204- type : 'ed' ,
205- createdBy : req . currentUser . id ,
206- createdAt : new Date ( ) ,
207- id : await catalog . getUniqueId ( 'identifiers' , 15 ) ,
208- } ) ;
209- }
210- if ( payload . crunchbase ) {
211- structureIdentifiers . push ( {
212- value : payload . crunchbase ,
213- type : 'crunchbase' ,
214- createdBy : req . currentUser . id ,
215- createdAt : new Date ( ) ,
216- id : await catalog . getUniqueId ( 'identifiers' , 15 ) ,
217- } ) ;
218- }
219- if ( payload . dealroom ) {
220- structureIdentifiers . push ( {
221- value : payload . dealroom ,
222- type : 'dealroom' ,
223- createdBy : req . currentUser . id ,
224- createdAt : new Date ( ) ,
225- id : await catalog . getUniqueId ( 'identifiers' , 15 ) ,
226- } ) ;
227- }
228- if ( payload . ror ) {
229- structureIdentifiers . push ( {
230- value : payload . ror ,
231- type : 'ror' ,
232- createdBy : req . currentUser . id ,
233- createdAt : new Date ( ) ,
234- id : await catalog . getUniqueId ( 'identifiers' , 15 ) ,
235- } ) ;
236- }
156+ const structureIdentifiers = ( await Promise . all (
157+ identifierTypes . map ( async ( type ) => {
158+ if ( payload [ type ] ) {
159+ return {
160+ value : payload [ type ] ,
161+ type,
162+ createdBy : req . currentUser . id ,
163+ createdAt : new Date ( ) ,
164+ id : await catalog . getUniqueId ( 'identifiers' , 15 ) ,
165+ } ;
166+ }
167+ return null ;
168+ } ) ,
169+ ) ) . filter ( Boolean ) ;
237170 const structureSocialMedias = [ ] ;
238171 if ( payload . twitter ) {
239172 structureSocialMedias . push ( {
0 commit comments