biz-slide-core 1.1.0 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- package/entity/image.entity.js +18 -0
- package/entity/index.js +26 -0
- package/entity/{png-svg.entity.ts → png-svg.entity.js} +8 -23
- package/entity/ppt-event.entity.js +13 -0
- package/entity/ppt-slide.entity.js +18 -0
- package/entity/ppt.entity.js +30 -0
- package/entity/slide-layout.entity.js +14 -0
- package/entity/slide.entity.js +26 -0
- package/entity/socket.entity.js +13 -0
- package/entity/template.entity.js +14 -0
- package/entity/user.entity.js +15 -0
- package/index.js +21 -0
- package/middleware/authentication.js +123 -0
- package/middleware/index.js +19 -0
- package/middleware/role.js +8 -0
- package/middleware/schemaValidate.js +58 -0
- package/package.json +6 -2
- package/resHandler/errorHandler.js +58 -0
- package/resHandler/index.js +18 -0
- package/resHandler/successHandler.js +8 -0
- package/types/IController.js +2 -0
- package/types/IRequest.js +2 -0
- package/types/index.js +28 -0
- package/utilities/callWithRetries.js +73 -0
- package/utilities/createFolder.js +60 -0
- package/utilities/encryptionUtils.js +66 -0
- package/utilities/index.js +19 -0
- package/entity/image.entity.ts +0 -32
- package/entity/index.ts +0 -10
- package/entity/ppt-event.entity.ts +0 -23
- package/entity/ppt-slide.entity.ts +0 -31
- package/entity/ppt.entity.ts +0 -60
- package/entity/slide-layout.entity.ts +0 -24
- package/entity/slide.entity.ts +0 -47
- package/entity/socket.entity.ts +0 -22
- package/entity/template.entity.ts +0 -24
- package/entity/user.entity.ts +0 -26
- package/middleware/authentication.ts +0 -64
- package/middleware/index.ts +0 -3
- package/middleware/role.ts +0 -5
- package/middleware/schemaValidate.ts +0 -20
- package/resHandler/errorHandler.ts +0 -44
- package/resHandler/index.ts +0 -2
- package/resHandler/successHandler.ts +0 -11
- package/tsconfig.json +0 -109
- package/types/IController.ts +0 -6
- package/types/IRequest.ts +0 -8
- package/types/index.ts +0 -11
- package/utilities/callWithRetries.ts +0 -9
- package/utilities/createFolder.ts +0 -12
- package/utilities/encryptionUtils.ts +0 -26
- package/utilities/index.ts +0 -4
@@ -0,0 +1,73 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
+
function step(op) {
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
+
switch (op[0]) {
|
21
|
+
case 0: case 1: t = op; break;
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
+
default:
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
+
if (t[2]) _.ops.pop();
|
31
|
+
_.trys.pop(); continue;
|
32
|
+
}
|
33
|
+
op = body.call(thisArg, _);
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
+
}
|
37
|
+
};
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
40
|
+
if (ar || !(i in from)) {
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
42
|
+
ar[i] = from[i];
|
43
|
+
}
|
44
|
+
}
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
46
|
+
};
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
48
|
+
exports.callWithRetries = void 0;
|
49
|
+
function callWithRetries(retryCount, failedMessage, functionRef) {
|
50
|
+
var args = [];
|
51
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
52
|
+
args[_i - 3] = arguments[_i];
|
53
|
+
}
|
54
|
+
return __awaiter(this, void 0, void 0, function () {
|
55
|
+
var error_1;
|
56
|
+
return __generator(this, function (_a) {
|
57
|
+
switch (_a.label) {
|
58
|
+
case 0:
|
59
|
+
_a.trys.push([0, 2, , 3]);
|
60
|
+
return [4 /*yield*/, functionRef.apply(void 0, args)];
|
61
|
+
case 1: return [2 /*return*/, _a.sent()];
|
62
|
+
case 2:
|
63
|
+
error_1 = _a.sent();
|
64
|
+
if (retryCount <= 0)
|
65
|
+
throw error_1;
|
66
|
+
console.log(failedMessage);
|
67
|
+
return [2 /*return*/, callWithRetries.apply(void 0, __spreadArray([retryCount - 1, failedMessage, functionRef], args, false))];
|
68
|
+
case 3: return [2 /*return*/];
|
69
|
+
}
|
70
|
+
});
|
71
|
+
});
|
72
|
+
}
|
73
|
+
exports.callWithRetries = callWithRetries;
|
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
+
function step(op) {
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
+
switch (op[0]) {
|
21
|
+
case 0: case 1: t = op; break;
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
+
default:
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
+
if (t[2]) _.ops.pop();
|
31
|
+
_.trys.pop(); continue;
|
32
|
+
}
|
33
|
+
op = body.call(thisArg, _);
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
+
}
|
37
|
+
};
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
40
|
+
};
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
42
|
+
exports.createFolder = void 0;
|
43
|
+
var fs_1 = __importDefault(require("fs"));
|
44
|
+
function createFolder(folderPath) {
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
46
|
+
return __generator(this, function (_a) {
|
47
|
+
try {
|
48
|
+
if (!fs_1.default.existsSync(folderPath)) {
|
49
|
+
fs_1.default.mkdirSync(folderPath);
|
50
|
+
}
|
51
|
+
console.log("Folder \"".concat(folderPath, "\" is ready."));
|
52
|
+
}
|
53
|
+
catch (error) {
|
54
|
+
console.error("Error: ".concat(error.message));
|
55
|
+
}
|
56
|
+
return [2 /*return*/];
|
57
|
+
});
|
58
|
+
});
|
59
|
+
}
|
60
|
+
exports.createFolder = createFolder;
|
@@ -0,0 +1,66 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
+
function step(op) {
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
+
switch (op[0]) {
|
21
|
+
case 0: case 1: t = op; break;
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
+
default:
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
+
if (t[2]) _.ops.pop();
|
31
|
+
_.trys.pop(); continue;
|
32
|
+
}
|
33
|
+
op = body.call(thisArg, _);
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
+
}
|
37
|
+
};
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
40
|
+
};
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
42
|
+
exports.verifyUid = exports.signUid = void 0;
|
43
|
+
var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
44
|
+
var signUid = function (value) {
|
45
|
+
return jsonwebtoken_1.default.sign({ value: value }, process.env.JWTSECRET || 'secret', {
|
46
|
+
expiresIn: '8h' // expires in 8 hours
|
47
|
+
});
|
48
|
+
};
|
49
|
+
exports.signUid = signUid;
|
50
|
+
var verifyUid = function (token) { return __awaiter(void 0, void 0, void 0, function () {
|
51
|
+
return __generator(this, function (_a) {
|
52
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
53
|
+
var jwtToken = token.split(" ")[1];
|
54
|
+
jsonwebtoken_1.default.verify(jwtToken, process.env.JWTSECRET || 'secret', function (err, decoded) {
|
55
|
+
if (err) {
|
56
|
+
console.log(err);
|
57
|
+
resolve(null);
|
58
|
+
}
|
59
|
+
else {
|
60
|
+
resolve(decoded);
|
61
|
+
}
|
62
|
+
});
|
63
|
+
})];
|
64
|
+
});
|
65
|
+
}); };
|
66
|
+
exports.verifyUid = verifyUid;
|
@@ -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("./callWithRetries"), exports);
|
18
|
+
__exportStar(require("./createFolder"), exports);
|
19
|
+
__exportStar(require("./encryptionUtils"), exports);
|
package/entity/image.entity.ts
DELETED
@@ -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/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,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/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);
|
package/entity/slide.entity.ts
DELETED
@@ -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);
|
package/entity/socket.entity.ts
DELETED
@@ -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);
|
package/entity/user.entity.ts
DELETED
@@ -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);
|
@@ -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 = 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/middleware/index.ts
DELETED
package/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
|
-
};
|