The backend for the TransDB site, responsible for handling all PI traffic.
- TypeScript Type-safe JavaScript superset.
- OvernightJS A TypeScript express.js wrapper for decorator support and eased type safety.
- Class Validator TypeScript compatible validation.
All non-configuration files are within the ./src parent directory.
controllersApi routes and endpoints. Each Controller is responsible for one route, and can contain multiple Endpoints.middlewareexpress.js middleware. Middleware modifies or validates incoming requests.modelsTyped classes and interfaces used for compile-time and run-time type validation.servicesES-modules handling the bulk of the backend logic.typesAdditional TypeScript types, and express type extensions.utilCollections of functions which can be used anywhere in the project.
config.service.tsInitializes, parses, and updates the backend configuration file.database.service.tsWraps database access in a type-safe manner.entry.service.tsHandles the creation, management, and deletion of entries.osm.serivce.tsOpenStreetMap Api interaction. Used to retrieve the GeoLocation of Entries.users.service.tsHandles the creation, management, and deletion of users.
Requirements: NodeJS 14.15.4 or higher, NPM, a running MongoDB server, with MongoDB Database Tools installed.
Warning! MongoDB Database Tools needs to be running on the same machine as NodeJS, not on MongoDB Server. If MongoDB Database Tools is not installed, database backups will fail!
- Download and extract latest release from releases.
- Run
npm install. - Run
npm start. - On first start the application will exit. A
config.jsonfile will now be in the root directory. - Fill out all config fields.
- Open your MongoDB, create a collection named "geodata" and import the data.json file in GeoDbJson.zip from Tool Downloads into the collection as json.
- Run
npm startagain.
Use Tab-Stops instead of spaces. Make sure to configure your editor.
Do not remove the indents from empty lines. This is not the default behaviour of most code-editors, so be sure to change it.
Do not use Hanging indents.
Leave two empty lines between top-level scopes (functions, classes and types).
Add an empty new-line to the end of a file.
Leave a space within curly brackets. eg. import { IRequest } from "express"
Leave a space between control statements and brackets. eg. if (count >= 5) { ... }
Do not leave a space between a function call and it's brackets. eg. filterEntry(newEntry);
camelCase files, functions, and variables.
PascalCase Classes, Modules, and Decorators.
Use es6 module import export syntax.
Use async await instead of call-backs where possible.
JSDoc comment exported functions. Comments should be in English. Capitalize Names. Do not place a full stop on single-line comments.
Prefix routes which require a login with authorized.
Prefix routes which require admin credentials with admin.
Using I and E as prefixes to indicate interfaces and enums is optional.
Avoid explicit any and unkown where possible. Unknown is sometimes required when interacting with the Database, but should not be used outside of the Database Service.
Try using generics and asserts to avoid the use of unknown. The filter functions in util/filter can help with this for entries and users.
Do not use Request and Response from express.js. Use IRequest and IResponse instead. See controllers for usage examples.
Never try to avoid a type Error with an explicit any annotation.
Make sure to annotate internal-only types with never. Omitting them is not sufficient, as typescript still allows this for interfaces. See models/response for usage examples.
Do not use .js files.
Warning You need to add .js endings when importing non-package modules. TypeScript does not throw an error if this is omitted, but a runtime error will be thrown.