Compare commits
3 Commits
74f19b669b
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 36c1fe805e | |||
| 96da68e18e | |||
| 59401b3c85 |
@@ -1,67 +1,153 @@
|
||||
# AdAstra_API
|
||||
# AdAstra API
|
||||
|
||||
API pour l'application Ad Astra
|
||||
Backend of the AdAstra platform — an Express REST API serving four feature domains: CMS, e-commerce, skydive club management, and Hero Wars guild analytics.
|
||||
|
||||
## Tech stack
|
||||
|
||||
| Layer | Choice |
|
||||
|---|---|
|
||||
| Runtime | Node.js `^16.20.2 \|\| ^18.19.1 \|\| ^20.11.1` |
|
||||
| Framework | Express 4 |
|
||||
| MySQL ORM | Sequelize 6 |
|
||||
| MongoDB ODM | Mongoose 6 |
|
||||
| Auth | Passport (local strategy) + JWT (express-jwt / jsonwebtoken) |
|
||||
| Validation | express-validator |
|
||||
| Security | Helmet, express-rate-limit, CORS |
|
||||
| Tests | Jest + Supertest, Postman/Newman |
|
||||
| Dev server | Nodemon |
|
||||
|
||||
## Related repository
|
||||
|
||||
The frontend lives in [`adastra_app`](../adastra_app) — an Angular 21 standalone app. It calls this API exclusively through relative paths prepended with `environment.apiBaseUrl`.
|
||||
|
||||
## Getting started
|
||||
|
||||
**Installation rapide**
|
||||
```bash
|
||||
# Initialisation (applique les migrations, seed roles → création admin interactive → seed articles)
|
||||
# La commande suivante applique d'abord les migrations nécessaires.
|
||||
npm install
|
||||
|
||||
# Copy the example env file for your environment
|
||||
cp config/env/.env.example config/env/.env.local
|
||||
# Edit .env.local: MYSQL_DBNAME, MYSQL_DBUSER, MYSQL_DBPASS, SECRET, …
|
||||
|
||||
# Initialize the database (migrate + seed roles + create admin user + seed articles)
|
||||
npm run setup:api
|
||||
|
||||
# Start the dev server
|
||||
npm run local
|
||||
```
|
||||
|
||||
**Installation manuelle**
|
||||
The server listens on `SERVER_PORT` (default **3200**).
|
||||
|
||||
## Commands
|
||||
|
||||
| Command | Description |
|
||||
|---|---|
|
||||
| `npm start` | Production server (`APP_ENV=production`) |
|
||||
| `npm run dev` | Development server, uses `.env.development` |
|
||||
| `npm run local` | Local server with Nodemon, uses `.env.local` |
|
||||
| `npm test` | Jest unit + integration tests |
|
||||
| `npm run test:postman` | Newman / Postman collection run |
|
||||
| `npm run create:user` | Interactive admin user creation script |
|
||||
| `npm run stop` | Kill the process on port 3200 |
|
||||
|
||||
## Environment
|
||||
|
||||
Environment files live in `config/env/` and are loaded by `dotenv` at startup based on `APP_ENV`:
|
||||
|
||||
| File | Used when |
|
||||
|---|---|
|
||||
| `.env.local` | `npm run local` |
|
||||
| `.env.development` | `npm run dev` |
|
||||
| `.env.production` | `npm start` |
|
||||
|
||||
Copy `.env.example` to create a new environment file. Key variables:
|
||||
|
||||
```
|
||||
SERVER_PORT=3200
|
||||
SECRET= # JWT signing secret
|
||||
SESSION_SECRET=
|
||||
MYSQL_DBNAME=
|
||||
MYSQL_DBUSER=
|
||||
MYSQL_DBPASS=
|
||||
MONGODB_URI=
|
||||
SENDGRID_API_KEY= # optional — email sending
|
||||
SKYDIVERID_API_URL= # optional — skydiver ID external API
|
||||
# TRUST_PROXY=1 # uncomment when behind a reverse proxy
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
### Route domains
|
||||
|
||||
All routes are mounted under `/api` and split into four domains:
|
||||
|
||||
| Domain | Prefix | Resources |
|
||||
|---|---|---|
|
||||
| CMS | `/api/cms` | users, profiles, articles, comments, tags |
|
||||
| E-commerce | `/api/ecommerce` | products |
|
||||
| Skydive | `/api/skydive` | aeronefs, canopies, dropzones, jumps, pages, QCM, applications |
|
||||
| Hero Wars | `/api/herowars` | clans, members |
|
||||
|
||||
### Middleware pipeline
|
||||
|
||||
Requests flow through:
|
||||
|
||||
1. **Helmet** — security headers
|
||||
2. **CORS** — origin whitelist from `ALLOWED_ORIGINS`
|
||||
3. **Rate limiter** — `express-rate-limit`
|
||||
4. **Body parser** — JSON + URL-encoded
|
||||
5. **Passport** — initializes local + header-API-key strategies
|
||||
6. **Route handlers** — validators → `auth` middleware → controller → `asyncHandler`
|
||||
7. **Error handlers** — 404 catcher, log handler, final error handler
|
||||
|
||||
### Auth
|
||||
|
||||
- **Session-less JWT**: tokens are signed with `SECRET` and attached by the client as `Authorization: Token <jwt>`.
|
||||
- `auth.js` middleware verifies the token via `express-jwt` and populates `req.auth`.
|
||||
- Password storage: PBKDF2-SHA512 with a random 16-byte salt (no bcrypt dependency on the auth path).
|
||||
|
||||
### Databases
|
||||
|
||||
- **MySQL** (Sequelize): users, roles, skydive entities, e-commerce, CMS content.
|
||||
- **MongoDB** (Mongoose): Hero Wars guild/clan data and analytics snapshots.
|
||||
|
||||
## Database — migrations & seeders
|
||||
|
||||
**One-command setup:**
|
||||
```bash
|
||||
npm run setup:api
|
||||
# Runs: db:migrate → seed roles → create:user → seed articles
|
||||
```
|
||||
|
||||
**Manual steps:**
|
||||
```bash
|
||||
# Appliquer les migrations
|
||||
npx sequelize-cli db:migrate
|
||||
|
||||
# Exécuter le seeder des articles
|
||||
npx sequelize-cli db:seed --seed 20251126-add-roles.js
|
||||
|
||||
# Créer un utilisateur Admin
|
||||
npm run create:user
|
||||
|
||||
# Exécuter le seeder des articles
|
||||
npx sequelize-cli db:seed --seed 20251127-add-articles.js
|
||||
```
|
||||
|
||||
**Migration**
|
||||
**Migration helpers:**
|
||||
```bash
|
||||
# Appliquer les migrations
|
||||
npx sequelize-cli db:migrate
|
||||
|
||||
# Voir le statut des migrations
|
||||
npx sequelize-cli db:migrate:status
|
||||
|
||||
# Annuler les migrations
|
||||
npx sequelize-cli db:migrate:undo:all
|
||||
```
|
||||
|
||||
**Seeder**
|
||||
**Seeder helpers:**
|
||||
```bash
|
||||
# Exécuter tous les seeders
|
||||
npx sequelize-cli db:seed:all
|
||||
|
||||
# Exécuter un seeder spécifique
|
||||
npx sequelize-cli db:seed --seed 20251127-add-articles.js
|
||||
|
||||
# Annuler tous les seeders
|
||||
npx sequelize-cli db:seed:undo:all
|
||||
|
||||
# Annuler un seeder spécifique
|
||||
npx sequelize-cli db:seed:undo --seed 20251127-add-articles.js
|
||||
```
|
||||
|
||||
**Start 'local' API server**
|
||||
```bash
|
||||
# Appliquer les migrations
|
||||
npm run local
|
||||
## Documentation
|
||||
|
||||
# Exécuter le seeder des articles
|
||||
npx sequelize-cli db:seed --seed 20251126-add-roles.js
|
||||
Extended references are in [`docs/`](docs/):
|
||||
|
||||
# Créer un utilisateur Admin
|
||||
npm run create:user
|
||||
|
||||
# Exécuter le seeder des articles
|
||||
npx sequelize-cli db:seed --seed 20251127-add-articles.js
|
||||
```
|
||||
| File | Content |
|
||||
|---|---|
|
||||
| [DEPLOYMENT.md](docs/DEPLOYMENT.md) | Full VPS production deployment guide (Apache, PM2, SSL) |
|
||||
| [ENVIRONMENT_VARIABLES.md](docs/ENVIRONMENT_VARIABLES.md) | All env variables documented |
|
||||
| [SWAGGER_GUIDE.md](docs/SWAGGER_GUIDE.md) | API documentation via Swagger UI |
|
||||
| [GITEA_INSTALL.md](docs/GITEA_INSTALL.md) | Self-hosted Gitea on Debian 11 + ISPConfig |
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
# Upgrade Express from v4 to v5 and remove redundant middleware
|
||||
|
||||
* Status: accepted
|
||||
* Date: 2026-04-28
|
||||
|
||||
## Context and Problem Statement
|
||||
|
||||
The API ran on Express 4.18, with two additional middleware packages (`method-override`, `errorhandler`) and an `asyncHandler` wrapper used across all controllers to forward async errors to Express. Express 5 was released as stable in September 2024 and addresses the async error handling gap natively.
|
||||
|
||||
## Decision Drivers
|
||||
|
||||
* Express 5 propagates promise rejections in route handlers to error middleware automatically — the `asyncHandler` wrapper is redundant noise.
|
||||
* `method-override` allows clients to tunnel `PUT`/`DELETE` via `POST` using a `_method` parameter. The API is consumed exclusively by Angular's `HttpClient`, which sends correct HTTP verbs directly. The middleware has never been exercised.
|
||||
* `errorhandler` provides verbose error pages in development, but a custom `exceptions.handler.js` already handles error formatting for all environments.
|
||||
* Removing unused middleware reduces the attack surface and the number of dependencies to keep up to date.
|
||||
|
||||
## Considered Options
|
||||
|
||||
* Stay on Express 4, keep existing middleware
|
||||
* Upgrade to Express 5, keep `method-override` and `errorhandler` for safety
|
||||
* Upgrade to Express 5 and remove all three redundant pieces
|
||||
|
||||
## Decision Outcome
|
||||
|
||||
Chosen option: "upgrade to Express 5 and remove all three redundant pieces", because the migration has zero breaking changes for this codebase (no wildcard routes, no removed APIs in use) and each removed package was demonstrably unused or superseded.
|
||||
|
||||
Changes made:
|
||||
- `express` bumped to `^5` (installed 5.2.1)
|
||||
- `method-override` removed from `package.json` and `createApp.js`
|
||||
- `errorhandler` removed from `package.json` and `createApp.js`
|
||||
- `asyncHandler` wrapper removed from all 8 controllers and its middleware file deleted
|
||||
- Controller exports changed from `asyncHandler(async (req, res, next) => { ... })` to `async (req, res, next) => { ... }`
|
||||
|
||||
### Positive Consequences
|
||||
|
||||
* Unhandled async errors now reach the error handler without any wrapper — less boilerplate in every controller.
|
||||
* Two dependencies removed from the production bundle (`method-override`, `errorhandler`).
|
||||
* Codebase is on a maintained major version with long-term support.
|
||||
|
||||
### Negative Consequences
|
||||
|
||||
* Express 5 is a major version bump — future middleware additions must be verified for Express 5 compatibility before adoption.
|
||||
|
||||
## Pros and Cons of the Options
|
||||
|
||||
### Stay on Express 4
|
||||
|
||||
* Good, because no migration effort.
|
||||
* Bad, because the async error gap requires the `asyncHandler` wrapper indefinitely.
|
||||
* Bad, because `method-override` and `errorhandler` remain as unused surface area.
|
||||
|
||||
### Upgrade to Express 5, keep existing middleware
|
||||
|
||||
* Good, because conservative — no behavioural changes beyond async propagation.
|
||||
* Bad, because `method-override` and `errorhandler` are still dead weight.
|
||||
|
||||
### Upgrade to Express 5 and remove all three
|
||||
|
||||
* Good, because every removed package is one fewer dependency to audit and update.
|
||||
* Good, because controller code is simpler without the wrapper.
|
||||
* Bad, because a future Express 4-only middleware would need to be replaced — acceptable trade-off given the ecosystem has largely moved to v5.
|
||||
@@ -0,0 +1,60 @@
|
||||
# Extract user and application routes into a dedicated auth domain
|
||||
|
||||
* Status: accepted
|
||||
* Date: 2026-05-01
|
||||
|
||||
## Context and Problem Statement
|
||||
|
||||
User authentication/registration routes (`/api/cms/user`) were grouped under the CMS domain, and API key application routes (`/api/skydive/applications`) were grouped under the Skydive domain. Neither resource is domain-specific content: users and applications are identity and access management concerns shared across all domains.
|
||||
|
||||
## Decision Drivers
|
||||
|
||||
* The domain prefix should reflect what a resource *is*, not which feature first needed it.
|
||||
* `/api/cms/user` implies users are CMS content; `/api/skydive/applications` implies API keys are skydive data — both are misleading.
|
||||
* A dedicated `auth` domain makes the security boundary explicit and easier to apply targeted middleware (rate limiting, stricter CORS, etc.) in the future.
|
||||
|
||||
## Considered Options
|
||||
|
||||
* Keep routes in their current domains
|
||||
* Move only users out of CMS, leave applications in skydive
|
||||
* Create a dedicated `auth` domain for both
|
||||
|
||||
## Decision Outcome
|
||||
|
||||
Chosen option: "dedicated `auth` domain", because both resources are identity/access concerns and grouping them together makes the API surface self-documenting.
|
||||
|
||||
Changes made:
|
||||
- `src/routes/api/auth/` created with `users.routes.js`, `applications.routes.js`, and `index.js`
|
||||
- `/user` removed from `src/routes/api/cms/index.js`
|
||||
- `/applications` removed from `src/routes/api/skydive/index.js`
|
||||
- `/auth` domain registered in `src/routes/api/index.js`
|
||||
- Frontend `user.service.ts` and `applications.service.ts` updated: `_apiDomain` changed from `/cms` and `/skydive` to `/auth`
|
||||
|
||||
Resulting routes: `/api/auth/user/*` and `/api/auth/applications/*`.
|
||||
|
||||
### Positive Consequences
|
||||
|
||||
* API domain structure matches resource semantics — auth concerns are isolated from content and feature domains.
|
||||
* A single place to tighten auth-specific middleware (rate limiting, IP allowlists, audit logging) without touching other domains.
|
||||
|
||||
### Negative Consequences
|
||||
|
||||
* Breaking change on the API surface — any client other than the Angular frontend calling the old paths must be updated.
|
||||
|
||||
## Pros and Cons of the Options
|
||||
|
||||
### Keep routes in current domains
|
||||
|
||||
* Good, because no migration effort.
|
||||
* Bad, because the domain prefix actively misleads — users are not CMS content, applications are not skydive data.
|
||||
|
||||
### Move only users out of CMS
|
||||
|
||||
* Good, because smaller change.
|
||||
* Bad, because applications in skydive remains wrong, and two related resources end up in different places.
|
||||
|
||||
### Dedicated auth domain
|
||||
|
||||
* Good, because both resources land where their semantics say they belong.
|
||||
* Good, because the auth boundary is explicit and ready for future hardening.
|
||||
* Bad, because it is a breaking change requiring a coordinated update of all consumers.
|
||||
Generated
+933
-675
File diff suppressed because it is too large
Load Diff
+16
-19
@@ -27,46 +27,43 @@
|
||||
"dependencies": {
|
||||
"@sendgrid/mail": "^7.7.0",
|
||||
"bcrypt": "^5.1.1",
|
||||
"body-parser": "^1.20.2",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.4.5",
|
||||
"ejs": "^3.1.9",
|
||||
"errorhandler": "^1.5.1",
|
||||
"express": "^4.18.2",
|
||||
"express-jwt": "^8.4.1",
|
||||
"cors": "^2.8.6",
|
||||
"dotenv": "^16.6.1",
|
||||
"ejs": "^3.1.10",
|
||||
"express": "^5",
|
||||
"express-jwt": "^8.5.1",
|
||||
"express-rate-limit": "^8.4.1",
|
||||
"express-session": "^1.18.0",
|
||||
"express-session": "^1.19.0",
|
||||
"express-validator": "^7.3.2",
|
||||
"helmet": "^8.1.0",
|
||||
"js-yaml": "^4.1.1",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"method-override": "3.0.0",
|
||||
"jsonwebtoken": "^9.0.3",
|
||||
"methods": "1.1.2",
|
||||
"mongoose": "^6.12.6",
|
||||
"mongoose-unique-validator": "^3.1.0",
|
||||
"morgan": "^1.10.0",
|
||||
"mysql2": "^3.14.3",
|
||||
"morgan": "^1.10.1",
|
||||
"mysql2": "^3.22.3",
|
||||
"node-fetch": "^3.3.2",
|
||||
"passport": "^0.6.0",
|
||||
"passport-headerapikey": "^1.2.2",
|
||||
"passport-local": "^1.0.0",
|
||||
"request": "^2.88.2",
|
||||
"sequelize": "^6.37.3",
|
||||
"sequelize": "^6.37.8",
|
||||
"sequelize-auto": "^0.8.8",
|
||||
"slug": "^8.2.3",
|
||||
"swagger-jsdoc": "^6.2.8",
|
||||
"swagger-ui-express": "^5.0.1",
|
||||
"underscore": "^1.13.6",
|
||||
"underscore": "^1.13.8",
|
||||
"uuid": "^9.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.0.0",
|
||||
"eslint": "^9.0.0",
|
||||
"globals": "^15.0.0",
|
||||
"@eslint/js": "^9.39.4",
|
||||
"eslint": "^9.39.4",
|
||||
"globals": "^15.15.0",
|
||||
"jest": "^30.3.0",
|
||||
"newman": "^5.3.2",
|
||||
"nodemon": "^2.0.22",
|
||||
"sequelize-cli": "^6.6.2",
|
||||
"nodemon": "^3.1.14",
|
||||
"sequelize-cli": "^6.6.5",
|
||||
"supertest": "^7.2.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@
|
||||
},
|
||||
{
|
||||
"num": 21,
|
||||
"libelle": "La vitesse de largage d’un Cessna (206 ; 207) est d ‘environ :",
|
||||
"libelle": "La vitesse de largage d’un Cessna (206 ; 207) est d’environ :",
|
||||
"answers": [
|
||||
{"index": "A", "libelle": "50 kts.", "correct": false},
|
||||
{"index": "B", "libelle": "80 kts.", "correct": true},
|
||||
@@ -189,7 +189,7 @@
|
||||
},
|
||||
{
|
||||
"num": 22,
|
||||
"libelle": "La vitesse de largage d’un Cessna Caravan est d ‘environ :",
|
||||
"libelle": "La vitesse de largage d’un Cessna Caravan est d’environ :",
|
||||
"answers": [
|
||||
{"index": "A", "libelle": "100 kts.", "correct": false},
|
||||
{"index": "B", "libelle": "80 kts.", "correct": true},
|
||||
@@ -839,7 +839,7 @@
|
||||
},
|
||||
{
|
||||
"num": 94,
|
||||
"libelle": "Au moment du largage, s‘assurer que l’espace aérien est dégagé en dessous :",
|
||||
"libelle": "Au moment du largage, s’assurer que l’espace aérien est dégagé en dessous :",
|
||||
"answers": [
|
||||
{"index": "A", "libelle": "Est de la responsabilité du pilote, du directeur de séance et du largueur.", "correct": true},
|
||||
{"index": "B", "libelle": "Est de la responsabilité du directeur de séance uniquement.", "correct": false},
|
||||
@@ -1519,7 +1519,7 @@
|
||||
},
|
||||
{
|
||||
"num": 167,
|
||||
"libelle": "Pour faire un virage ‘’à plat’’ :",
|
||||
"libelle": "Pour faire un virage ’à plat’ :",
|
||||
"answers": [
|
||||
{"index": "A", "libelle": "Il faut manœuvrer très rapidement à pleine vitesse.", "correct": false},
|
||||
{"index": "B", "libelle": "Il faut manœuvrer doucement et en ½ frein.", "correct": true}
|
||||
@@ -1738,7 +1738,7 @@
|
||||
},
|
||||
{
|
||||
"num": 191,
|
||||
"libelle": "Qu‘appelle-t-on angle d’incidence ?",
|
||||
"libelle": "Qu’appelle-t-on angle d’incidence ?",
|
||||
"answers": [
|
||||
{"index": "A", "libelle": "L’angle entre l’aile et l’axe du cône de suspension.", "correct": false},
|
||||
{"index": "B", "libelle": "L’angle entre la trajectoire et l’horizontale.", "correct": false},
|
||||
@@ -3260,7 +3260,7 @@
|
||||
"libelle": "La présence d’une couche nuageuse en altitude (cirrocumulus ou cirrostratus) :",
|
||||
"answers": [
|
||||
{"index": "A", "libelle": "Indique que le mauvais temps est passé.", "correct": false},
|
||||
{"index": "B", "libelle": "Annonce l ‘arrivée d’une perturbation.", "correct": true}
|
||||
{"index": "B", "libelle": "Annonce l’arrivée d’une perturbation.", "correct": true}
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
const { ArticleService, TagService, UserService } = require('../services');
|
||||
const asyncHandler = require("../middlewares/asyncHandler");
|
||||
const ErrorResponse = require("../utils/errorResponse");
|
||||
|
||||
const includeOptions = ArticleService.getArticleIncludeAssoc();
|
||||
|
||||
module.exports.createArticle = asyncHandler(async (req, res, next) => {
|
||||
module.exports.createArticle = async (req, res, next) => {
|
||||
try {
|
||||
const loggedUser = await UserService.getLoggedUserById(req.payload.id);
|
||||
|
||||
@@ -47,9 +46,9 @@ module.exports.createArticle = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while creating article.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.deleteArticle = asyncHandler(async (req, res, next) => {
|
||||
module.exports.deleteArticle = async (req, res, next) => {
|
||||
try {
|
||||
const { slug } = req.params;
|
||||
const loggedUser = await UserService.getLoggedUserById(req.payload.id);
|
||||
@@ -72,9 +71,9 @@ module.exports.deleteArticle = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while deleting article.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getArticle = asyncHandler(async (req, res, next) => {
|
||||
module.exports.getArticle = async (req, res, next) => {
|
||||
try {
|
||||
const { slug } = req.params;
|
||||
|
||||
@@ -93,9 +92,9 @@ module.exports.getArticle = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while fetching article.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getArticles = asyncHandler(async (req, res, next) => {
|
||||
module.exports.getArticles = async (req, res, next) => {
|
||||
try {
|
||||
let articles = { rows: [], count: 0 };
|
||||
const { tag, author, favorited, limit = 20, offset = 0 } = req.query;
|
||||
@@ -131,9 +130,9 @@ module.exports.getArticles = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while fetching articles.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.updateArticle = asyncHandler(async (req, res, next) => {
|
||||
module.exports.updateArticle = async (req, res, next) => {
|
||||
try {
|
||||
const { slug } = req.params;
|
||||
const loggedUser = await UserService.getLoggedUserById(req.payload.id);
|
||||
@@ -174,9 +173,9 @@ module.exports.updateArticle = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while updating article.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.articlesFeed = asyncHandler(async (req, res, next) => {
|
||||
module.exports.articlesFeed = async (req, res, next) => {
|
||||
try {
|
||||
const { limit = 3, offset = 0 } = req.query;
|
||||
const loggedUser = await UserService.getLoggedUserById(req.payload.id);
|
||||
@@ -207,9 +206,9 @@ module.exports.articlesFeed = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while fetching articles feed.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.addFavoriteArticle = asyncHandler(async (req, res, next) => {
|
||||
module.exports.addFavoriteArticle = async (req, res, next) => {
|
||||
try {
|
||||
const { slug } = req.params;
|
||||
const loggedUser = await UserService.getLoggedUserById(req.payload.id);
|
||||
@@ -227,9 +226,9 @@ module.exports.addFavoriteArticle = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while adding a favorite.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.deleteFavoriteArticle = asyncHandler(async (req, res, next) => {
|
||||
module.exports.deleteFavoriteArticle = async (req, res, next) => {
|
||||
try {
|
||||
const { slug } = req.params;
|
||||
const loggedUser = await UserService.getLoggedUserById(req.payload.id);
|
||||
@@ -248,5 +247,5 @@ module.exports.deleteFavoriteArticle = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while removing a favorite.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
const { ClanService, UserService } = require('../services');
|
||||
const asyncHandler = require("../middlewares/asyncHandler");
|
||||
const ErrorResponse = require("../utils/errorResponse");
|
||||
|
||||
module.exports.createClan = asyncHandler(async (req, res, next) => {
|
||||
module.exports.createClan = async (req, res, next) => {
|
||||
try {
|
||||
const user = await UserService.getUserById(req.payload.id);
|
||||
if (!user) {
|
||||
@@ -27,9 +26,9 @@ module.exports.createClan = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse(`Something went wrong while creating clan.`, 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.deleteClan = asyncHandler(async (req, res, next) => {
|
||||
module.exports.deleteClan = async (req, res, next) => {
|
||||
try {
|
||||
const { clanId } = req.params;
|
||||
let clan = await ClanService.getClanById(clanId);
|
||||
@@ -45,9 +44,9 @@ module.exports.deleteClan = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse(`Something went wrong while deleting clan.`, 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getAllClans = asyncHandler(async (req, res, next) => {
|
||||
module.exports.getAllClans = async (req, res, next) => {
|
||||
try {
|
||||
let query = {};
|
||||
let { limit = 25, offset = 0 } = req.query;
|
||||
@@ -73,9 +72,9 @@ module.exports.getAllClans = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse(`Something went wrong while fetching clans.`, 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getClan = asyncHandler(async (req, res, next) => {
|
||||
module.exports.getClan = async (req, res, next) => {
|
||||
try {
|
||||
const { clanId } = req.params;
|
||||
let clan = await ClanService.getClanById(clanId);
|
||||
@@ -87,9 +86,9 @@ module.exports.getClan = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse(`Something went wrong while fetching clan.`, 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.updateClan = asyncHandler(async (req, res, next) => {
|
||||
module.exports.updateClan = async (req, res, next) => {
|
||||
try {
|
||||
const { clanId } = req.params;
|
||||
let clan = await ClanService.getClanById(clanId);
|
||||
@@ -110,4 +109,4 @@ module.exports.updateClan = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse(`Something went wrong while updating clan.`, 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
const { CommentService } = require('../services');
|
||||
const asyncHandler = require("../middlewares/asyncHandler");
|
||||
const ErrorResponse = require("../utils/errorResponse");
|
||||
|
||||
module.exports.createComment = asyncHandler(async (req, res, next) => {
|
||||
module.exports.createComment = async (req, res, next) => {
|
||||
try {
|
||||
const { slug, title, description, body } = req.body;
|
||||
const comment = await CommentService.createComment({
|
||||
@@ -20,9 +19,9 @@ module.exports.createComment = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while creating comment.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getAllComments = asyncHandler(async (req, res, next) => {
|
||||
module.exports.getAllComments = async (req, res, next) => {
|
||||
try {
|
||||
const comments = await CommentService.getAllComments();
|
||||
|
||||
@@ -32,4 +31,4 @@ module.exports.getAllComments = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while fetching comments.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
const { MemberService, UserService } = require('../services');
|
||||
const asyncHandler = require("../middlewares/asyncHandler");
|
||||
const ErrorResponse = require("../utils/errorResponse");
|
||||
|
||||
module.exports.createMember = asyncHandler(async (req, res, next) => {
|
||||
module.exports.createMember = async (req, res, next) => {
|
||||
try {
|
||||
const user = await UserService.getUserById(req.payload.id);
|
||||
if (!user) {
|
||||
@@ -26,9 +25,9 @@ module.exports.createMember = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse(`Something went wrong while creating member.`, 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.deleteMember = asyncHandler(async (req, res, next) => {
|
||||
module.exports.deleteMember = async (req, res, next) => {
|
||||
try {
|
||||
const { memberId } = req.params;
|
||||
let member = await MemberService.getMemberById(memberId);
|
||||
@@ -44,9 +43,9 @@ module.exports.deleteMember = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse(`Something went wrong while deleting member.`, 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getAllMembers = asyncHandler(async (req, res, next) => {
|
||||
module.exports.getAllMembers = async (req, res, next) => {
|
||||
try {
|
||||
let query = {};
|
||||
let { limit = 25, offset = 0 } = req.query;
|
||||
@@ -72,9 +71,9 @@ module.exports.getAllMembers = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse(`Something went wrong while fetching members.`, 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getMember = asyncHandler(async (req, res, next) => {
|
||||
module.exports.getMember = async (req, res, next) => {
|
||||
try {
|
||||
const { memberId } = req.params;
|
||||
let member = await MemberService.getMemberById(memberId);
|
||||
@@ -86,9 +85,9 @@ module.exports.getMember = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse(`Something went wrong while updating member.`, 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.updateMember = asyncHandler(async (req, res, next) => {
|
||||
module.exports.updateMember = async (req, res, next) => {
|
||||
try {
|
||||
const { memberId } = req.params;
|
||||
let member = await MemberService.getMemberById(memberId);
|
||||
@@ -109,4 +108,4 @@ module.exports.updateMember = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse(`Something went wrong while updating member.`, 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const { ProductService } = require('../services');
|
||||
//const { where } = require("sequelize");
|
||||
const asyncHandler = require("../middlewares/asyncHandler");
|
||||
const Product = require("../database/models/mysql/Product");
|
||||
const Tag = require("../database/models/mysql/Tag");
|
||||
const User = require("../database/models/mysql/User");
|
||||
@@ -23,7 +22,7 @@ const includeOptions = [
|
||||
{ model: User, as: "author", attributes: { exclude: ["email", "password"] } },
|
||||
];
|
||||
|
||||
module.exports.getProducts = asyncHandler(async (req, res) => {
|
||||
module.exports.getProducts = async (req, res) => {
|
||||
const { tag, author, favorited, limit = 20, offset = 0 } = req.query;
|
||||
const { loggedUser } = req;
|
||||
|
||||
@@ -75,9 +74,9 @@ module.exports.getProducts = asyncHandler(async (req, res) => {
|
||||
res
|
||||
.status(200)
|
||||
.json({ products: products.rows, productsCount: products.count });
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getProductsByCategory = asyncHandler(async (req, res, next) => {
|
||||
module.exports.getProductsByCategory = async (req, res, next) => {
|
||||
const { category } = req.params;
|
||||
//console.log(category);
|
||||
|
||||
@@ -88,9 +87,9 @@ module.exports.getProductsByCategory = asyncHandler(async (req, res, next) => {
|
||||
return next(new ErrorResponse("Products not found", 404));
|
||||
}
|
||||
res.status(200).json({ category: category, count: products.count, products: products.rows });
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.productsFeed = asyncHandler(async (req, res) => {
|
||||
module.exports.productsFeed = async (req, res) => {
|
||||
const { loggedUser } = req;
|
||||
|
||||
const { limit = 3, offset = 0 } = req.query;
|
||||
@@ -114,9 +113,9 @@ module.exports.productsFeed = asyncHandler(async (req, res) => {
|
||||
}
|
||||
|
||||
res.json({ products: products.rows, productsCount: products.count });
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getProduct = asyncHandler(async (req, res, next) => {
|
||||
module.exports.getProduct = async (req, res, next) => {
|
||||
const { slug: productSlug } = req.params;
|
||||
|
||||
let product = await ProductService.getProductBySlug(productSlug);
|
||||
@@ -129,9 +128,9 @@ module.exports.getProduct = asyncHandler(async (req, res, next) => {
|
||||
product.tags = tags;
|
||||
|
||||
res.status(200).json({ product: product });
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.createProduct = asyncHandler(async (req, res, next) => {
|
||||
module.exports.createProduct = async (req, res, next) => {
|
||||
const { loggedUser } = req;
|
||||
|
||||
const { title, description, body, tagList } = req.body.product;
|
||||
@@ -165,9 +164,9 @@ module.exports.createProduct = asyncHandler(async (req, res, next) => {
|
||||
await appendFavorites(loggedUser, product);
|
||||
|
||||
res.status(201).json({ product });
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.deleteProduct = asyncHandler(async (req, res, next) => {
|
||||
module.exports.deleteProduct = async (req, res, next) => {
|
||||
const { slug: productSlug } = req.params;
|
||||
const { loggedUser } = req;
|
||||
|
||||
@@ -187,9 +186,9 @@ module.exports.deleteProduct = asyncHandler(async (req, res, next) => {
|
||||
await product.destroy();
|
||||
|
||||
res.status(200).json({ product });
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.updateProduct = asyncHandler(async (req, res, next) => {
|
||||
module.exports.updateProduct = async (req, res, next) => {
|
||||
const { slug: productSlug } = req.params;
|
||||
const { loggedUser } = req;
|
||||
|
||||
@@ -225,9 +224,9 @@ module.exports.updateProduct = asyncHandler(async (req, res, next) => {
|
||||
await appendFavorites(loggedUser, product);
|
||||
|
||||
res.status(200).json({ product });
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.addFavoriteProduct = asyncHandler(async (req, res, next) => {
|
||||
module.exports.addFavoriteProduct = async (req, res, next) => {
|
||||
const { loggedUser } = req;
|
||||
const { slug: productSlug } = req.params;
|
||||
|
||||
@@ -248,9 +247,9 @@ module.exports.addFavoriteProduct = asyncHandler(async (req, res, next) => {
|
||||
await appendFavorites(loggedUser, product);
|
||||
|
||||
res.status(200).json({ product });
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.deleteFavoriteProduct = asyncHandler(async (req, res, next) => {
|
||||
module.exports.deleteFavoriteProduct = async (req, res, next) => {
|
||||
const { loggedUser } = req;
|
||||
const { slug: productSlug } = req.params;
|
||||
|
||||
@@ -271,5 +270,5 @@ module.exports.deleteFavoriteProduct = asyncHandler(async (req, res, next) => {
|
||||
await appendFavorites(loggedUser, product);
|
||||
|
||||
res.status(200).json({ product });
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
const { UserService } = require('../services');
|
||||
const asyncHandler = require("../middlewares/asyncHandler");
|
||||
const ErrorResponse = require("../utils/errorResponse");
|
||||
|
||||
module.exports.addFollowUser = asyncHandler(async (req, res, next) => {
|
||||
module.exports.addFollowUser = async (req, res, next) => {
|
||||
try {
|
||||
return res.status(200).json({
|
||||
message: 'The user is now being followed.'
|
||||
@@ -10,9 +9,9 @@ module.exports.addFollowUser = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while following a user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.deleteFollowUser = asyncHandler(async (req, res, next) => {
|
||||
module.exports.deleteFollowUser = async (req, res, next) => {
|
||||
try {
|
||||
return res.status(200).json({
|
||||
message: 'The user is no longer being followed.',
|
||||
@@ -21,9 +20,9 @@ module.exports.deleteFollowUser = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while unfollowing a user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getProfile = asyncHandler(async (req, res, next) => {
|
||||
module.exports.getProfile = async (req, res, next) => {
|
||||
try {
|
||||
/*const user = await UserService.getUserById(req.payload.id);
|
||||
if (!user) {
|
||||
@@ -35,7 +34,7 @@ module.exports.getProfile = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while fetching user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getParamUsername = async (req, res, next, value) => {
|
||||
try {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
const { TagService, UserService } = require('../services');
|
||||
const asyncHandler = require("../middlewares/asyncHandler");
|
||||
const ErrorResponse = require("../utils/errorResponse");
|
||||
|
||||
module.exports.createTag = asyncHandler(async (req, res, next) => {
|
||||
module.exports.createTag = async (req, res, next) => {
|
||||
try {
|
||||
const { name } = req.body.tag;
|
||||
const tagInDB = await TagService.tagIsInDB(name);
|
||||
@@ -19,9 +18,9 @@ module.exports.createTag = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while creating tag.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.deleteTag = asyncHandler(async (req, res, next) => {
|
||||
module.exports.deleteTag = async (req, res, next) => {
|
||||
try {
|
||||
const { name } = req.params;
|
||||
const tag = await TagService.getTagByName(name);
|
||||
@@ -41,9 +40,9 @@ module.exports.deleteTag = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while fetching tags.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getAllTags = asyncHandler(async (req, res, next) => {
|
||||
module.exports.getAllTags = async (req, res, next) => {
|
||||
try {
|
||||
const tags = await TagService.getAllTags();
|
||||
|
||||
@@ -56,5 +55,5 @@ module.exports.getAllTags = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while fetching tags.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
const { UserService, SkydiverProfileService } = require('../services');
|
||||
const asyncHandler = require("../middlewares/asyncHandler");
|
||||
const ErrorResponse = require("../utils/errorResponse");
|
||||
var crypto = require('crypto');
|
||||
const passport = require('passport');
|
||||
|
||||
module.exports.authenticate = asyncHandler(async (req, res, next) => {
|
||||
module.exports.authenticate = async (req, res, next) => {
|
||||
try {
|
||||
passport.authenticate('headerapikey', { session: false }, function (err, application, info) {
|
||||
if (err) {
|
||||
@@ -28,9 +27,9 @@ module.exports.authenticate = asyncHandler(async (req, res, next) => {
|
||||
//res.status(500).json({ message: 'Something went wrong while authenticating.', error: err.message });
|
||||
return next(new ErrorResponse('Something went wrong while authenticating.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.createUser = asyncHandler(async (req, res, next) => {
|
||||
module.exports.createUser = async (req, res, next) => {
|
||||
try {
|
||||
const { username, firstname, lastname, phone, email, password } = req.body.user;
|
||||
const userSlug = UserService.slugify(username);
|
||||
@@ -57,9 +56,9 @@ module.exports.createUser = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while creating user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getAllUsers = asyncHandler(async (req, res, next) => {
|
||||
module.exports.getAllUsers = async (req, res, next) => {
|
||||
try {
|
||||
const users = await UserService.getAllUsers();
|
||||
|
||||
@@ -69,24 +68,29 @@ module.exports.getAllUsers = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while fetching user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.getUser = asyncHandler(async (req, res, next) => {
|
||||
module.exports.getUser = async (req, res, next) => {
|
||||
try {
|
||||
const user = await UserService.getUserById(req.payload.id);
|
||||
if (!user) {
|
||||
return next(new ErrorResponse("Unauthorized", 401, "Authentication required."));
|
||||
}
|
||||
|
||||
const profile = await SkydiverProfileService.getByUserId(req.payload.id);
|
||||
|
||||
res.status(200).json({
|
||||
user: user.toAuthJSON()
|
||||
user: {
|
||||
...user.toAuthJSON(),
|
||||
...(profile ? profile.toJSONFor() : { poids: null, licence: null, bg_image: null }),
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while fetching user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.loginAsUser = asyncHandler(async (req, res, next) => {
|
||||
module.exports.loginAsUser = async (req, res, next) => {
|
||||
try {
|
||||
passport.authenticate('local', { session: false }, function (err, user, info) {
|
||||
if (err) {
|
||||
@@ -102,9 +106,9 @@ module.exports.loginAsUser = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while processing login.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.updateUser = asyncHandler(async (req, res, next) => {
|
||||
module.exports.updateUser = async (req, res, next) => {
|
||||
try {
|
||||
let user = await UserService.getUserById(req.payload.id);
|
||||
if (!user) {
|
||||
@@ -142,9 +146,9 @@ module.exports.updateUser = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while updating user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.updateUserEmail = asyncHandler(async (req, res, next) => {
|
||||
module.exports.updateUserEmail = async (req, res, next) => {
|
||||
try {
|
||||
let user = await UserService.getUserById(req.payload.id);
|
||||
if (!user) {
|
||||
@@ -162,9 +166,9 @@ module.exports.updateUserEmail = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while updating user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.updateUserPassword = asyncHandler(async (req, res, next) => {
|
||||
module.exports.updateUserPassword = async (req, res, next) => {
|
||||
try {
|
||||
let user = await UserService.getUserById(req.payload.id);
|
||||
if (!user) {
|
||||
@@ -182,9 +186,9 @@ module.exports.updateUserPassword = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while updating user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.updateUserRole = asyncHandler(async (req, res, next) => {
|
||||
module.exports.updateUserRole = async (req, res, next) => {
|
||||
try {
|
||||
let user = await UserService.getUserById(req.payload.id);
|
||||
if (!user) {
|
||||
@@ -205,9 +209,9 @@ module.exports.updateUserRole = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while updating user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.updateUserUsername = asyncHandler(async (req, res, next) => {
|
||||
module.exports.updateUserUsername = async (req, res, next) => {
|
||||
try {
|
||||
let user = await UserService.getUserById(req.payload.id);
|
||||
if (!user) {
|
||||
@@ -225,5 +229,5 @@ module.exports.updateUserUsername = asyncHandler(async (req, res, next) => {
|
||||
} catch (err) {
|
||||
return next(new ErrorResponse('Something went wrong while updating user.', 500, err.message));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
+1
-7
@@ -1,8 +1,7 @@
|
||||
var express = require('express'),
|
||||
session = require('express-session'),
|
||||
cors = require('cors'),
|
||||
helmet = require('helmet'),
|
||||
errorhandler = require('errorhandler');
|
||||
helmet = require('helmet');
|
||||
|
||||
const config = require('./config'),
|
||||
swaggerUi = require('swagger-ui-express'),
|
||||
@@ -23,7 +22,6 @@ function createApp() {
|
||||
}));
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use(require('method-override')());
|
||||
app.use(express.static(__dirname + '/../public'));
|
||||
app.use(session({
|
||||
secret: process.env.SESSION_SECRET || config.secret,
|
||||
@@ -32,10 +30,6 @@ function createApp() {
|
||||
saveUninitialized: false
|
||||
}));
|
||||
|
||||
if (process.env.APP_ENV !== 'production') {
|
||||
app.use(errorhandler());
|
||||
}
|
||||
|
||||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec, {
|
||||
swaggerOptions: { persistAuthorization: true },
|
||||
}));
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
const asyncHandler = (fn) => (req, res, next) => {
|
||||
Promise.resolve(fn(req, res, next)).catch((err) => {
|
||||
next(err);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = asyncHandler;
|
||||
@@ -0,0 +1,6 @@
|
||||
var routes = require('express').Router();
|
||||
|
||||
routes.use('/user', require('./users.routes'));
|
||||
routes.use('/applications', require('./applications.routes'));
|
||||
|
||||
module.exports = routes;
|
||||
@@ -1,6 +1,5 @@
|
||||
var routes = require('express').Router();
|
||||
|
||||
routes.use('/user', require('./users.routes'));
|
||||
routes.use('/articles', require('./articles.routes'));
|
||||
routes.use('/comments', require('./comments.routes'));
|
||||
routes.use('/profiles', require('./profiles.routes'));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
var routes = require('express').Router();
|
||||
|
||||
routes.use('/auth', require('./auth'));
|
||||
routes.use('/skydive', require('./skydive'));
|
||||
routes.use('/cms', require('./cms'));
|
||||
routes.use('/ecommerce', require('./ecommerce'));
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
var routes = require('express').Router();
|
||||
|
||||
routes.use('/applications', require('./applications.routes'));
|
||||
routes.use('/aeronefs', require('./aeronefs.routes'));
|
||||
routes.use('/canopies', require('./canopies.routes'));
|
||||
routes.use('/dropzones', require('./dropzones.routes'));
|
||||
|
||||
Reference in New Issue
Block a user