diff --git a/Taskfile.yml b/Taskfile.yml index 63c36e5..190ee4c 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -151,6 +151,18 @@ tasks: requires: vars: [STUDENT_ID] + send-degree-with-subject-and-body: + desc: Call the send-file endpoint + cmds: + - 'echo -n ''{"file": "{{.FILE_BASE64}}", "messageSubject": "{{.SUBJECT}}", "messageBody": "{{.BODY}}"}'' | http -b POST localhost:8099/students/{{.STUDENT_ID}}/files/abiturzeugnis ''X-API-KEY: This_is_a_test_APIKEY_with_30_chars+'' | jq' + vars: + FILE_BASE64: + sh: 'cat assets/Zeugnis.pdf | {{if eq OS "darwin"}}base64{{else}}base64 -w 0{{end}}' + SUBJECT: "Ihr Abiturzeugnis" + BODY: Hallo {{"{{"}}student.givenname{{"}}"}} {{"{{"}}student.surname{{"}}"}},\n\nherzlichen Glückwunsch zum Abitur! Wir freuen uns, Ihnen mitteilen zu können, dass wie ihnen ihr Abiturzeugnis zusenden können.\n\nIhr offizielles Zeugnis liegt in Ihren Dokumenten und Dateien zur weiteren Verwendung bereit.\n\nMit freundlichen Grüßen\nIhr {{"{{"}}organization.displayName{{"}}"}} + requires: + vars: [STUDENT_ID] + audit-log: desc: Get the audit log for a student cmds: diff --git a/src/StudentsController.ts b/src/StudentsController.ts index 90a107f..c3d1fb9 100644 --- a/src/StudentsController.ts +++ b/src/StudentsController.ts @@ -533,20 +533,29 @@ export class StudentsController { return text; } - public async sendFile(student: Student, data: { file: string; title: string; filename: string; mimetype: string; tags?: string[] | undefined }): Promise { + public async sendFile( + student: Student, + data: { file: string; title: string; filename: string; mimetype: string; tags?: string[] | undefined; messageSubject?: string; messageBody?: string } + ): Promise { if (!student.correspondingRelationshipId) throw new ApplicationError("error.schoolModule.noRelationship", "The student has no relationship."); const relationship = await this.services.transportServices.relationships.getRelationship({ id: student.correspondingRelationshipId.toString() }); + const title = await this.fillTemplateStringWithStudentAndOrganizationData(student, data.title); const file = await this.services.transportServices.files.uploadOwnFile({ content: Buffer.from(data.file, "base64"), tags: data.tags, filename: data.filename, mimetype: data.mimetype, - title: data.title + title }); + const subject = data.messageSubject ? await this.fillTemplateStringWithStudentAndOrganizationData(student, data.messageSubject) : title; + const body = data.messageBody ? await this.fillTemplateStringWithStudentAndOrganizationData(student, data.messageBody) : undefined; + const request = await this.services.consumptionServices.outgoingRequests.create({ content: { + title: subject, + description: body, items: [ { "@type": "TransferFileOwnershipRequestItem", diff --git a/src/controllers/schemas.ts b/src/controllers/schemas.ts index 0e2ce72..fdd6780 100644 --- a/src/controllers/schemas.ts +++ b/src/controllers/schemas.ts @@ -44,7 +44,9 @@ export const sendFileRequestSchema = z.object({ title: z.string().min(5).max(255), filename: z.string().min(5).max(255), mimetype: z.string(), - tags: z.array(z.string()).optional() + tags: z.array(z.string()).optional(), + messageSubject: z.string().min(1).max(64).optional(), + messageBody: z.string().min(1).max(2000).optional() }); export const sendAbiturzeugnisRequestSchema = z.object({ @@ -52,5 +54,7 @@ export const sendAbiturzeugnisRequestSchema = z.object({ title: z.string().min(5).max(255).optional(), filename: z.string().min(5).max(255).optional(), mimetype: z.string().optional(), - tags: z.array(z.string()).optional() + tags: z.array(z.string()).optional(), + messageSubject: z.string().min(1).max(64).optional(), + messageBody: z.string().min(1).max(2000).optional() });