Skip to content

Commit

Permalink
Release v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanja-4732 committed Aug 5, 2019
2 parents 128d4f1 + 207c4a5 commit 235476a
Show file tree
Hide file tree
Showing 20 changed files with 2,990 additions and 3,370 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ Thumbs.db
# ...except for the default one and the example one
!/src/environments/environment.ts
!/src/environments/environment.example.ts
!/src/environments/environment.d.ts

# Avoid server-side configuration files...
/backend/environments/*

# ...except for the default one and the example one
!/backend/environments/environment.d.ts
!/backend/environments/example.ts

# Development keys
/backend/keys/*
!/backend/keys/keys-go-here
4 changes: 2 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"version": "2.0.0",
"tasks": [
{
"label": "Watch TypeScript (backend)",
"label": "Watch and compile TypeScript (backend)",
"type": "typescript",
"tsconfig": "backend/tsconfig.json",
"option": "watch",
"options": { "shell": { "executable": "powershell.exe" } },
// "options": { "shell": { "executable": "powershell.exe" } },
"problemMatcher": ["$tsc-watch"],
"group": "build"
}
Expand Down
20 changes: 20 additions & 0 deletions backend/controllers/thingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,24 @@ export class ThingController {
message: "Thing deleted"
});
}

static async getByCode(req: Request, res: Response): Promise<void> {
// Check for authorization
AccountController.authOrError(res, InventoryUserAccessRightsEnum.READ);

// Get entityManager
const mgr: EntityManager = getManager();

// Find the thing in the db
let theThing: Thing;
try {
theThing = await mgr.findOneOrFail(Thing, {
where: { code: req.params.code,
// FIXME this probably doesn't work
inventory: res.locals.inventory }
});
} catch (error) {
res.status(404).json({ error: "The code couldn't be resolved." });
}
}
}
1 change: 1 addition & 0 deletions backend/keys/keys-go-here
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
They really do.
6 changes: 6 additions & 0 deletions backend/models/thingModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export class Thing {
@JoinTable()
categories: Category[];

@Column({ nullable: true })
/**
* The barcode of the thing
*/
code: string;

// TODO fix this #3
@OneToMany(() => Stock, stock => stock.thing)
stocks: Stock[];
Expand Down
4 changes: 3 additions & 1 deletion backend/routes/api/v1/thingsRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ thingsRoutes.get("/", ThingController.getAllThings);
// Create new thing
thingsRoutes.post("/", ThingController.createNewThing);

// Resolve barcode
thingsRoutes.get("/code/:code", ThingController.getByCode);

// Set the thingNo
thingsRoutes.use("/:thingNo", ThingController.setThingInDotLocals);

Expand All @@ -22,7 +25,6 @@ thingsRoutes.use("/:thingNo/stocks", stocksRoutes);
// Return one thing
thingsRoutes.get("/:thingNo", ThingController.getThing);


// Replace thing
thingsRoutes.put("/:thingNo", ThingController.replaceThing);

Expand Down
55 changes: 49 additions & 6 deletions backend/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

import { log } from "util";
import "source-map-support/register";
import { createServer } from "https";
import { readFileSync } from "fs";
import * as express from "express";

// Set port
const PORT: string = process.env.PORT || 420 + "";
// Set the ports
const PORT: string = process.env.PORT || 443 + "";
const INSECURE_PORT: string = process.env.INSECURE_PORT || 80 + "";

// Set EDM_WORKING_DIRECTORY (working directory of the server)
process.env.EDM_WORKING_DIRECTORY = __dirname;
Expand All @@ -18,8 +22,47 @@ log("Starting server in " + process.env.EDM_WORKING_DIRECTORY);

// Import the app
import app from "./app";
import { resolve } from "path";

// Log listening
app.listen(PORT, () => {
log("Server listening on port " + PORT);
});
// Check for development mode
switch (process.env.EDM_SSL) {
case "yes":
const PUBLIC_KEY: string | Buffer =
process.env.EDM_PUBLIC_KEY_VAL ||
readFileSync(process.env.EDM_PUBLIC_KEY);

// Certificate
const privateKey: string =
process.env.EDM_PK_VAL || readFileSync(process.env.EDM_PK, "utf8");
const certificate: string =
process.env.EDM_CERT_VAL || readFileSync(process.env.EDM_CERT, "utf8");
const ca: string =
process.env.EDM_CA_VAL || readFileSync(process.env.EDM_CA, "utf8");

const credentials = {
key: privateKey,
cert: certificate,
ca
};

// Create and start the https app server
createServer(credentials, app).listen(PORT, () => {
log("HTTPS app server listening on port " + PORT);
});

// Create and start the http redirect server
express()
.use("*", (req, res) => {
res.redirect("https://" + req.headers.host + req.url);
})
.listen(INSECURE_PORT, () => {
log("HTTP redirect server listening on port " + INSECURE_PORT);
});
break;

default:
// Don't use SSL
app.listen(process.env.PORT || 80 + "", () => {
log("HTTP app server listening on port " + process.env.PORT || 80 + "");
});
}
Loading

0 comments on commit 235476a

Please sign in to comment.