bemoore-be-ticketing-common 1.0.1 → 1.0.4

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.
@@ -1,9 +1,9 @@
1
- import { CustomError } from './custom-error';
2
- export declare class BadRequestError extends CustomError {
3
- message: string;
4
- statusCode: number;
5
- constructor(message: string);
6
- serializeErrors(): {
7
- message: string;
8
- }[];
9
- }
1
+ import { CustomError } from './custom-error';
2
+ export declare class BadRequestError extends CustomError {
3
+ message: string;
4
+ statusCode: number;
5
+ constructor(message: string);
6
+ serializeErrors(): {
7
+ message: string;
8
+ }[];
9
+ }
@@ -1,16 +1,34 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BadRequestError = void 0;
4
- const custom_error_1 = require("./custom-error");
5
- class BadRequestError extends custom_error_1.CustomError {
6
- constructor(message) {
7
- super(message);
8
- this.message = message;
9
- this.statusCode = 500;
10
- Object.setPrototypeOf(this, BadRequestError.prototype);
11
- }
12
- serializeErrors() {
13
- return [{ message: this.message }];
14
- }
15
- }
16
- exports.BadRequestError = BadRequestError;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.BadRequestError = void 0;
19
+ var custom_error_1 = require("./custom-error");
20
+ var BadRequestError = /** @class */ (function (_super) {
21
+ __extends(BadRequestError, _super);
22
+ function BadRequestError(message) {
23
+ var _this = _super.call(this, message) || this;
24
+ _this.message = message;
25
+ _this.statusCode = 500;
26
+ Object.setPrototypeOf(_this, BadRequestError.prototype);
27
+ return _this;
28
+ }
29
+ BadRequestError.prototype.serializeErrors = function () {
30
+ return [{ message: this.message }];
31
+ };
32
+ return BadRequestError;
33
+ }(custom_error_1.CustomError));
34
+ exports.BadRequestError = BadRequestError;
@@ -1,8 +1,8 @@
1
- export declare abstract class CustomError extends Error {
2
- abstract statusCode: number;
3
- constructor(message: string);
4
- abstract serializeErrors(): Array<{
5
- message: string;
6
- field?: string;
7
- }>;
8
- }
1
+ export declare abstract class CustomError extends Error {
2
+ abstract statusCode: number;
3
+ constructor(message: string);
4
+ abstract serializeErrors(): Array<{
5
+ message: string;
6
+ field?: string;
7
+ }>;
8
+ }
@@ -1,10 +1,28 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CustomError = void 0;
4
- class CustomError extends Error {
5
- constructor(message) {
6
- super(message);
7
- Object.setPrototypeOf(this, CustomError.prototype);
8
- }
9
- }
10
- exports.CustomError = CustomError;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.CustomError = void 0;
19
+ var CustomError = /** @class */ (function (_super) {
20
+ __extends(CustomError, _super);
21
+ function CustomError(message) {
22
+ var _this = _super.call(this, message) || this;
23
+ Object.setPrototypeOf(_this, CustomError.prototype);
24
+ return _this;
25
+ }
26
+ return CustomError;
27
+ }(Error));
28
+ exports.CustomError = CustomError;
@@ -1,9 +1,9 @@
1
- import { CustomError } from './custom-error';
2
- export declare class DatabaseConnextionError extends CustomError {
3
- reason: string;
4
- statusCode: number;
5
- constructor();
6
- serializeErrors: () => {
7
- message: string;
8
- }[];
9
- }
1
+ import { CustomError } from './custom-error';
2
+ export declare class DatabaseConnextionError extends CustomError {
3
+ reason: string;
4
+ statusCode: number;
5
+ constructor();
6
+ serializeErrors: () => {
7
+ message: string;
8
+ }[];
9
+ }
@@ -1,16 +1,34 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DatabaseConnextionError = void 0;
4
- const custom_error_1 = require("./custom-error");
5
- class DatabaseConnextionError extends custom_error_1.CustomError {
6
- constructor() {
7
- super('Error connecting to db!');
8
- this.reason = 'Unable to connect to database';
9
- this.statusCode = 500;
10
- this.serializeErrors = () => {
11
- return [{ message: this.reason }];
12
- };
13
- Object.setPrototypeOf(this, DatabaseConnextionError.prototype);
14
- }
15
- }
16
- exports.DatabaseConnextionError = DatabaseConnextionError;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.DatabaseConnextionError = void 0;
19
+ var custom_error_1 = require("./custom-error");
20
+ var DatabaseConnextionError = /** @class */ (function (_super) {
21
+ __extends(DatabaseConnextionError, _super);
22
+ function DatabaseConnextionError() {
23
+ var _this = _super.call(this, 'Error connecting to db!') || this;
24
+ _this.reason = 'Unable to connect to database';
25
+ _this.statusCode = 500;
26
+ _this.serializeErrors = function () {
27
+ return [{ message: _this.reason }];
28
+ };
29
+ Object.setPrototypeOf(_this, DatabaseConnextionError.prototype);
30
+ return _this;
31
+ }
32
+ return DatabaseConnextionError;
33
+ }(custom_error_1.CustomError));
34
+ exports.DatabaseConnextionError = DatabaseConnextionError;
@@ -1,7 +1,7 @@
1
- import { BadRequestError } from './bad-request-error';
2
- import { CustomError } from './custom-error';
3
- import { DatabaseConnextionError } from './database-connection-error';
4
- import { NotAuthorizedError } from './not-authorized';
5
- import { NotFoundError } from './not-found-error';
6
- import { RequestValidationError } from './request-validation-error';
7
- export { BadRequestError, CustomError, DatabaseConnextionError, NotAuthorizedError, NotFoundError, RequestValidationError, };
1
+ import { BadRequestError } from './bad-request-error';
2
+ import { CustomError } from './custom-error';
3
+ import { DatabaseConnextionError } from './database-connection-error';
4
+ import { NotAuthorizedError } from './not-authorized';
5
+ import { NotFoundError } from './not-found-error';
6
+ import { RequestValidationError } from './request-validation-error';
7
+ export { BadRequestError, CustomError, DatabaseConnextionError, NotAuthorizedError, NotFoundError, RequestValidationError, };
@@ -1,15 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RequestValidationError = exports.NotFoundError = exports.NotAuthorizedError = exports.DatabaseConnextionError = exports.CustomError = exports.BadRequestError = void 0;
4
- const bad_request_error_1 = require("./bad-request-error");
5
- Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return bad_request_error_1.BadRequestError; } });
6
- const custom_error_1 = require("./custom-error");
7
- Object.defineProperty(exports, "CustomError", { enumerable: true, get: function () { return custom_error_1.CustomError; } });
8
- const database_connection_error_1 = require("./database-connection-error");
9
- Object.defineProperty(exports, "DatabaseConnextionError", { enumerable: true, get: function () { return database_connection_error_1.DatabaseConnextionError; } });
10
- const not_authorized_1 = require("./not-authorized");
11
- Object.defineProperty(exports, "NotAuthorizedError", { enumerable: true, get: function () { return not_authorized_1.NotAuthorizedError; } });
12
- const not_found_error_1 = require("./not-found-error");
13
- Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return not_found_error_1.NotFoundError; } });
14
- const request_validation_error_1 = require("./request-validation-error");
15
- Object.defineProperty(exports, "RequestValidationError", { enumerable: true, get: function () { return request_validation_error_1.RequestValidationError; } });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequestValidationError = exports.NotFoundError = exports.NotAuthorizedError = exports.DatabaseConnextionError = exports.CustomError = exports.BadRequestError = void 0;
4
+ var bad_request_error_1 = require("./bad-request-error");
5
+ Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return bad_request_error_1.BadRequestError; } });
6
+ var custom_error_1 = require("./custom-error");
7
+ Object.defineProperty(exports, "CustomError", { enumerable: true, get: function () { return custom_error_1.CustomError; } });
8
+ var database_connection_error_1 = require("./database-connection-error");
9
+ Object.defineProperty(exports, "DatabaseConnextionError", { enumerable: true, get: function () { return database_connection_error_1.DatabaseConnextionError; } });
10
+ var not_authorized_1 = require("./not-authorized");
11
+ Object.defineProperty(exports, "NotAuthorizedError", { enumerable: true, get: function () { return not_authorized_1.NotAuthorizedError; } });
12
+ var not_found_error_1 = require("./not-found-error");
13
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return not_found_error_1.NotFoundError; } });
14
+ var request_validation_error_1 = require("./request-validation-error");
15
+ Object.defineProperty(exports, "RequestValidationError", { enumerable: true, get: function () { return request_validation_error_1.RequestValidationError; } });
@@ -1,8 +1,8 @@
1
- import { CustomError } from './custom-error';
2
- export declare class NotAuthorizedError extends CustomError {
3
- statusCode: number;
4
- constructor();
5
- serializeErrors(): {
6
- message: string;
7
- }[];
8
- }
1
+ import { CustomError } from './custom-error';
2
+ export declare class NotAuthorizedError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
6
+ message: string;
7
+ }[];
8
+ }
@@ -1,15 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotAuthorizedError = void 0;
4
- const custom_error_1 = require("./custom-error");
5
- class NotAuthorizedError extends custom_error_1.CustomError {
6
- constructor() {
7
- super('Not authorized');
8
- this.statusCode = 401;
9
- Object.setPrototypeOf(this, NotAuthorizedError.prototype);
10
- }
11
- serializeErrors() {
12
- return [{ message: 'Not authorized' }];
13
- }
14
- }
15
- exports.NotAuthorizedError = NotAuthorizedError;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.NotAuthorizedError = void 0;
19
+ var custom_error_1 = require("./custom-error");
20
+ var NotAuthorizedError = /** @class */ (function (_super) {
21
+ __extends(NotAuthorizedError, _super);
22
+ function NotAuthorizedError() {
23
+ var _this = _super.call(this, 'Not authorized') || this;
24
+ _this.statusCode = 401;
25
+ Object.setPrototypeOf(_this, NotAuthorizedError.prototype);
26
+ return _this;
27
+ }
28
+ NotAuthorizedError.prototype.serializeErrors = function () {
29
+ return [{ message: 'Not authorized' }];
30
+ };
31
+ return NotAuthorizedError;
32
+ }(custom_error_1.CustomError));
33
+ exports.NotAuthorizedError = NotAuthorizedError;
@@ -1,8 +1,8 @@
1
- import { CustomError } from './custom-error';
2
- export declare class NotFoundError extends CustomError {
3
- statusCode: number;
4
- constructor();
5
- serializeErrors(): {
6
- message: string;
7
- }[];
8
- }
1
+ import { CustomError } from './custom-error';
2
+ export declare class NotFoundError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
6
+ message: string;
7
+ }[];
8
+ }
@@ -1,15 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotFoundError = void 0;
4
- const custom_error_1 = require("./custom-error");
5
- class NotFoundError extends custom_error_1.CustomError {
6
- constructor() {
7
- super('Route not found');
8
- this.statusCode = 404;
9
- Object.setPrototypeOf(this, NotFoundError.prototype);
10
- }
11
- serializeErrors() {
12
- return [{ message: 'Not Found' }];
13
- }
14
- }
15
- exports.NotFoundError = NotFoundError;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.NotFoundError = void 0;
19
+ var custom_error_1 = require("./custom-error");
20
+ var NotFoundError = /** @class */ (function (_super) {
21
+ __extends(NotFoundError, _super);
22
+ function NotFoundError() {
23
+ var _this = _super.call(this, 'Route not found') || this;
24
+ _this.statusCode = 404;
25
+ Object.setPrototypeOf(_this, NotFoundError.prototype);
26
+ return _this;
27
+ }
28
+ NotFoundError.prototype.serializeErrors = function () {
29
+ return [{ message: 'Not Found' }];
30
+ };
31
+ return NotFoundError;
32
+ }(custom_error_1.CustomError));
33
+ exports.NotFoundError = NotFoundError;
@@ -1,14 +1,14 @@
1
- import { ValidationError } from 'express-validator';
2
- import { CustomError } from './custom-error';
3
- export declare class RequestValidationError extends CustomError {
4
- errors: ValidationError[];
5
- statusCode: number;
6
- constructor(errors: ValidationError[]);
7
- serializeErrors: () => ({
8
- message: any;
9
- field: string;
10
- } | {
11
- message: any;
12
- field?: undefined;
13
- })[];
14
- }
1
+ import { ValidationError } from 'express-validator';
2
+ import { CustomError } from './custom-error';
3
+ export declare class RequestValidationError extends CustomError {
4
+ errors: ValidationError[];
5
+ statusCode: number;
6
+ constructor(errors: ValidationError[]);
7
+ serializeErrors: () => ({
8
+ message: any;
9
+ field: string;
10
+ } | {
11
+ message: any;
12
+ field?: undefined;
13
+ })[];
14
+ }
@@ -1,20 +1,38 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RequestValidationError = void 0;
4
- const custom_error_1 = require("./custom-error");
5
- class RequestValidationError extends custom_error_1.CustomError {
6
- constructor(errors) {
7
- super('Validation Error occured!');
8
- this.errors = errors;
9
- this.statusCode = 400;
10
- this.serializeErrors = () => {
11
- return this.errors.map((error) => {
12
- if (error.type === 'field') {
13
- return { message: error.msg, field: error.path };
14
- }
15
- return { message: error.msg };
16
- });
17
- };
18
- }
19
- }
20
- exports.RequestValidationError = RequestValidationError;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.RequestValidationError = void 0;
19
+ var custom_error_1 = require("./custom-error");
20
+ var RequestValidationError = /** @class */ (function (_super) {
21
+ __extends(RequestValidationError, _super);
22
+ function RequestValidationError(errors) {
23
+ var _this = _super.call(this, 'Validation Error occured!') || this;
24
+ _this.errors = errors;
25
+ _this.statusCode = 400;
26
+ _this.serializeErrors = function () {
27
+ return _this.errors.map(function (error) {
28
+ if (error.type === 'field') {
29
+ return { message: error.msg, field: error.path };
30
+ }
31
+ return { message: error.msg };
32
+ });
33
+ };
34
+ return _this;
35
+ }
36
+ return RequestValidationError;
37
+ }(custom_error_1.CustomError));
38
+ exports.RequestValidationError = RequestValidationError;
@@ -0,0 +1,3 @@
1
+ export * from './errors';
2
+ export * from './middlewares';
3
+ export * from './middlewares';
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./errors"), exports);
18
+ __exportStar(require("./middlewares"), exports);
19
+ __exportStar(require("./middlewares"), exports);
@@ -1,4 +1,4 @@
1
- export interface IUserPayload {
2
- id: string;
3
- email: string;
4
- }
1
+ export interface IUserPayload {
2
+ id: string;
3
+ email: string;
4
+ }
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +1,10 @@
1
- import { Request, Response, NextFunction } from 'express';
2
- import { IUserPayload } from '../interfaces';
3
- declare global {
4
- namespace Express {
5
- interface Request {
6
- currentUser?: IUserPayload;
7
- }
8
- }
9
- }
10
- export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void;
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import { IUserPayload } from '../interfaces';
3
+ declare global {
4
+ namespace Express {
5
+ interface Request {
6
+ currentUser?: IUserPayload;
7
+ }
8
+ }
9
+ }
10
+ export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void;
@@ -1,19 +1,19 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.currentUser = void 0;
7
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
- const currentUser = (req, res, next) => {
9
- var _a;
10
- if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt))
11
- return next();
12
- try {
13
- const payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY);
14
- req.currentUser = payload;
15
- }
16
- catch (error) { }
17
- next();
18
- };
19
- exports.currentUser = currentUser;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.currentUser = void 0;
7
+ var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
+ var currentUser = function (req, res, next) {
9
+ var _a;
10
+ if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt))
11
+ return next();
12
+ try {
13
+ var payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY);
14
+ req.currentUser = payload;
15
+ }
16
+ catch (error) { }
17
+ next();
18
+ };
19
+ exports.currentUser = currentUser;
@@ -1,2 +1,2 @@
1
- import { Request, Response, NextFunction } from 'express';
2
- export declare const errorHandler: (err: Error, req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
1
+ import { Request, Response, NextFunction } from 'express';
2
+ export declare const errorHandler: (err: Error, req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
@@ -1,15 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.errorHandler = void 0;
4
- const errors_1 = require("../errors");
5
- const errorHandler = (err, req, res, next) => {
6
- if (err instanceof errors_1.CustomError) {
7
- return res.status(err.statusCode).send({
8
- errors: err.serializeErrors(),
9
- });
10
- }
11
- res.status(400).send({
12
- errors: [{ message: 'Something went wrong' }],
13
- });
14
- };
15
- exports.errorHandler = errorHandler;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errorHandler = void 0;
4
+ var errors_1 = require("../errors");
5
+ var errorHandler = function (err, req, res, next) {
6
+ if (err instanceof errors_1.CustomError) {
7
+ return res.status(err.statusCode).send({
8
+ errors: err.serializeErrors(),
9
+ });
10
+ }
11
+ res.status(400).send({
12
+ errors: [{ message: 'Something went wrong' }],
13
+ });
14
+ };
15
+ exports.errorHandler = errorHandler;
@@ -1,4 +1,4 @@
1
- import { currentUser } from './current-user';
2
- import { errorHandler } from './error-handler';
3
- import { requireAuth } from './require-auth';
4
- export { currentUser, errorHandler, requireAuth };
1
+ import { currentUser } from './current-user';
2
+ import { errorHandler } from './error-handler';
3
+ import { requireAuth } from './require-auth';
4
+ export { currentUser, errorHandler, requireAuth };
@@ -1,9 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireAuth = exports.errorHandler = exports.currentUser = void 0;
4
- const current_user_1 = require("./current-user");
5
- Object.defineProperty(exports, "currentUser", { enumerable: true, get: function () { return current_user_1.currentUser; } });
6
- const error_handler_1 = require("./error-handler");
7
- Object.defineProperty(exports, "errorHandler", { enumerable: true, get: function () { return error_handler_1.errorHandler; } });
8
- const require_auth_1 = require("./require-auth");
9
- Object.defineProperty(exports, "requireAuth", { enumerable: true, get: function () { return require_auth_1.requireAuth; } });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requireAuth = exports.errorHandler = exports.currentUser = void 0;
4
+ var current_user_1 = require("./current-user");
5
+ Object.defineProperty(exports, "currentUser", { enumerable: true, get: function () { return current_user_1.currentUser; } });
6
+ var error_handler_1 = require("./error-handler");
7
+ Object.defineProperty(exports, "errorHandler", { enumerable: true, get: function () { return error_handler_1.errorHandler; } });
8
+ var require_auth_1 = require("./require-auth");
9
+ Object.defineProperty(exports, "requireAuth", { enumerable: true, get: function () { return require_auth_1.requireAuth; } });
@@ -1,2 +1,2 @@
1
- import { Request, Response, NextFunction } from 'express';
2
- export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void;
1
+ import { Request, Response, NextFunction } from 'express';
2
+ export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void;
@@ -1,11 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireAuth = void 0;
4
- const not_authorized_1 = require("../errors/not-authorized");
5
- const requireAuth = (req, res, next) => {
6
- if (!req.currentUser) {
7
- throw new not_authorized_1.NotAuthorizedError();
8
- }
9
- next();
10
- };
11
- exports.requireAuth = requireAuth;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requireAuth = void 0;
4
+ var not_authorized_1 = require("../errors/not-authorized");
5
+ var requireAuth = function (req, res, next) {
6
+ if (!req.currentUser) {
7
+ throw new not_authorized_1.NotAuthorizedError();
8
+ }
9
+ next();
10
+ };
11
+ exports.requireAuth = requireAuth;
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "bemoore-be-ticketing-common",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
- "dist"
8
+ "dist/**/*"
9
9
  ],
10
10
  "scripts": {
11
- "build": "tsc"
11
+ "build": "tsc --skipLibCheck"
12
12
  },
13
13
  "keywords": [
14
14
  "typescript",