Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 11 additions & 2 deletions src/StudentsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SchoolFileDTO> {
public async sendFile(
student: Student,
data: { file: string; title: string; filename: string; mimetype: string; tags?: string[] | undefined; messageSubject?: string; messageBody?: string }
): Promise<SchoolFileDTO> {
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",
Expand Down
8 changes: 6 additions & 2 deletions src/controllers/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ 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({
file: z.string().base64(),
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()
});