@wrcb/cb-common 1.0.33 → 1.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/errors/databaseConnectionError.js +2 -4
- package/build/errors/requestValidationError.js +1 -1
- package/build/events/baseListener.js +3 -1
- package/build/events/predictionPausedEvent.d.ts +16 -0
- package/build/events/predictionPausedEvent.js +2 -0
- package/build/events/subjects.d.ts +1 -0
- package/build/events/subjects.js +1 -0
- package/build/events/types/predictionStatus.d.ts +1 -0
- package/build/events/types/predictionStatus.js +1 -1
- package/build/events/types/userRole.d.ts +4 -0
- package/build/events/types/userRole.js +8 -0
- package/build/index.d.ts +3 -0
- package/build/index.js +3 -0
- package/build/middlewares/currentUser.d.ts +1 -0
- package/build/middlewares/errorHandler.js +1 -4
- package/build/middlewares/requireAdmin.d.ts +2 -0
- package/build/middlewares/requireAdmin.js +13 -0
- package/package.json +1 -1
|
@@ -4,15 +4,13 @@ exports.DatabaseConnectionError = void 0;
|
|
|
4
4
|
const customError_1 = require("./customError");
|
|
5
5
|
class DatabaseConnectionError extends customError_1.CustomError {
|
|
6
6
|
constructor() {
|
|
7
|
-
super(
|
|
7
|
+
super('Error connecting to database'); // apenas para logging pourpouses
|
|
8
8
|
this.statusCode = 500;
|
|
9
9
|
this.reason = 'Error connecting to database';
|
|
10
10
|
Object.setPrototypeOf(this, DatabaseConnectionError.prototype);
|
|
11
11
|
}
|
|
12
12
|
serializeErrors() {
|
|
13
|
-
return [
|
|
14
|
-
{ message: this.reason }
|
|
15
|
-
];
|
|
13
|
+
return [{ message: this.reason }];
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
exports.DatabaseConnectionError = DatabaseConnectionError;
|
|
@@ -4,7 +4,7 @@ exports.RequestValidationError = void 0;
|
|
|
4
4
|
const customError_1 = require("./customError");
|
|
5
5
|
class RequestValidationError extends customError_1.CustomError {
|
|
6
6
|
constructor(errors) {
|
|
7
|
-
super(
|
|
7
|
+
super('Invalid request parameters'); // apenas para logging pourpouses
|
|
8
8
|
this.errors = errors;
|
|
9
9
|
this.statusCode = 400;
|
|
10
10
|
Object.setPrototypeOf(this, RequestValidationError.prototype);
|
|
@@ -24,7 +24,9 @@ class Listener {
|
|
|
24
24
|
}
|
|
25
25
|
parseMessage(msg) {
|
|
26
26
|
const data = msg.getData();
|
|
27
|
-
return typeof data === 'string'
|
|
27
|
+
return typeof data === 'string'
|
|
28
|
+
? JSON.parse(data)
|
|
29
|
+
: JSON.parse(data.toString('utf-8'));
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
exports.Listener = Listener;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Subjects } from './subjects';
|
|
2
|
+
export interface PredictionPausedEvent {
|
|
3
|
+
subject: Subjects.PredictionPaused;
|
|
4
|
+
data: {
|
|
5
|
+
id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
description: string;
|
|
8
|
+
version: number;
|
|
9
|
+
deadLine: Date;
|
|
10
|
+
market: {
|
|
11
|
+
id: string;
|
|
12
|
+
title: string;
|
|
13
|
+
description: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -4,6 +4,7 @@ export declare enum Subjects {
|
|
|
4
4
|
CommentUpdated = "comment:updated",
|
|
5
5
|
PredictionCreated = "prediction:created",
|
|
6
6
|
PredictionStarted = "prediction:started",
|
|
7
|
+
PredictionPaused = "prediction:paused",
|
|
7
8
|
PredictionFinished = "prediction:finished",
|
|
8
9
|
PredictionResultProcessed = "prediction:result:processed",
|
|
9
10
|
BetMade = "bet:made",
|
package/build/events/subjects.js
CHANGED
|
@@ -8,6 +8,7 @@ var Subjects;
|
|
|
8
8
|
Subjects["CommentUpdated"] = "comment:updated";
|
|
9
9
|
Subjects["PredictionCreated"] = "prediction:created";
|
|
10
10
|
Subjects["PredictionStarted"] = "prediction:started";
|
|
11
|
+
Subjects["PredictionPaused"] = "prediction:paused";
|
|
11
12
|
Subjects["PredictionFinished"] = "prediction:finished";
|
|
12
13
|
Subjects["PredictionResultProcessed"] = "prediction:result:processed";
|
|
13
14
|
Subjects["BetMade"] = "bet:made";
|
|
@@ -4,8 +4,8 @@ exports.PredictionStatus = void 0;
|
|
|
4
4
|
var PredictionStatus;
|
|
5
5
|
(function (PredictionStatus) {
|
|
6
6
|
PredictionStatus["Created"] = "created";
|
|
7
|
-
// Confirmed = 'confirmed', // aposta que foi confirmada mas não iniciou o evento (preciso disso?)
|
|
8
7
|
PredictionStatus["Started"] = "started";
|
|
8
|
+
PredictionStatus["Paused"] = "paused";
|
|
9
9
|
PredictionStatus["Finished"] = "finished";
|
|
10
10
|
PredictionStatus["PaymentProcessed"] = "payment:processed";
|
|
11
11
|
})(PredictionStatus || (exports.PredictionStatus = PredictionStatus = {}));
|
package/build/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './middlewares/currentUser';
|
|
|
8
8
|
export * from './middlewares/errorHandler';
|
|
9
9
|
export * from './middlewares/requireAuth';
|
|
10
10
|
export * from './middlewares/validateRequest';
|
|
11
|
+
export * from './middlewares/requireAdmin';
|
|
11
12
|
export * from './events/baseListener';
|
|
12
13
|
export * from './events/basePublisher';
|
|
13
14
|
export * from './events/subjects';
|
|
@@ -16,10 +17,12 @@ export * from './events/types/predictionStatus';
|
|
|
16
17
|
export * from './events/types/ledgerOperation';
|
|
17
18
|
export * from './events/types/ledgerOperationMode';
|
|
18
19
|
export * from './events/types/country';
|
|
20
|
+
export * from './events/types/userRole';
|
|
19
21
|
export * from './events/commentCreatedEvent';
|
|
20
22
|
export * from './events/commentUpdatedEvent';
|
|
21
23
|
export * from './events/predictionFinishedEvent';
|
|
22
24
|
export * from './events/predictionStartedEvent';
|
|
25
|
+
export * from './events/predictionPausedEvent';
|
|
23
26
|
export * from './events/betMadeEvent';
|
|
24
27
|
export * from './events/betClaimMadeEvent';
|
|
25
28
|
export * from './events/depositMadeEvent';
|
package/build/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __exportStar(require("./middlewares/currentUser"), exports);
|
|
|
24
24
|
__exportStar(require("./middlewares/errorHandler"), exports);
|
|
25
25
|
__exportStar(require("./middlewares/requireAuth"), exports);
|
|
26
26
|
__exportStar(require("./middlewares/validateRequest"), exports);
|
|
27
|
+
__exportStar(require("./middlewares/requireAdmin"), exports);
|
|
27
28
|
__exportStar(require("./events/baseListener"), exports);
|
|
28
29
|
__exportStar(require("./events/basePublisher"), exports);
|
|
29
30
|
__exportStar(require("./events/subjects"), exports);
|
|
@@ -32,10 +33,12 @@ __exportStar(require("./events/types/predictionStatus"), exports);
|
|
|
32
33
|
__exportStar(require("./events/types/ledgerOperation"), exports);
|
|
33
34
|
__exportStar(require("./events/types/ledgerOperationMode"), exports);
|
|
34
35
|
__exportStar(require("./events/types/country"), exports);
|
|
36
|
+
__exportStar(require("./events/types/userRole"), exports);
|
|
35
37
|
__exportStar(require("./events/commentCreatedEvent"), exports);
|
|
36
38
|
__exportStar(require("./events/commentUpdatedEvent"), exports);
|
|
37
39
|
__exportStar(require("./events/predictionFinishedEvent"), exports);
|
|
38
40
|
__exportStar(require("./events/predictionStartedEvent"), exports);
|
|
41
|
+
__exportStar(require("./events/predictionPausedEvent"), exports);
|
|
39
42
|
__exportStar(require("./events/betMadeEvent"), exports);
|
|
40
43
|
__exportStar(require("./events/betClaimMadeEvent"), exports);
|
|
41
44
|
__exportStar(require("./events/depositMadeEvent"), exports);
|
|
@@ -7,9 +7,6 @@ const errorHandler = (err, req, res, next) => {
|
|
|
7
7
|
return res.status(err.statusCode).send({ errors: err.serializeErrors() });
|
|
8
8
|
}
|
|
9
9
|
console.error(err);
|
|
10
|
-
res.status(400).send({ errors: [
|
|
11
|
-
{ message: 'Something went wrong' }
|
|
12
|
-
]
|
|
13
|
-
});
|
|
10
|
+
res.status(400).send({ errors: [{ message: 'Something went wrong' }] });
|
|
14
11
|
};
|
|
15
12
|
exports.errorHandler = errorHandler;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requireAdmin = void 0;
|
|
4
|
+
const notAuthorizedError_1 = require("../errors/notAuthorizedError");
|
|
5
|
+
const userRole_1 = require("../events/types/userRole");
|
|
6
|
+
const requireAdmin = (req, res, next) => {
|
|
7
|
+
var _a;
|
|
8
|
+
if (((_a = req.currentUser) === null || _a === void 0 ? void 0 : _a.role) !== userRole_1.UserRole.Admin) {
|
|
9
|
+
throw new notAuthorizedError_1.NotAuthorizedError('Not Authorized - Just Admin role');
|
|
10
|
+
}
|
|
11
|
+
next();
|
|
12
|
+
};
|
|
13
|
+
exports.requireAdmin = requireAdmin;
|