biz-slide-core 1.2.30 → 1.2.32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. package/package.json +2 -4
  2. package/{dist/utilities → utilities}/index.js +0 -1
  3. package/dist/package-lock.json +0 -1770
  4. package/dist/package.json +0 -23
  5. package/src/entity/config.enity.ts +0 -18
  6. package/src/entity/image.entity.ts +0 -32
  7. package/src/entity/index.ts +0 -16
  8. package/src/entity/logs.entity.ts +0 -20
  9. package/src/entity/png-svg.entity.ts +0 -42
  10. package/src/entity/ppt-event.entity.ts +0 -23
  11. package/src/entity/ppt-slide.entity.ts +0 -29
  12. package/src/entity/ppt.entity.ts +0 -48
  13. package/src/entity/slide-layout.entity.ts +0 -22
  14. package/src/entity/slide.entity.ts +0 -47
  15. package/src/entity/socket.entity.ts +0 -20
  16. package/src/entity/template-type.entity.ts +0 -57
  17. package/src/entity/template.entity.ts +0 -38
  18. package/src/entity/training-queue.entity.ts +0 -26
  19. package/src/entity/user.entity.ts +0 -24
  20. package/src/index.ts +0 -6
  21. package/src/middleware/authentication.ts +0 -68
  22. package/src/middleware/index.ts +0 -3
  23. package/src/middleware/role.ts +0 -5
  24. package/src/middleware/schemaValidate.ts +0 -20
  25. package/src/resHandler/errorHandler.ts +0 -65
  26. package/src/resHandler/index.ts +0 -2
  27. package/src/resHandler/successHandler.ts +0 -11
  28. package/src/types/IController.ts +0 -6
  29. package/src/types/IRequest.ts +0 -8
  30. package/src/types/index.ts +0 -11
  31. package/src/utilities/callWithRetries.ts +0 -9
  32. package/src/utilities/createFolder.ts +0 -11
  33. package/src/utilities/encryptionUtils.ts +0 -26
  34. package/src/utilities/hasAbusiveWords.ts +0 -33
  35. package/src/utilities/index.ts +0 -6
  36. package/src/utilities/pngSvgCategories.ts +0 -167
  37. package/src/utilities/sendEmail.ts +0 -30
  38. package/tsconfig.json +0 -11
  39. /package/{dist/entity → entity}/config.enity.js +0 -0
  40. /package/{dist/entity → entity}/image.entity.js +0 -0
  41. /package/{dist/entity → entity}/index.js +0 -0
  42. /package/{dist/entity → entity}/logs.entity.js +0 -0
  43. /package/{dist/entity → entity}/png-svg.entity.js +0 -0
  44. /package/{dist/entity → entity}/ppt-event.entity.js +0 -0
  45. /package/{dist/entity → entity}/ppt-slide.entity.js +0 -0
  46. /package/{dist/entity → entity}/ppt.entity.js +0 -0
  47. /package/{dist/entity → entity}/slide-layout.entity.js +0 -0
  48. /package/{dist/entity → entity}/slide.entity.js +0 -0
  49. /package/{dist/entity → entity}/socket.entity.js +0 -0
  50. /package/{dist/entity → entity}/template-type.entity.js +0 -0
  51. /package/{dist/entity → entity}/template.entity.js +0 -0
  52. /package/{dist/entity → entity}/training-queue.entity.js +0 -0
  53. /package/{dist/entity → entity}/user.entity.js +0 -0
  54. /package/{dist/index.js → index.js} +0 -0
  55. /package/{dist/middleware → middleware}/authentication.js +0 -0
  56. /package/{dist/middleware → middleware}/index.js +0 -0
  57. /package/{dist/middleware → middleware}/role.js +0 -0
  58. /package/{dist/middleware → middleware}/schemaValidate.js +0 -0
  59. /package/{dist/resHandler → resHandler}/errorHandler.js +0 -0
  60. /package/{dist/resHandler → resHandler}/index.js +0 -0
  61. /package/{dist/resHandler → resHandler}/successHandler.js +0 -0
  62. /package/{dist/types → types}/IController.js +0 -0
  63. /package/{dist/types → types}/IRequest.js +0 -0
  64. /package/{dist/types → types}/index.js +0 -0
  65. /package/{dist/utilities → utilities}/callWithRetries.js +0 -0
  66. /package/{dist/utilities → utilities}/createFolder.js +0 -0
  67. /package/{dist/utilities → utilities}/encryptionUtils.js +0 -0
  68. /package/{dist/utilities → utilities}/hasAbusiveWords.js +0 -0
  69. /package/{dist/utilities → utilities}/pngSvgCategories.js +0 -0
  70. /package/{dist/utilities → utilities}/sendEmail.js +0 -0
