biz-slide-core 1.1.1 → 1.1.3
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/{dist/middleware → middleware}/authentication.js +13 -3
- package/package.json +1 -1
- package/src/entity/image.entity.ts +0 -32
- package/src/entity/index.ts +0 -10
- package/src/entity/png-svg.entity.ts +0 -34
- package/src/entity/ppt-event.entity.ts +0 -23
- package/src/entity/ppt-slide.entity.ts +0 -31
- package/src/entity/ppt.entity.ts +0 -60
- package/src/entity/slide-layout.entity.ts +0 -24
- package/src/entity/slide.entity.ts +0 -47
- package/src/entity/socket.entity.ts +0 -22
- package/src/entity/template.entity.ts +0 -24
- package/src/entity/user.entity.ts +0 -26
- package/src/index.ts +0 -5
- package/src/middleware/authentication.ts +0 -64
- package/src/middleware/index.ts +0 -3
- package/src/middleware/role.ts +0 -5
- package/src/middleware/schemaValidate.ts +0 -20
- package/src/resHandler/errorHandler.ts +0 -44
- package/src/resHandler/index.ts +0 -2
- package/src/resHandler/successHandler.ts +0 -11
- package/src/types/IController.ts +0 -6
- package/src/types/IRequest.ts +0 -8
- package/src/types/index.ts +0 -11
- package/src/utilities/callWithRetries.ts +0 -9
- package/src/utilities/createFolder.ts +0 -12
- package/src/utilities/encryptionUtils.ts +0 -26
- package/src/utilities/index.ts +0 -4
- package/tsconfig.json +0 -11
- /package/{dist/entity → entity}/image.entity.js +0 -0
- /package/{dist/entity → entity}/index.js +0 -0
- /package/{dist/entity → entity}/png-svg.entity.js +0 -0
- /package/{dist/entity → entity}/ppt-event.entity.js +0 -0
- /package/{dist/entity → entity}/ppt-slide.entity.js +0 -0
- /package/{dist/entity → entity}/ppt.entity.js +0 -0
- /package/{dist/entity → entity}/slide-layout.entity.js +0 -0
- /package/{dist/entity → entity}/slide.entity.js +0 -0
- /package/{dist/entity → entity}/socket.entity.js +0 -0
- /package/{dist/entity → entity}/template.entity.js +0 -0
- /package/{dist/entity → entity}/user.entity.js +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/middleware → middleware}/index.js +0 -0
- /package/{dist/middleware → middleware}/role.js +0 -0
- /package/{dist/middleware → middleware}/schemaValidate.js +0 -0
- /package/{dist/resHandler → resHandler}/errorHandler.js +0 -0
- /package/{dist/resHandler → resHandler}/index.js +0 -0
- /package/{dist/resHandler → resHandler}/successHandler.js +0 -0
- /package/{dist/types → types}/IController.js +0 -0
- /package/{dist/types → types}/IRequest.js +0 -0
- /package/{dist/types → types}/index.js +0 -0
- /package/{dist/utilities → utilities}/callWithRetries.js +0 -0
- /package/{dist/utilities → utilities}/createFolder.js +0 -0
- /package/{dist/utilities → utilities}/encryptionUtils.js +0 -0
- /package/{dist/utilities → utilities}/index.js +0 -0
@@ -1,4 +1,15 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
3
|
+
__assign = Object.assign || function(t) {
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
+
s = arguments[i];
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
+
t[p] = s[p];
|
8
|
+
}
|
9
|
+
return t;
|
10
|
+
};
|
11
|
+
return __assign.apply(this, arguments);
|
12
|
+
};
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -81,7 +92,7 @@ var authorize = function (roles) {
|
|
81
92
|
return [2 /*return*/, res.status(403).json({ message: 'Forbbiden' })];
|
82
93
|
}
|
83
94
|
_a = user_1.toObject(), createdAt = _a.createdAt, updatedAt = _a.updatedAt, deletedAt = _a.deletedAt, password = _a.password, rest = __rest(_a, ["createdAt", "updatedAt", "deletedAt", "password"]);
|
84
|
-
req.user = rest;
|
95
|
+
req.user = __assign(__assign({}, rest), { userId: rest.email });
|
85
96
|
next();
|
86
97
|
_b.label = 3;
|
87
98
|
case 3: return [2 /*return*/];
|
@@ -108,9 +119,8 @@ var authorizeWithSlideApp = function () {
|
|
108
119
|
if (!token) {
|
109
120
|
return [2 /*return*/, res.status(401).json({ message: 'Session Expired' })];
|
110
121
|
}
|
111
|
-
// token.value.customerid
|
112
122
|
req.user = {
|
113
|
-
userId:
|
123
|
+
userId: token.value.email || token.value.customer_id
|
114
124
|
};
|
115
125
|
next();
|
116
126
|
_a.label = 2;
|
package/package.json
CHANGED
@@ -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
|
-
userId: Types.ObjectId;
|
10
|
-
createdAt: Date;
|
11
|
-
updatedAt: Date;
|
12
|
-
deletedAt: Date;
|
13
|
-
}
|
14
|
-
|
15
|
-
const ImageSchema = new Schema<IImageSchema>(
|
16
|
-
{
|
17
|
-
focusPoint: { x: Number, y: Number },
|
18
|
-
url: { type: String, required: true },
|
19
|
-
radius: { type: String, required: true },
|
20
|
-
keywords: { type: [String], default: [] },
|
21
|
-
title: { type: String, required: true },
|
22
|
-
userId: { type: Schema.Types.ObjectId, ref: "user" },
|
23
|
-
createdAt: { type: Date, default: Date.now() },
|
24
|
-
updatedAt: { type: Date, default: Date.now() },
|
25
|
-
deletedAt: { type: Date, default: null },
|
26
|
-
},
|
27
|
-
{
|
28
|
-
timestamps: true,
|
29
|
-
}
|
30
|
-
);
|
31
|
-
|
32
|
-
export const ImageModel = model<IImageSchema>("image", ImageSchema);
|
package/src/entity/index.ts
DELETED
@@ -1,10 +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 "./user.entity";
|
@@ -1,34 +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
|
-
createdAt?: Date;
|
12
|
-
updatedAt?: Date;
|
13
|
-
deletedAt?: Date;
|
14
|
-
}
|
15
|
-
|
16
|
-
const PngSvgSchema = new Schema<IPngSvgSchema>(
|
17
|
-
{
|
18
|
-
createdAt: { type: Date, default: Date.now() },
|
19
|
-
updatedAt: { type: Date, default: Date.now() },
|
20
|
-
deletedAt: { type: Date, default: null },
|
21
|
-
isLocked: { type: Boolean, default: false },
|
22
|
-
isCompleted: { type: Boolean, default: false },
|
23
|
-
userId: { type: String, default: null },
|
24
|
-
title: { type: String, default: null },
|
25
|
-
styleCategory: { type: String, default: null },
|
26
|
-
styleSubCategory: { type: String, default: null },
|
27
|
-
colors: { type: [{ type: String, default: null }], default: null, _id: false }
|
28
|
-
},
|
29
|
-
{
|
30
|
-
timestamps: true,
|
31
|
-
}
|
32
|
-
);
|
33
|
-
|
34
|
-
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
|
-
message: string;
|
7
|
-
createdAt?: Date;
|
8
|
-
updatedAt?: Date;
|
9
|
-
}
|
10
|
-
|
11
|
-
const PPTEventSchema = new Schema<IPPTEventSchema>(
|
12
|
-
{
|
13
|
-
createdAt: { type: Date, default: Date.now() },
|
14
|
-
updatedAt: { type: Date, default: Date.now() },
|
15
|
-
pptRef: { type: Schema.Types.ObjectId, ref: 'ppt' },
|
16
|
-
message: { type: String, default: null }
|
17
|
-
},
|
18
|
-
{
|
19
|
-
timestamps: true,
|
20
|
-
}
|
21
|
-
);
|
22
|
-
|
23
|
-
export const PPTSlideEventModel = model<IPPTEventSchema>("ppt-event", PPTEventSchema);
|
@@ -1,31 +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
|
-
createdAt: { type: Date, default: Date.now() },
|
17
|
-
updatedAt: { type: Date, default: Date.now() },
|
18
|
-
deletedAt: { type: Date, default: null },
|
19
|
-
pptRef: { type: Schema.Types.ObjectId, ref: 'ppt' },
|
20
|
-
slideRef: { type: Schema.Types.ObjectId, ref: 'slide' },
|
21
|
-
slideLayoutRef: { type: Schema.Types.ObjectId, ref: 'slide-layout' },
|
22
|
-
title: { type: String, default: null },
|
23
|
-
rawData: { type: String, default: "{}" },
|
24
|
-
images: { type: String, default: "{}" },
|
25
|
-
},
|
26
|
-
{
|
27
|
-
timestamps: true,
|
28
|
-
}
|
29
|
-
);
|
30
|
-
|
31
|
-
export const PPTSlideModel = model<IPPTSlideSchema>("ppt-slide", PPTSlideSchema);
|
package/src/entity/ppt.entity.ts
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
import { Schema, model, Types } from "mongoose";
|
2
|
-
|
3
|
-
interface IPPTQuestions {
|
4
|
-
question: string;
|
5
|
-
answer: string;
|
6
|
-
}
|
7
|
-
|
8
|
-
const questionSchema = new Schema<IPPTQuestions>({
|
9
|
-
question: { type: String},
|
10
|
-
answer : { type : String }
|
11
|
-
}, {
|
12
|
-
timestamps: false,
|
13
|
-
_id: false
|
14
|
-
})
|
15
|
-
|
16
|
-
export interface IPPTQuestionSchema {
|
17
|
-
question: string;
|
18
|
-
answer: string;
|
19
|
-
}
|
20
|
-
|
21
|
-
export interface IPPTSchema {
|
22
|
-
systemGeneratedtopics: Array<string>;
|
23
|
-
colors: Array<string>;
|
24
|
-
slideRefs: Types.ObjectId[];
|
25
|
-
templateRef: Types.ObjectId;
|
26
|
-
template_type: string;
|
27
|
-
prompt: string;
|
28
|
-
userId: string;
|
29
|
-
questions: IPPTQuestions[];
|
30
|
-
isLocked?: boolean;
|
31
|
-
fileCreated?: boolean;
|
32
|
-
isCompleted?: boolean;
|
33
|
-
createdAt?: Date;
|
34
|
-
updatedAt?: Date;
|
35
|
-
deletedAt?: Date;
|
36
|
-
}
|
37
|
-
|
38
|
-
const PPTSchema = new Schema<IPPTSchema>(
|
39
|
-
{
|
40
|
-
createdAt: { type: Date, default: Date.now() },
|
41
|
-
updatedAt: { type: Date, default: Date.now() },
|
42
|
-
deletedAt: { type: Date, default: null },
|
43
|
-
isLocked: { type: Boolean, default: false },
|
44
|
-
isCompleted: { type: Boolean, default: false },
|
45
|
-
fileCreated: { type: Boolean, default: false },
|
46
|
-
userId: { type: String, default: null },
|
47
|
-
template_type: { type: String, default: null },
|
48
|
-
systemGeneratedtopics: { type: [String], default: [], _id: false },
|
49
|
-
questions: [questionSchema],
|
50
|
-
colors: { type: [String], default: [], _id: false },
|
51
|
-
prompt: { type: String, default: null },
|
52
|
-
templateRef: { type: Schema.Types.ObjectId, ref: 'template' },
|
53
|
-
slideRefs: {type: [{ type: Schema.Types.ObjectId, ref: 'ppt-slide' }], default: [], _id: false}
|
54
|
-
},
|
55
|
-
{
|
56
|
-
timestamps: true,
|
57
|
-
}
|
58
|
-
);
|
59
|
-
|
60
|
-
export const PPTModel = model<IPPTSchema>("ppt", PPTSchema);
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import { Schema, model, Types } from "mongoose";
|
2
|
-
|
3
|
-
export interface ISlideLayoutSchema {
|
4
|
-
name: string;
|
5
|
-
templateId: 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
|
-
templateId: { type: Schema.Types.ObjectId, ref: "template" },
|
15
|
-
createdAt: { type: Date, default: Date.now() },
|
16
|
-
updatedAt: { type: Date, default: Date.now() },
|
17
|
-
deletedAt: { type: Date, default: null },
|
18
|
-
},
|
19
|
-
{
|
20
|
-
timestamps: true,
|
21
|
-
}
|
22
|
-
);
|
23
|
-
|
24
|
-
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
|
-
}
|
29
|
-
|
30
|
-
const SlideSchema = new Schema<ISlideSchema>(
|
31
|
-
{
|
32
|
-
name: { type: String, default: "", required: true },
|
33
|
-
postfix: { type: String, default: "" },
|
34
|
-
rules: { type: String, default: "" },
|
35
|
-
layers: [layerSchema],
|
36
|
-
slideLayoutId: { type: Schema.Types.ObjectId, ref: "slide-layout" },
|
37
|
-
templateId: { type: Schema.Types.ObjectId, ref: "template" },
|
38
|
-
createdAt: { type: Date, default: Date.now() },
|
39
|
-
updatedAt: { type: Date, default: Date.now() },
|
40
|
-
deletedAt: { type: Date, default: null },
|
41
|
-
},
|
42
|
-
{
|
43
|
-
timestamps: true,
|
44
|
-
}
|
45
|
-
);
|
46
|
-
|
47
|
-
export const SlideModel = model<ISlideSchema>("slide", SlideSchema);
|
@@ -1,22 +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
|
-
createdAt: { type: Date, default: Date.now() },
|
13
|
-
updatedAt: { type: Date, default: Date.now() },
|
14
|
-
userId: { type: String, default: null },
|
15
|
-
socketIds: { type: [String], default: [] }
|
16
|
-
},
|
17
|
-
{
|
18
|
-
timestamps: true,
|
19
|
-
}
|
20
|
-
);
|
21
|
-
|
22
|
-
export const SocketModel = model<ISocketSchema>("socket", SocketSchema);
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import { Schema, model } from "mongoose";
|
2
|
-
|
3
|
-
export interface ITemplateSchema{
|
4
|
-
name: string;
|
5
|
-
template_type: string;
|
6
|
-
createdAt: Date,
|
7
|
-
updatedAt: Date,
|
8
|
-
deletedAt: Date
|
9
|
-
}
|
10
|
-
|
11
|
-
const TemplateSchema = new Schema<ITemplateSchema>(
|
12
|
-
{
|
13
|
-
name: { type: String, default: "", required: true },
|
14
|
-
template_type: { type: String, default: "", required: true },
|
15
|
-
createdAt: { type: Date, default: Date.now() },
|
16
|
-
updatedAt: { type: Date, default: Date.now() },
|
17
|
-
deletedAt: { type: Date, default: null },
|
18
|
-
},
|
19
|
-
{
|
20
|
-
timestamps: true,
|
21
|
-
}
|
22
|
-
);
|
23
|
-
|
24
|
-
export const TemplateModel = model<ITemplateSchema>("template", TemplateSchema);
|
@@ -1,26 +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
|
-
createdAt: { type: Date, default: Date.now()},
|
18
|
-
updatedAt: { type: Date, default: Date.now()},
|
19
|
-
deletedAt: { type: Date, default: null},
|
20
|
-
},
|
21
|
-
{
|
22
|
-
timestamps: true,
|
23
|
-
}
|
24
|
-
);
|
25
|
-
|
26
|
-
export const UserModel = model<IUser>("user", UserSchema);
|
package/src/index.ts
DELETED
@@ -1,64 +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;
|
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
|
-
// token.value.customerid
|
54
|
-
|
55
|
-
req.user = {
|
56
|
-
userId: "123" //token.value.customerid
|
57
|
-
}
|
58
|
-
|
59
|
-
next();
|
60
|
-
}
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
export {authorize, authorizeWithSlideApp};
|
package/src/middleware/index.ts
DELETED
package/src/middleware/role.ts
DELETED
@@ -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,44 +0,0 @@
|
|
1
|
-
import { Request, Response, NextFunction } from 'express';
|
2
|
-
|
3
|
-
export class BadRequestError extends Error {
|
4
|
-
constructor(message: string) {
|
5
|
-
super(message);
|
6
|
-
this.name = 'BadRequestError';
|
7
|
-
}
|
8
|
-
}
|
9
|
-
|
10
|
-
export class NotFoundRequestError extends Error {
|
11
|
-
constructor(message: string) {
|
12
|
-
super(message);
|
13
|
-
this.name = 'NotFoundRequestError';
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
// Custom error handler middleware
|
20
|
-
export const errorHandler = (
|
21
|
-
err: Error,
|
22
|
-
req: Request,
|
23
|
-
res: Response,
|
24
|
-
next: NextFunction
|
25
|
-
) => {
|
26
|
-
console.error(err.stack); // Log the error for debugging
|
27
|
-
|
28
|
-
let statusCode = 500; // Default status code
|
29
|
-
let errorMessage = 'Internal Server Error'; // Default error message
|
30
|
-
|
31
|
-
if (err instanceof BadRequestError) {
|
32
|
-
statusCode = 400;
|
33
|
-
errorMessage = err.message;
|
34
|
-
} else if(err instanceof NotFoundRequestError) {
|
35
|
-
statusCode = 404;
|
36
|
-
errorMessage = err.message;
|
37
|
-
}
|
38
|
-
|
39
|
-
// Send an error response
|
40
|
-
res.status(statusCode).json({
|
41
|
-
message: errorMessage,
|
42
|
-
error: err.name // Optionally send the error name/type
|
43
|
-
});
|
44
|
-
};
|
package/src/resHandler/index.ts
DELETED
package/src/types/IController.ts
DELETED
package/src/types/IRequest.ts
DELETED
package/src/types/index.ts
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
export * from "./IController";
|
2
|
-
export * from "./IRequest";
|
3
|
-
|
4
|
-
export enum QUEUES {
|
5
|
-
IMAGE_MODEL_BULK = "image-model-bulk", // Will be used for bulk training model
|
6
|
-
IMAGE_MODEL_SINGLE = "image-model-single", // Will be used for single image training
|
7
|
-
NOTIFICATION = "notification", // Notify to user
|
8
|
-
THUMBNAIL = "thumbnail", // To create thubmnail
|
9
|
-
PPT = "ppt", // to call PPT Service
|
10
|
-
PNG_SVG = "png-svg" // to convert raster to vector image
|
11
|
-
}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
export async function callWithRetries(retryCount: number, failedMessage: string, functionRef: Function, ...args: any): Promise<any> {
|
2
|
-
try {
|
3
|
-
return await functionRef(...args)
|
4
|
-
} catch (error) {
|
5
|
-
if (retryCount <= 0) throw error;
|
6
|
-
console.log(failedMessage)
|
7
|
-
return callWithRetries(retryCount - 1, failedMessage, functionRef, ...args);
|
8
|
-
}
|
9
|
-
}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import fs from "fs";
|
2
|
-
|
3
|
-
export async function createFolder(folderPath: string) {
|
4
|
-
try {
|
5
|
-
if (!fs.existsSync(folderPath)) {
|
6
|
-
fs.mkdirSync(folderPath);
|
7
|
-
}
|
8
|
-
console.log(`Folder "${folderPath}" is ready.`);
|
9
|
-
} catch (error: any) {
|
10
|
-
console.error(`Error: ${error.message}`);
|
11
|
-
}
|
12
|
-
}
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import jwt from 'jsonwebtoken';
|
2
|
-
|
3
|
-
const signUid = (value: object) => {
|
4
|
-
return jwt.sign({ value }, process.env.JWTSECRET || 'secret', {
|
5
|
-
expiresIn: '8h' // expires in 8 hours
|
6
|
-
});
|
7
|
-
};
|
8
|
-
|
9
|
-
const verifyUid = async (token: string): Promise<any> =>
|
10
|
-
new Promise(resolve => {
|
11
|
-
const jwtToken = token.split(" ")[1];
|
12
|
-
jwt.verify(
|
13
|
-
jwtToken,
|
14
|
-
process.env.JWTSECRET || 'secret',
|
15
|
-
(err, decoded) => {
|
16
|
-
if (err) {
|
17
|
-
console.log(err)
|
18
|
-
resolve(null);
|
19
|
-
} else {
|
20
|
-
resolve(decoded);
|
21
|
-
}
|
22
|
-
},
|
23
|
-
);
|
24
|
-
});
|
25
|
-
|
26
|
-
export { signUid, verifyUid }
|
package/src/utilities/index.ts
DELETED
package/tsconfig.json
DELETED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|