diff --git a/api/__tests__/mock/address.ts b/api/__tests__/mock/address.ts index 71cc0d86..3936efd3 100644 --- a/api/__tests__/mock/address.ts +++ b/api/__tests__/mock/address.ts @@ -1,6 +1,7 @@ import { prisma } from "./prisma"; export async function initialiseAddress() { + // addresses for tests const address1 = { street: "Wallaby Way", number: 42, @@ -37,7 +38,35 @@ export async function initialiseAddress() { longitude: 3.71847, }; + // addresses for demo + const deBrug = { + street: "Sint-Pietersnieuwstraat", + number: 45, + city: "Ghent", + zip_code: 9000, + latitude: 51.0457, + longitude: 3.72697, + }; + + const dunant = { + street: "Henri Dunantlaan", + number: 2, + city: "Ghent", + zip_code: 9000, + latitude: 50.75342, + longitude: 5.09142, + }; + + const sterre = { + street: "Krijgslaan 281", + number: 281, + city: "Ghent", + zip_code: 9000, + latitude: 51.02776, + longitude: 3.71847, + }; + await prisma.address.createMany({ - data: [address1, address2, address3, address4], + data: [address1, address2, address3, address4, deBrug, dunant, sterre], }); } diff --git a/api/__tests__/mock/building.ts b/api/__tests__/mock/building.ts index 115a221d..6dea5cbb 100644 --- a/api/__tests__/mock/building.ts +++ b/api/__tests__/mock/building.ts @@ -1,5 +1,11 @@ import { prisma } from "./prisma"; -import { image, manual } from "./file"; +import { + image, + manual, + manualDeBrug, + manualDunant, + manualSterre, +} from "./file"; export async function initialiseBuilding() { const building1 = { @@ -42,8 +48,43 @@ export async function initialiseBuilding() { hash: "klmno", }; + // buildings for demo + const deBrug = { + name: "Resto De Brug", + ivago_id: "ivago-de-brug", + description: "Resto De Brug van Universiteit Gent", + expected_time: 100, + address_id: 5, + manual_id: 3, + syndicus_id: 3, + hash: "visitor-de-brug", + deleted: false, + }; + + const dunant = { + name: "Resto Dunant", + ivago_id: "ivago-dunant", + description: "Resto Dunant van Universiteit Gent", + expected_time: 200, + address_id: 6, + manual_id: 4, + syndicus_id: 3, + hash: "visitor-dunant", + }; + + const sterre = { + name: "Resto Sterre", + ivago_id: "ivago-sterre", + description: "Resto Sterre van Universiteit Gent", + expected_time: 300, + address_id: 7, + manual_id: 5, + syndicus_id: 3, + hash: "visitor-sterre", + }; + await prisma.building.createMany({ - data: [building1, building2, building3], + data: [building1, building2, building3, deBrug, dunant, sterre], }); } diff --git a/api/__tests__/mock/file.ts b/api/__tests__/mock/file.ts index fc8f0a58..1b107158 100644 --- a/api/__tests__/mock/file.ts +++ b/api/__tests__/mock/file.ts @@ -35,8 +35,39 @@ export const image = { updatedAt: new Date("1970-01-01T00:00:00Z"), }; +// manuals for demo +export const manualDeBrug = { + user_id: 7, + original_name: "manual_de_brug.pdf", + size_in_bytes: 18296, + mime: "application/pdf", + path: "manuals/manual_de_brug.pdf", + createdAt: new Date("2023-05-20T18:57:05Z"), + updatedAt: new Date("2023-05-20T18:57:05Z"), +}; + +export const manualDunant = { + user_id: 7, + original_name: "manual_dunant.pdf", + size_in_bytes: 17590, + mime: "application/pdf", + path: "manuals/manual_dunant.pdf", + createdAt: new Date("2023-05-20T18:57:05Z"), + updatedAt: new Date("2023-05-20T18:57:05Z"), +}; + +export const manualSterre = { + user_id: 7, + original_name: "manual_sterre.pdf", + size_in_bytes: 17872, + mime: "application/pdf", + path: "manuals/manual_sterre.pdf", + createdAt: new Date("2023-05-20T18:57:05Z"), + updatedAt: new Date("2023-05-20T18:57:05Z"), +}; + export async function initialiseFiles() { - const result = await prisma.file.createMany({ - data: [manual, testfile, image], + await prisma.file.createMany({ + data: [manual, image, manualDeBrug, manualDunant, manualSterre], }); } diff --git a/api/__tests__/mock/manuals/manual_de_brug.pdf b/api/__tests__/mock/manuals/manual_de_brug.pdf new file mode 100644 index 00000000..940f5009 Binary files /dev/null and b/api/__tests__/mock/manuals/manual_de_brug.pdf differ diff --git a/api/__tests__/mock/manuals/manual_dunant.pdf b/api/__tests__/mock/manuals/manual_dunant.pdf new file mode 100644 index 00000000..2979205d Binary files /dev/null and b/api/__tests__/mock/manuals/manual_dunant.pdf differ diff --git a/api/__tests__/mock/manuals/manual_sterre.pdf b/api/__tests__/mock/manuals/manual_sterre.pdf new file mode 100644 index 00000000..72c71d3d Binary files /dev/null and b/api/__tests__/mock/manuals/manual_sterre.pdf differ diff --git a/api/__tests__/mock/user.ts b/api/__tests__/mock/user.ts index 089fc6ea..1bd7310b 100644 --- a/api/__tests__/mock/user.ts +++ b/api/__tests__/mock/user.ts @@ -110,15 +110,15 @@ export async function initialiseUser() { const student_salt2 = crypto.randomBytes(32).toString("hex"); const student_hash2 = crypto .createHash("sha256") - .update("student" + student_salt) + .update("student" + student_salt2) .digest("hex"); - // create second student + // create second student await prisma.user.create({ data: { email: "student2@trottoir.be", - first_name: "Dirk", - last_name: "De Student", + first_name: "Denise", + last_name: "De Studente", date_added: timestamp, last_login: timestamp, phone: "0123456789", @@ -130,6 +130,52 @@ export async function initialiseUser() { address_id: 1, }, }); + + // omni user + const omniSalt = crypto.randomBytes(32).toString("hex"); + const omniHash = crypto + .createHash("sha256") + .update("omni" + omniSalt) + .digest("hex"); + await prisma.user.create({ + data: { + email: "omni@trottoir.be", + first_name: "Omni", + last_name: "User", + date_added: timestamp, + last_login: timestamp, + phone: "0123456789", + student: true, + super_student: true, + admin: true, + salt: omniSalt, + hash: omniHash, + address_id: 1, + }, + }); + + // UGent as example syndicus + const ugentSalt = crypto.randomBytes(32).toString("hex"); + const ugentHash = crypto + .createHash("sha256") + .update("ugent" + ugentSalt) + .digest("hex"); + await prisma.user.create({ + data: { + email: "ugent@trottoir.be", + first_name: "De Universiteit", + last_name: "Gent", + date_added: timestamp, + last_login: timestamp, + phone: "0123456789", + student: false, + super_student: false, + admin: false, + salt: ugentSalt, + hash: ugentHash, + address_id: 2, + }, + }); } export async function initialiseUserRegion() { @@ -157,7 +203,12 @@ export async function initialiseSyndicus() { user_id: 1, }; + // UGent syndicus for demo + const ugent = { + user_id: 7, + }; + await prisma.syndicus.createMany({ - data: [syndicus1, syndicus2], + data: [syndicus1, syndicus2, ugent], }); } diff --git a/api/fileserver/manuals/manual_de_brug.pdf b/api/fileserver/manuals/manual_de_brug.pdf new file mode 100644 index 00000000..940f5009 Binary files /dev/null and b/api/fileserver/manuals/manual_de_brug.pdf differ diff --git a/api/fileserver/manuals/manual_dunant.pdf b/api/fileserver/manuals/manual_dunant.pdf new file mode 100644 index 00000000..2979205d Binary files /dev/null and b/api/fileserver/manuals/manual_dunant.pdf differ diff --git a/api/fileserver/manuals/manual_sterre.pdf b/api/fileserver/manuals/manual_sterre.pdf new file mode 100644 index 00000000..72c71d3d Binary files /dev/null and b/api/fileserver/manuals/manual_sterre.pdf differ diff --git a/api/src/routes/file.ts b/api/src/routes/file.ts index 87b86a71..6bef8a48 100644 --- a/api/src/routes/file.ts +++ b/api/src/routes/file.ts @@ -8,6 +8,7 @@ import { APIError } from "../errors/api_error"; import { APIErrorCode } from "../errors/api_error_code"; import fs from "fs"; import { File } from "@selab-2/groep-1-orm"; +import path from "path"; export class FileRouting extends Routing { private storage = multer.diskStorage({ @@ -49,8 +50,13 @@ export class FileRouting extends Routing { }, }); + console.log(process.env.FILE_STORAGE_DIRECTORY); + console.log(path.resolve()); + return res.sendFile( - `${process.env.FILE_STORAGE_DIRECTORY}/${result.path}`, + `${path.resolve()}/${process.env.FILE_STORAGE_DIRECTORY}/${ + result.path + }`, ); } diff --git a/web/src/views/building/BuildingScreen.vue b/web/src/views/building/BuildingScreen.vue index fbb89b78..dc473825 100644 --- a/web/src/views/building/BuildingScreen.vue +++ b/web/src/views/building/BuildingScreen.vue @@ -262,6 +262,7 @@ import RemovedCard from "@/components/cards/RemovedCard.vue"; import router from "@/router"; import { ImgProxy } from "@/imgproxy"; import BuildingAnalyticCard from "@/components/cards/BuildingAnalyticCard.vue"; +import * as process from "process"; const showRemovePopup = ref(false);