@@ -84,9 +84,41 @@ router.getRaw("/all.xlsx", async (req, res) => {
8484
8585 const canViewAll = true || Boolean ( application ?. feedback ?. id ) || hasAtLeastRole ( Role . Admin , user ) ;
8686
87+ const scannedUsers = await prisma . companyScannedUser . findMany ( {
88+ where : {
89+ company : {
90+ uid : user . companies ?. [ 0 ] ?. uid || "" ,
91+ } ,
92+ } ,
93+ select : {
94+ user : true ,
95+ } ,
96+ } ) ;
97+
98+ const resumeIds = scannedUsers
99+ . map ( ( entry ) => entry . user . resumeId )
100+ . filter ( ( id ) : id is number => null !== id ) ;
101+
102+ const scannedResumes = await prisma . resume . findMany ( {
103+ where : {
104+ id : { in : resumeIds } ,
105+ } ,
106+ include,
107+ } ) ;
108+
109+ const resumeById : Map < number , typeof scannedResumes [ 0 ] > = new Map (
110+ scannedResumes . map ( ( resume ) => [ resume . id , resume ] ) ,
111+ ) ;
112+
113+ const scannedUsersWithResumes = scannedUsers . map ( ( { user } ) => ( {
114+ user,
115+ resume : user . resumeId ? resumeById . get ( user . resumeId ) ?? null : null ,
116+ } ) ) ;
117+
118+
87119 const [
88120 allResumes ,
89- scannedResumes ,
121+ // scannedResumes,
90122 favouriteResumes ,
91123 translations ,
92124 ] = await Promise . all ( [
@@ -95,18 +127,18 @@ router.getRaw("/all.xlsx", async (req, res) => {
95127 include,
96128 } )
97129 : Promise . resolve ( [ ] ) ,
98- prisma . scannedResume . findMany ( {
99- where : {
100- company : {
101- uid : user . companies ?. [ 0 ] ?. uid || "" ,
102- } ,
103- } ,
104- select : {
105- resume : {
106- include,
107- } ,
108- } ,
109- } ) ,
130+ // prisma.scannedResume.findMany({
131+ // where: {
132+ // company: {
133+ // uid: user.companies?.[0]?.uid || "",
134+ // },
135+ // },
136+ // select: {
137+ // resume: {
138+ // include,
139+ // },
140+ // },
141+ // }),
110142 prisma . favouriteResume . findMany ( {
111143 where : {
112144 company : {
@@ -174,13 +206,13 @@ router.getRaw("/all.xlsx", async (req, res) => {
174206
175207 const addResumePage = (
176208 filter : ResumeFilters ,
177- resumes : typeof allResumes ,
209+ resumes : typeof scannedUsersWithResumes ,
178210 ) => {
179211 const worksheet = workbook . addWorksheet ( $t ( filter ) ) ;
180- const MAX_STUDY_YEARS = Math . max ( ...resumes . map ( ( x ) => x . studyYears ?. length || 0 ) ) ;
181- const MAX_WORK_EXPERIENCES = Math . max ( ...resumes . map ( ( x ) => x . workExperiences ?. length || 0 ) ) ;
182- const MAX_PROJECTS = Math . max ( ...resumes . map ( ( x ) => x . projects ?. length || 0 ) ) ;
183- const MAX_VOLUNTEER_EXPERIENCES = Math . max ( ...resumes . map ( ( x ) => x . volunteerExperiences ?. length || 0 ) ) ;
212+ const MAX_STUDY_YEARS = Math . max ( ...resumes . map ( ( x ) => x . resume ?. studyYears ?. length || 0 ) ) ;
213+ const MAX_WORK_EXPERIENCES = Math . max ( ...resumes . map ( ( x ) => x . resume ?. workExperiences ?. length || 0 ) ) ;
214+ const MAX_PROJECTS = Math . max ( ...resumes . map ( ( x ) => x . resume ?. projects ?. length || 0 ) ) ;
215+ const MAX_VOLUNTEER_EXPERIENCES = Math . max ( ...resumes . map ( ( x ) => x . resume ?. volunteerExperiences ?. length || 0 ) ) ;
184216
185217 worksheet . columns = [
186218 { header : $t ( "resume.name" ) , key : "name" } ,
@@ -226,119 +258,130 @@ router.getRaw("/all.xlsx", async (req, res) => {
226258
227259 const $fDur = < T extends { start : Date | string , until : Date | string | null | undefined , } > ( x : T ) => $fDate ( x . start , x . until ) ;
228260
229- for ( const resume of resumes ) {
230- const {
231- user : _user ,
232- volunteerExperiences,
233- faculty,
234- projects,
235- workExperiences,
236- technologies,
237- studyYears,
238- interests,
239- city,
240- cv,
241- } = resume ;
242- const user = _user ! ;
243-
244- const row = worksheet . addRow ( {
245- name : `${ user . firstName } ${ user . lastName } ` ,
246- city : `${ city } ` ,
247- phone : `${ user . phone } ` ,
248- email : `${ user . email } ` ,
249- facultyName : "" ,
250- facultyModule : "" ,
251- ...Object . fromEntries (
252- Array . from ( { length : MAX_STUDY_YEARS } , ( _ , i ) => [
253- [ `studyYearsType${ i } ` , "" ] ,
254- [ `studyYearsDuration${ i } ` , "" ] ,
255- ] as const ) . flat ( ) ,
256- ) ,
257- ...Object . fromEntries (
258- Array . from ( { length : MAX_WORK_EXPERIENCES } , ( _ , i ) => [
259- [ `workExperiencesCompany${ i } ` , "" ] ,
260- [ `workExperiencesPosition${ i } ` , "" ] ,
261- [ `workExperiencesDuration${ i } ` , "" ] ,
262- ] as const ) . flat ( ) ,
263- ) ,
264- ...Object . fromEntries (
265- Array . from ( { length : MAX_PROJECTS } , ( _ , i ) => [
266- [ `projectsProject${ i } ` , "" ] ,
267- [ `projectsPosition${ i } ` , "" ] ,
268- [ `projectsDuration${ i } ` , "" ] ,
269- ] as const ) . flat ( ) ,
270- ) ,
271- ...Object . fromEntries (
272- Array . from ( { length : MAX_VOLUNTEER_EXPERIENCES } , ( _ , i ) => [
273- [ `volunteerExperiencesOrganisation${ i } ` , "" ] ,
274- [ `volunteerExperiencesPosition${ i } ` , "" ] ,
275- [ `volunteerExperiencesDuration${ i } ` , "" ] ,
276- ] as const ) . flat ( ) ,
277- ) ,
278- technologies : "" ,
279- interests : "" ,
280- cv : "" ,
281- } ) ;
282-
283- if ( faculty ) {
284- row . getCell ( "facultyName" ) . value = faculty . name ;
285- row . getCell ( "facultyModule" ) . value = faculty . module ;
286- }
287-
288- if ( studyYears ) {
289- studyYears . forEach ( ( studyYear , i ) => {
290- row . getCell ( `studyYearsType${ i } ` ) . value = studyYear . studyType ;
291- row . getCell ( `studyYearsDuration${ i } ` ) . value = studyYear . studyYear ;
292- } ) ;
293- }
294-
295- if ( workExperiences ) {
296- workExperiences . forEach ( ( item , i ) => {
297- row . getCell ( `workExperiencesCompany${ i } ` ) . value = item . company ;
298- row . getCell ( `workExperiencesPosition${ i } ` ) . value = item . position ;
299- row . getCell ( `workExperiencesDuration${ i } ` ) . value = $fDur ( item ) ;
300- } ) ;
301- }
261+ for ( const entry of scannedUsers ) {
262+ const { user } = entry ;
263+ const resume = resumeById . get ( user . resumeId ?? - 1 ) ?? null ;
302264
303- if ( projects ) {
304- projects . forEach ( ( item , i ) => {
305- row . getCell ( `projectsProject ${ i } ` ) . value = item . project ;
306- row . getCell ( `projectsPosition ${ i } `) . value = item . position ;
307- row . getCell ( `projectsDuration ${ i } `) . value = $fDur ( item ) ;
265+ if ( ! resume ) {
266+ const row = worksheet . addRow ( {
267+ name : ` ${ user ?. firstName } ${ user ?. lastName } ` ,
268+ phone : ` ${ user ?. phone } `,
269+ email : ` ${ user ?. email } `,
308270 } ) ;
309- }
310-
311- if ( volunteerExperiences ) {
312- volunteerExperiences . forEach ( ( item , i ) => {
313- row . getCell ( `volunteerExperiencesOrganisation${ i } ` ) . value = item . organisation ;
314- row . getCell ( `volunteerExperiencesPosition${ i } ` ) . value = item . position ;
315- row . getCell ( `volunteerExperiencesDuration${ i } ` ) . value = $fDur ( item ) ;
271+ } else {
272+ const {
273+ user : _user ,
274+ volunteerExperiences,
275+ faculty,
276+ projects,
277+ workExperiences,
278+ technologies,
279+ studyYears,
280+ interests,
281+ city,
282+ cv,
283+ } = resume ;
284+ const user = _user ;
285+
286+ const row = worksheet . addRow ( {
287+ name : `${ user ?. firstName } ${ user ?. lastName } ` ,
288+ city : `${ city } ` ,
289+ phone : `${ user ?. phone } ` ,
290+ email : `${ user ?. email } ` ,
291+ facultyName : "" ,
292+ facultyModule : "" ,
293+ ...Object . fromEntries (
294+ Array . from ( { length : MAX_STUDY_YEARS } , ( _ , i ) => [
295+ [ `studyYearsType${ i } ` , "" ] ,
296+ [ `studyYearsDuration${ i } ` , "" ] ,
297+ ] as const ) . flat ( ) ,
298+ ) ,
299+ ...Object . fromEntries (
300+ Array . from ( { length : MAX_WORK_EXPERIENCES } , ( _ , i ) => [
301+ [ `workExperiencesCompany${ i } ` , "" ] ,
302+ [ `workExperiencesPosition${ i } ` , "" ] ,
303+ [ `workExperiencesDuration${ i } ` , "" ] ,
304+ ] as const ) . flat ( ) ,
305+ ) ,
306+ ...Object . fromEntries (
307+ Array . from ( { length : MAX_PROJECTS } , ( _ , i ) => [
308+ [ `projectsProject${ i } ` , "" ] ,
309+ [ `projectsPosition${ i } ` , "" ] ,
310+ [ `projectsDuration${ i } ` , "" ] ,
311+ ] as const ) . flat ( ) ,
312+ ) ,
313+ ...Object . fromEntries (
314+ Array . from ( { length : MAX_VOLUNTEER_EXPERIENCES } , ( _ , i ) => [
315+ [ `volunteerExperiencesOrganisation${ i } ` , "" ] ,
316+ [ `volunteerExperiencesPosition${ i } ` , "" ] ,
317+ [ `volunteerExperiencesDuration${ i } ` , "" ] ,
318+ ] as const ) . flat ( ) ,
319+ ) ,
320+ technologies : "" ,
321+ interests : "" ,
322+ cv : "" ,
316323 } ) ;
317- }
318-
319- if ( technologies ) {
320- row . getCell ( "technologies" ) . value = technologies . map ( ( x ) => x . name ) . join ( ", " ) ;
321- }
322-
323- if ( interests ) {
324- row . getCell ( "interests" ) . value = interests . map ( ( x ) => x . name ) . join ( ", " ) ;
325- }
326324
327- if ( cv ) {
328- const url = `${ process . env . BASE_URL || "https://jobfair.fer.unizg.hr/api" } /file/${ cv . uid } ` ;
329- row . getCell ( "cv" ) . value = {
330- text : url ,
331- hyperlink : url ,
332- } ;
325+ if ( faculty ) {
326+ row . getCell ( "facultyName" ) . value = faculty . name ;
327+ row . getCell ( "facultyModule" ) . value = faculty . module ;
328+ }
329+
330+ if ( studyYears ) {
331+ studyYears . forEach ( ( studyYear , i ) => {
332+ row . getCell ( `studyYearsType${ i } ` ) . value = studyYear . studyType ;
333+ row . getCell ( `studyYearsDuration${ i } ` ) . value = studyYear . studyYear ;
334+ } ) ;
335+ }
336+
337+ if ( workExperiences ) {
338+ workExperiences . forEach ( ( item , i ) => {
339+ row . getCell ( `workExperiencesCompany${ i } ` ) . value = item . company ;
340+ row . getCell ( `workExperiencesPosition${ i } ` ) . value = item . position ;
341+ row . getCell ( `workExperiencesDuration${ i } ` ) . value = $fDur ( item ) ;
342+ } ) ;
343+ }
344+
345+ if ( projects ) {
346+ projects . forEach ( ( item , i ) => {
347+ row . getCell ( `projectsProject${ i } ` ) . value = item . project ;
348+ row . getCell ( `projectsPosition${ i } ` ) . value = item . position ;
349+ row . getCell ( `projectsDuration${ i } ` ) . value = $fDur ( item ) ;
350+ } ) ;
351+ }
352+
353+ if ( volunteerExperiences ) {
354+ volunteerExperiences . forEach ( ( item , i ) => {
355+ row . getCell ( `volunteerExperiencesOrganisation${ i } ` ) . value = item . organisation ;
356+ row . getCell ( `volunteerExperiencesPosition${ i } ` ) . value = item . position ;
357+ row . getCell ( `volunteerExperiencesDuration${ i } ` ) . value = $fDur ( item ) ;
358+ } ) ;
359+ }
360+
361+ if ( technologies ) {
362+ row . getCell ( "technologies" ) . value = technologies . map ( ( x ) => x . name ) . join ( ", " ) ;
363+ }
364+
365+ if ( interests ) {
366+ row . getCell ( "interests" ) . value = interests . map ( ( x ) => x . name ) . join ( ", " ) ;
367+ }
368+
369+ if ( cv ) {
370+ const url = `${ process . env . BASE_URL || "https://jobfair.fer.unizg.hr/api" } /file/${ cv . uid } ` ;
371+ row . getCell ( "cv" ) . value = {
372+ text : url ,
373+ hyperlink : url ,
374+ } ;
375+ }
333376 }
334377 }
335378 } ;
336379
337380 // if (canViewAll) {
338381 // addResumePage(ResumeFilters.All, allResumes);
339382 // }
340- addResumePage ( ResumeFilters . Scanned , scannedResumes . map ( ( x ) => x . resume ) ) ;
341- addResumePage ( ResumeFilters . Favourites , favouriteResumes . map ( ( x ) => x . resume ) ) ;
383+ addResumePage ( ResumeFilters . Scanned , scannedUsersWithResumes ) ;
384+ // addResumePage(ResumeFilters.Favourites, favouriteResumes.map((x) => x.resume));
342385
343386 res
344387 . header ( "content-type" , "application/vnd.ms-excel" )
0 commit comments