package/dist/package.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "name": "biz-slide-core",
3
- "version": "1.2.30",
4
- "description": "",
5
- "main": "dist/index.js",
6
- "scripts": {
7
- "build": "tsc",
8
- "test": "echo \"Error: no test specified\" && exit 1"
9
- },
10
- "keywords": [],
11
- "author": "",
12
- "license": "ISC",
13
- "dependencies": {
14
- "express": "^4.18.2",
15
- "joi": "^17.11.0",
16
- "jsonwebtoken": "^9.0.2",
17
- "typescript": "^5.3.3"
18
- },
19
- "devDependencies": {
20
- "@types/express": "^4.17.21",
21
- "@types/jsonwebtoken": "^9.0.5"
22
- }
23
- }
@@ -1,18 +0,0 @@
1
- import { Schema, model, Types } from "mongoose";
2
-
3
- export interface IConfigSchema {
4
- configType: string;
5
- value: string;
6
- }
7
-
8
- const CongigSchema = new Schema<IConfigSchema>(
9
- {
10
- configType: { type: String, required: true },
11
- value: { type: String, required: true },
12
- },
13
- {
14
- timestamps: true,
15
- }
16
- );
17
-
18
- export const ConfigModel = model<IConfigSchema>("config", CongigSchema);
@@ -1,32 +0,0 @@
1
- import { Schema, model, Types } from "mongoose";
2
-
3
- export interface IImageSchema {
4
- focusPoint: { x: number, y: number };
5
- url: string;
6
- radius: string;
7
- keywords: [string] | null;
8
- title: string;
9
- aliasName: string;
10
- userId: Types.ObjectId;
11
- createdAt: Date;
12
- updatedAt: Date;
13
- deletedAt: Date;
14
- }
15
-
16
- const ImageSchema = new Schema<IImageSchema>(
17
- {
18
- focusPoint: { x: Number, y: Number },
19
- url: { type: String, required: true },
20
- radius: { type: String, required: true },
21
- aliasName: { type: String, required: true },
22
- keywords: { type: [String], default: [] },
23
- title: { type: String, required: true },
24
- userId: { type: Schema.Types.ObjectId, ref: "user" },
25
- deletedAt: { type: Date, default: null },
26
- },
27
- {
28
- timestamps: true,
29
- }
30
- );
31
-
32
- export const ImageModel = model<IImageSchema>("image", ImageSchema);
@@ -1,16 +0,0 @@
1
- export * from "./image.entity";
2
- export * from "./png-svg.entity";
3
- export * from "./ppt-event.entity";
4
- export * from "./ppt-slide.entity";
5
- export * from "./ppt.entity";
6
- export * from "./slide-layout.entity";
7
- export * from "./slide.entity";
8
- export * from "./socket.entity";
9
- export * from "./template.entity";
10
- export * from "./template-type.entity";
11
- export * from "./user.entity";
12
- export * from "./training-queue.entity";
13
- export * from "./config.enity";
14
- export * from "./logs.entity";
15
-
16
-
@@ -1,20 +0,0 @@
1
- import { Schema, model } from "mongoose";
2
-
3
- export interface ILogsSchema {
4
- type: string;
5
- event: string;
6
- message: string;
7
- }
8
-
9
- const LogsSchema = new Schema<ILogsSchema>(
10
- {
11
- type: { type: String, required: true },
12
- event: { type: String, required: true },
13
- message: { type: String, required: true },
14
- },
15
- {
16
- timestamps: true,
17
- }
18
- );
19
-
20
- export const LogsModel = model<ILogsSchema>("logs", LogsSchema);
@@ -1,42 +0,0 @@
1
- import { Schema, model } from "mongoose";
2
-
3
- export interface IPngSvgSchema {
4
- title: string;
5
- styleCategory: string;
6
- styleSubCategory: string;
7
- colors: Array<string>;
8
- userId: string;
9
- isLocked?: boolean;
10
- isCompleted?: boolean;
11
- isDownloaded?: boolean;
12
- hasError?: boolean;
13
- optionsDownloaded: any;
14
- userReaction: number;
15
- userFeedback: string;
16
- createdAt?: Date;
17
- updatedAt?: Date;
18
- deletedAt?: Date;
19
- }
20
-
21
- const PngSvgSchema = new Schema<IPngSvgSchema>(
22
- {
23
- deletedAt: { type: Date, default: null },
24
- isLocked: { type: Boolean, default: false },
25
- optionsDownloaded: Schema.Types.Mixed,
26
- isDownloaded: { type: Boolean, default: false },
27
- isCompleted: { type: Boolean, default: false },
28
- hasError: { type: Boolean, default: false },
29
- userId: { type: String, default: null },
30
- userReaction: { type: Number, default: 0 },
31
- userFeedback: { type: String, default: null },
32
- title: { type: String, default: null },
33
- styleCategory: { type: String, default: null },
34
- styleSubCategory: { type: String, default: null },
35
- colors: { type: [{ type: String, default: null }], default: null, _id: false }
36
- },
37
- {
38
- timestamps: true,
39
- }
40
- );
41
-
42
- export const PngSvgModel = model<IPngSvgSchema>("png-svg", PngSvgSchema);
@@ -1,23 +0,0 @@
1
- import { Schema, model, Types } from "mongoose";
2
-
3
-
4
- export interface IPPTEventSchema {
5
- pptRef: Types.ObjectId;
6
- event: string;
7
- message: string;
8
- createdAt?: Date;
9
- updatedAt?: Date;
10
- }
11
-
12
- const PPTEventSchema = new Schema<IPPTEventSchema>(
13
- {
14
- pptRef: { type: Schema.Types.ObjectId, ref: 'ppt' },
15
- message: { type: String, default: null },
16
- event: { type: String, default: null },
17
- },
18
- {
19
- timestamps: true,
20
- }
21
- );
22
-
23
- export const PPTSlideEventModel = model<IPPTEventSchema>("ppt-event", PPTEventSchema);
@@ -1,29 +0,0 @@
1
- import { Schema, model, Types } from "mongoose";
2
- export interface IPPTSlideSchema {
3
- pptRef: Types.ObjectId;
4
- slideRef: Types.ObjectId;
5
- slideLayoutRef: Types.ObjectId;
6
- title: string;
7
- rawData: string;
8
- images: string;
9
- createdAt?: Date;
10
- updatedAt?: Date;
11
- deletedAt?: Date;
12
- }
13
-
14
- const PPTSlideSchema = new Schema<IPPTSlideSchema>(
15
- {
16
- deletedAt: { type: Date, default: null },
17
- pptRef: { type: Schema.Types.ObjectId, ref: 'ppt' },
18
- slideRef: { type: Schema.Types.ObjectId, ref: 'slide' },
19
- slideLayoutRef: { type: Schema.Types.ObjectId, ref: 'slide-layout' },
20
- title: { type: String, default: null },
21
- rawData: { type: String, default: "{}" },
22
- images: { type: String, default: "{}" },
23
- },
24
- {
25
- timestamps: true,
26
- }
27
- );
28
-
29
- export const PPTSlideModel = model<IPPTSlideSchema>("ppt-slide", PPTSlideSchema);
@@ -1,48 +0,0 @@
1
- import { Schema, model, Types } from "mongoose";
2
-
3
- export interface IPPTSchema {
4
- systemGeneratedtopics: Array<string>;
5
- userSelectedTopics: Array<string>;
6
- colors: Array<string>;
7
- slideRefs: Types.ObjectId[];
8
- templateId: Types.ObjectId;
9
- templateTypeId: Types.ObjectId;
10
- prompt: string;
11
- userId: string;
12
- userReaction: number;
13
- userFeedback: string;
14
- questions: Array<string>;
15
- isLocked?: boolean;
16
- fileCreated?: boolean;
17
- isCompleted?: boolean;
18
- createdAt?: Date;
19
- updatedAt?: Date;
20
- deletedAt?: Date;
21
- hasError?: boolean;
22
- }
23
-
24
- const PPTSchema = new Schema<IPPTSchema>(
25
- {
26
- deletedAt: { type: Date, default: null },
27
- isLocked: { type: Boolean, default: false },
28
- isCompleted: { type: Boolean, default: false },
29
- fileCreated: { type: Boolean, default: false },
30
- userId: { type: String, default: null },
31
- templateTypeId: { type: Schema.Types.ObjectId, ref: "template-type" },
32
- systemGeneratedtopics: { type: [String], default: [], _id: false },
33
- userSelectedTopics: { type: [String], default: [], _id: false },
34
- userReaction: { type: Number, default: 0 },
35
- userFeedback: { type: String, default: null },
36
- questions: { type: [String], default: [], _id: false },
37
- colors: { type: [String], default: [], _id: false },
38
- prompt: { type: String, default: null },
39
- templateId: { type: Schema.Types.ObjectId, ref: 'template' },
40
- hasError: { type: Boolean, default: false },
41
- slideRefs: {type: [{ type: Schema.Types.ObjectId, ref: 'ppt-slide' }], default: [], _id: false}
42
- },
43
- {
44
- timestamps: true,
45
- }
46
- );
47
-
48
- export const PPTModel = model<IPPTSchema>("ppt", PPTSchema);
@@ -1,22 +0,0 @@
1
- import { Schema, model, Types } from "mongoose";
2
-
3
- export interface ISlideLayoutSchema {
4
- name: string;
5
- templateTypeId: Types.ObjectId;
6
- createdAt: Date;
7
- updatedAt: Date;
8
- deletedAt: Date;
9
- }
10
-
11
- const SlideLayoutSchema = new Schema<ISlideLayoutSchema>(
12
- {
13
- name: { type: String, default: "", required: true },
14
- templateTypeId: { type: Schema.Types.ObjectId, ref: "template-type" },
15
- deletedAt: { type: Date, default: null },
16
- },
17
- {
18
- timestamps: true,
19
- }
20
- );
21
-
22
- export const SlideLayoutModel = model<ISlideLayoutSchema>("slide-layout", SlideLayoutSchema);
@@ -1,47 +0,0 @@
1
- import { Schema, model, Types } from "mongoose";
2
-
3
- interface layer {
4
- metaType: String;
5
- optionsMeta: String;
6
- chatMeta: string;
7
- }
8
-
9
- const layerSchema = new Schema<layer>({
10
- metaType: { type: String, enum: ['text', 'image', 'shape', 'list', 'table'] },
11
- optionsMeta: { type: String },
12
- chatMeta: { type: String },
13
- }, {
14
- timestamps: false,
15
- _id: false
16
- })
17
-
18
- export interface ISlideSchema {
19
- name: string;
20
- postfix: string;
21
- rules: string;
22
- slideLayoutId: Types.ObjectId;
23
- templateId: Types.ObjectId;
24
- layers: layer[];
25
- createdAt: Date;
26
- updatedAt: Date;
27
- deletedAt: Date;
28
- isDelete: boolean;
29
- }
30
-
31
- const SlideSchema = new Schema<ISlideSchema>(
32
- {
33
- name: { type: String, default: "", required: true },
34
- postfix: { type: String, default: "" },
35
- rules: { type: String, default: "" },
36
- layers: [layerSchema],
37
- slideLayoutId: { type: Schema.Types.ObjectId, ref: "slide-layout" },
38
- templateId: { type: Schema.Types.ObjectId, ref: "template" },
39
- deletedAt: { type: Date, default: null },
40
- isDelete: { type: Boolean, default: false }
41
- },
42
- {
43
- timestamps: true,
44
- }
45
- );
46
-
47
- export const SlideModel = model<ISlideSchema>("slide", SlideSchema);
@@ -1,20 +0,0 @@
1
- import { Schema, model, Types } from "mongoose";
2
-
3
- export interface ISocketSchema {
4
- userId: string;
5
- socketIds: Array<string>;
6
- createdAt?: Date;
7
- updatedAt?: Date;
8
- }
9
-
10
- const SocketSchema = new Schema<ISocketSchema>(
11
- {
12
- userId: { type: String, default: null },
13
- socketIds: { type: [String], default: [] }
14
- },
15
- {
16
- timestamps: true,
17
- }
18
- );
19
-
20
- export const SocketModel = model<ISocketSchema>("socket", SocketSchema);
@@ -1,57 +0,0 @@
1
- import { Schema, model } from "mongoose";
2
-
3
- interface IQuestionSchema {
4
- question: string;
5
- systemMessage: string;
6
- keyId: string;
7
- placeholder: string;
8
- }
9
-
10
- export interface ITemplateLayout {
11
- title: string;
12
- layoutType: string;
13
- }
14
- export interface ITemplateTypeSchema{
15
- name: string;
16
- questions: Array<IQuestionSchema>;
17
- predefineSystemMessage: string;
18
- layouts: Array<ITemplateLayout>;
19
- createdAt: Date;
20
- updatedAt: Date;
21
- deletedAt: Date;
22
- suggestionPrompts: Array<string>;
23
- }
24
-
25
- const questionSchema = new Schema<IQuestionSchema>({
26
- question: { type: String },
27
- systemMessage: { type: String },
28
- keyId: { type: String },
29
- placeholder: { type: String },
30
- }, {
31
- timestamps: false,
32
- _id: false
33
- })
34
-
35
- const layoutsSchema = new Schema<ITemplateLayout>({
36
- title: { type: String },
37
- layoutType: { type: String },
38
- }, {
39
- timestamps: false,
40
- _id: false
41
- })
42
-
43
- const TemplateTypeSchema = new Schema<ITemplateTypeSchema>(
44
- {
45
- name: { type: String, default: "", required: true },
46
- questions: [questionSchema],
47
- predefineSystemMessage: {type: String, default: ""},
48
- layouts: [layoutsSchema],
49
- suggestionPrompts: {type: [String], default: [], _id: false},
50
- deletedAt: { type: Date, default: null },
51
- },
52
- {
53
- timestamps: true,
54
- }
55
- );
56
-
57
- export const TemplateTypeModel = model<ITemplateTypeSchema>("template-type", TemplateTypeSchema);
@@ -1,38 +0,0 @@
1
- import { Schema, model, Types } from "mongoose";
2
-
3
- export interface ITemplateSchema{
4
- name: string;
5
- templateTypeId: Types.ObjectId;
6
- createdAt: Date,
7
- updatedAt: Date,
8
- deletedAt: Date,
9
- defaultColorPallete: Array<string>;
10
- colorPalletes: Array<Array<string>>;
11
- staticImageDir: string;
12
- published: boolean;
13
- }
14
-
15
- const TemplateSchema = new Schema<ITemplateSchema>(
16
- {
17
- name: { type: String, default: "", required: true },
18
- published: { type: Boolean, default: false },
19
- templateTypeId: { type: Schema.Types.ObjectId, ref: "template-type" },
20
- defaultColorPallete: { type: [String], default: [], _id: false },
21
- colorPalletes: {
22
- type: [
23
- {
24
- type: [String],
25
- default: [],
26
- _id: false
27
- }
28
- ], default: [], _id: false
29
- },
30
- deletedAt: { type: Date, default: null },
31
- staticImageDir: { type: String, default: "", required: true }
32
- },
33
- {
34
- timestamps: true,
35
- }
36
- );
37
-
38
- export const TemplateModel = model<ITemplateSchema>("template", TemplateSchema);
@@ -1,26 +0,0 @@
1
- import { Schema, model, Types } from "mongoose";
2
-
3
- interface ITrainingQueue {
4
- filename: string,
5
- isCompleted: boolean,
6
- isLocked: boolean,
7
- userId: Types.ObjectId;
8
- createdAt: Date,
9
- updatedAt: Date,
10
- deletedAt: Date
11
- }
12
-
13
- const TrainingQueueSchema = new Schema<ITrainingQueue>(
14
- {
15
- filename: { type: String, default: null },
16
- isCompleted: { type: Boolean, default: false },
17
- userId: { type: Schema.Types.ObjectId, ref: "user" },
18
- isLocked: { type: Boolean, default: false },
19
- deletedAt: { type: Date, default: null},
20
- },
21
- {
22
- timestamps: true,
23
- }
24
- );
25
-
26
- export const TrainingQueueModel = model<ITrainingQueue>("training-queue", TrainingQueueSchema);
@@ -1,24 +0,0 @@
1
- import { Schema, model } from "mongoose";
2
-
3
- interface IUser {
4
- email: string | null;
5
- password: string,
6
- role: string,
7
- createdAt: Date,
8
- updatedAt: Date,
9
- deletedAt: Date
10
- }
11
-
12
- const UserSchema = new Schema<IUser>(
13
- {
14
- email: { type: String, unique: true, sparse: true },
15
- password: { type: String, default: null },
16
- role: { type: String, default: null },
17
- deletedAt: { type: Date, default: null},
18
- },
19
- {
20
- timestamps: true,
21
- }
22
- );
23
-
24
- export const UserModel = model<IUser>("user", UserSchema);
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- export * from "./entity";
2
- export * from "./middleware";
3
- export * from "./resHandler";
4
- export * from "./types";
5
-
6
- export * from "./utilities";
@@ -1,68 +0,0 @@
1
- import { Response, NextFunction } from "express";
2
- import { verifyUid } from "../utilities";
3
- import { IRequest } from "../types";
4
- import { UserModel } from "../entity";
5
-
6
-
7
- const authorize = (roles: string[]) => {
8
- return async function (req: IRequest, res: Response, next: NextFunction) {
9
- if (!req.headers.authorization) {
10
- return res.status(401).json({ message: 'Unauthorized' })
11
- }
12
- if (!roles.length) {
13
- return res.status(401).json({ message: 'Unauthorized' })
14
- }
15
- if (req.headers.authorization) {
16
- const token = await verifyUid(req.headers.authorization);
17
- if (!token) {
18
- return res.status(401).json({ message: 'Session Expired' })
19
- }
20
-
21
- let user: any = await UserModel.findOne({ email: token.value.email })
22
-
23
- if (!user) {
24
- return res.status(401).json({ message: 'No User Found' })
25
- }
26
-
27
- const hasAccess = roles.find(role => role === user.role);
28
-
29
- if (!hasAccess) {
30
- return res.status(403).json({ message: 'Forbbiden' })
31
- }
32
-
33
- const { createdAt, updatedAt, deletedAt, password, ...rest } = user.toObject();
34
-
35
- req.user = {...rest, userId: rest.email};
36
- next();
37
- }
38
- }
39
- }
40
-
41
- const authorizeWithSlideApp = () => {
42
- return async function (req: IRequest, res: Response, next: NextFunction) {
43
- if (!req.headers.authorization) {
44
- return res.status(401).json({ message: 'Unauthorized' })
45
- }
46
-
47
- if (req.headers.authorization) {
48
- const token = await verifyUid(req.headers.authorization);
49
- if (!token) {
50
- return res.status(401).json({ message: 'Session Expired' })
51
- }
52
-
53
- const userId = token?.customer_id || token?.value?.email;
54
-
55
- if(!userId) {
56
- return res.status(401).json({ message: 'userId not found' })
57
- }
58
-
59
- req.user = {
60
- userId: userId
61
- }
62
-
63
- next();
64
- }
65
- }
66
- }
67
-
68
- export {authorize, authorizeWithSlideApp};
@@ -1,3 +0,0 @@
1
- export * from "./authentication";
2
- export * from "./role";
3
- export * from "./schemaValidate";
@@ -1,5 +0,0 @@
1
- export const ROLES = {
2
- User: 'User',
3
- Admin: 'Admin',
4
- SuperAdmin: 'SuperAdmin'
5
- }
@@ -1,20 +0,0 @@
1
- import { NextFunction, Response } from "express";
2
- import Joi from 'joi';
3
-
4
- import { IRequest } from "../types";
5
-
6
- export const validateSchema = (schema: Joi.ObjectSchema<any>) => {
7
- return async function (req: IRequest, res: Response, next: NextFunction) {
8
-
9
- const { error } = schema.validate(req.body, { abortEarly: false });
10
-
11
- if(error) {
12
- const errorMessage = error.details.map((err) => err.message).join(', ');
13
- return res.status(400).json({ message: errorMessage });
14
- } else {
15
- next();
16
- }
17
- }
18
- }
19
-
20
-
@@ -1,65 +0,0 @@
1
- import { Request, Response, NextFunction } from 'express';
2
-
3
- export class BadRequestError extends Error {
4
- constructor(message: string) {
5
- super(message);
6
- Object.setPrototypeOf(this, BadRequestError.prototype);
7
- this.name = 'BadRequestError';
8
- }
9
- }
10
-
11
- export class NotFoundRequestError extends Error {
12
- constructor(message: string) {
13
- super(message);
14
- Object.setPrototypeOf(this, NotFoundRequestError.prototype);
15
- this.name = 'NotFoundRequestError';
16
- }
17
- }
18
-
19
- export class CustomRequestError {
20
- name: string;
21
- message: {
22
- title: string,
23
- description: string
24
- };
25
-
26
- constructor(title: string, description: string) {
27
- this.name = 'CustomRequestError';
28
- this.message = {
29
- title,
30
- description
31
- };
32
- }
33
- }
34
-
35
-
36
-
37
- // Custom error handler middleware
38
- export const errorHandler = (
39
- err: Error,
40
- req: Request,
41
- res: Response,
42
- next: NextFunction
43
- ) => {
44
- console.error(err.stack); // Log the error for debugging
45
-
46
- let statusCode = 500; // Default status code
47
- let errorMessage = 'Internal Server Error'; // Default error message
48
-
49
- if (err instanceof BadRequestError) {
50
- statusCode = 400;
51
- errorMessage = err.message;
52
- } else if(err instanceof NotFoundRequestError) {
53
- statusCode = 404;
54
- errorMessage = err.message;
55
- } else if(err instanceof CustomRequestError) {
56
- statusCode = 422;
57
- errorMessage = err.message;
58
- }
59
-
60
- // Send an error response
61
- res.status(statusCode).json({
62
- message: errorMessage,
63
- error: err.name // Optionally send the error name/type
64
- });
65
- };
@@ -1,2 +0,0 @@
1
- export * from "./errorHandler";
2
- export * from "./successHandler";