Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Add initial demo data #507

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
31 changes: 30 additions & 1 deletion api/__tests__/mock/address.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { prisma } from "./prisma";

export async function initialiseAddress() {
// addresses for tests
const address1 = {
street: "Wallaby Way",
number: 42,
Expand Down Expand Up @@ -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],
});
}
45 changes: 43 additions & 2 deletions api/__tests__/mock/building.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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],
});
}

Expand Down
35 changes: 33 additions & 2 deletions api/__tests__/mock/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
});
}
Binary file added api/__tests__/mock/manuals/manual_de_brug.pdf
Binary file not shown.
Binary file added api/__tests__/mock/manuals/manual_dunant.pdf
Binary file not shown.
Binary file added api/__tests__/mock/manuals/manual_sterre.pdf
Binary file not shown.
61 changes: 56 additions & 5 deletions api/__tests__/mock/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]",
first_name: "Dirk",
last_name: "De Student",
first_name: "Denise",
last_name: "De Studente",
date_added: timestamp,
last_login: timestamp,
phone: "0123456789",
Expand All @@ -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: "[email protected]",
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: "[email protected]",
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() {
Expand Down Expand Up @@ -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],
});
}
Binary file added api/fileserver/manuals/manual_de_brug.pdf
Binary file not shown.
Binary file added api/fileserver/manuals/manual_dunant.pdf
Binary file not shown.
Binary file added api/fileserver/manuals/manual_sterre.pdf
Binary file not shown.
8 changes: 7 additions & 1 deletion api/src/routes/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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
}`,
);
}

Expand Down
1 change: 1 addition & 0 deletions web/src/views/building/BuildingScreen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down