Skip to content

Commit 6fc4120

Browse files
Merge pull request #488 from codeanker/development
next
2 parents 0b342cb + fe229f3 commit 6fc4120

4 files changed

Lines changed: 55 additions & 49 deletions

File tree

apps/api/src/routes/exports/photos.archive.ts

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import archiver from 'archiver'
66
import type { Context } from 'hono'
77
import { stream } from 'hono/streaming'
88
import mime from 'mime'
9-
import { Readable } from 'node:stream'
109
import { z } from 'zod'
1110
import prisma from '../../prisma.js'
1211
import { openFileStream } from '../../services/file/helpers/getFileUrl.js'
@@ -119,54 +118,67 @@ export async function veranstaltungPhotoArchive(ctx: Context<{ Variables: Author
119118

120119
const zip = archiver('zip')
121120

122-
zip.on('warning', function (err) {
123-
if (err.code === 'ENOENT') {
124-
console.warn(err)
125-
} else {
126-
throw err
127-
}
128-
})
129-
130-
zip.on('error', function (err) {
131-
throw err
132-
})
133-
134121
ctx.status(201)
135122
ctx.header('Content-Type', 'application/zip')
136123
ctx.header('Content-Disposition', `attachment; filename="${mode === 'flat' ? 'FotosForAutomation' : 'Fotos'}.zip"`)
137124

138125
zip.append(`Gesamtzahl Fotos: ${anmeldungen.length}`, { name: `${baseDirectory}/README.txt` })
139126

140-
for (const { person, unterveranstaltung } of anmeldungen) {
141-
if (!person.photo) {
142-
continue
143-
}
127+
return stream(ctx, async (s) => {
128+
zip.on('data', (chunk) => {
129+
/* eslint-disable @typescript-eslint/no-floating-promises */
130+
s.write(chunk)
131+
})
144132

145-
const stream = await openFileStream(person.photo)
133+
for (const { person, unterveranstaltung } of anmeldungen) {
134+
if (!person.photo) {
135+
continue
136+
}
146137

147-
const directory = `${unterveranstaltung.veranstaltung.name}/${unterveranstaltung.gliederung.name}`
148-
const basename = mode === 'group' ? `${person.firstname} ${person.lastname}` : person.id
149-
const extension = mime.getExtension(person.photo.mimetype ?? 'text/plain')
138+
const stream = await openFileStream(person.photo)
150139

151-
zip.append(stream, {
152-
name:
153-
mode === 'group'
154-
? `${baseDirectory}/${directory}/${basename}.${extension}`
155-
: `Fotos/${person.photo.id}.${extension}`,
156-
date: person.photo.createdAt,
157-
})
158-
}
140+
stream.on('end', () => {
141+
stream.destroy()
142+
})
159143

160-
if (mode === 'flat') {
161-
const buffer = buildSheet(anmeldungen, account.person)
162-
zip.append(buffer, {
163-
name: 'Datenzusammenführung.xlsx',
164-
})
165-
}
144+
const directory = `${unterveranstaltung.veranstaltung.name}/${unterveranstaltung.gliederung.name}`
145+
const basename = mode === 'group' ? `${person.firstname} ${person.lastname}` : person.id
146+
const extension = mime.getExtension(person.photo.mimetype ?? 'text/plain')
147+
148+
zip.append(stream, {
149+
name:
150+
mode === 'group'
151+
? `${baseDirectory}/${directory}/${basename}.${extension}`
152+
: `Fotos/${person.photo.id}.${extension}`,
153+
date: person.photo.createdAt,
154+
})
155+
}
166156

167-
await zip.finalize()
157+
if (mode === 'flat') {
158+
const buffer = buildSheet(anmeldungen, account.person)
159+
zip.append(buffer, {
160+
name: 'Datenzusammenführung.xlsx',
161+
})
162+
}
168163

169-
return stream(ctx, async (s) => {
170-
await s.pipe(Readable.toWeb(zip))
164+
/* eslint-disable @typescript-eslint/no-floating-promises */
165+
zip.finalize()
166+
167+
await new Promise<void>((resolve, reject) => {
168+
zip.on('warning', function (err) {
169+
if (err.code === 'ENOENT') {
170+
console.warn(err)
171+
} else {
172+
reject(err)
173+
}
174+
})
175+
176+
zip.once('end', () => {
177+
resolve()
178+
})
179+
zip.once('error', (err) => {
180+
reject(err)
181+
})
182+
})
171183
})
172184
}

apps/api/src/routes/exports/teilnehmendenliste.sheet.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export async function veranstaltungTeilnehmendenliste(ctx: Context<{ Variables:
2424
unterveranstaltung: {
2525
gliederungId: gliederung?.id,
2626
},
27-
status: 'BESTAETIGT',
2827
},
2928
select: {
3029
id: true,
@@ -114,8 +113,7 @@ export async function veranstaltungTeilnehmendenliste(ctx: Context<{ Variables:
114113
'#': anmeldung.id,
115114

116115
Veranstaltung: anmeldung.unterveranstaltung.veranstaltung.name,
117-
Ausschreibung:
118-
anmeldung.unterveranstaltung.beschreibung?.substring(0, 30) || anmeldung.unterveranstaltung.gliederung.name,
116+
Ausschreibung: anmeldung.unterveranstaltung.gliederung.name,
119117
'Art der Ausschreibung': anmeldung.unterveranstaltung.type,
120118

121119
Status: AnmeldungStatusMapping[anmeldung.status].human,

apps/api/src/services/unterveranstaltung/unterveranstaltungList.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,7 @@ export const unterveranstaltungListProcedure = defineProtectedQueryProcedure({
102102
},
103103
_count: {
104104
select: {
105-
Anmeldung: {
106-
where: {
107-
status: 'BESTAETIGT',
108-
},
109-
},
105+
Anmeldung: true,
110106
},
111107
},
112108
meldebeginn: true,

apps/frontend/src/views/Anmeldung/AnmeldungFormGeneral.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import { FaceFrownIcon } from '@heroicons/vue/24/outline'
33
import { useAsyncState } from '@vueuse/core'
4-
import { defineProps, ref, watch, withDefaults } from 'vue'
4+
import { ref, watch } from 'vue'
55
import { useRouter } from 'vue-router'
66
77
import { apiClient } from '@/api'
@@ -29,11 +29,11 @@ const { state: customFields, execute: loadCustomFields } = useAsyncState(async (
2929
if (!unterveranstaltung) {
3030
return undefined
3131
}
32-
// TODO: Nur Felder für die Position anzeigen
32+
3333
return apiClient.customFields.list.query({
3434
entity: 'unterveranstaltung',
3535
entityId: unterveranstaltung.value.id,
36-
position: 'PUBLIC_ANMELDUNG',
36+
position: props.isPublic ? 'PUBLIC_ANMELDUNG' : 'INTERN_ANMELDUNG',
3737
})
3838
}, [])
3939

0 commit comments

Comments
 (0)