@duvdu-v1/duvdu 1.1.41 → 1.1.43

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,7 +1,9 @@
1
1
  import multer from 'multer';
2
+ import { FOLDERS } from '../types/folders';
2
3
  interface uploadOptions {
3
- fileType?: string;
4
+ fileTypes?: string[];
4
5
  maxSize?: number;
6
+ fileFilter?(req: Request, file: Express.Multer.File, callback: multer.FileFilterCallback): void;
5
7
  }
6
- export declare const globalUploadMiddleware: (options?: uploadOptions) => multer.Multer;
8
+ export declare const globalUploadMiddleware: (folder: FOLDERS, options?: uploadOptions) => multer.Multer;
7
9
  export {};
@@ -4,19 +4,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.globalUploadMiddleware = void 0;
7
+ /* eslint-disable indent */
8
+ const path_1 = __importDefault(require("path"));
7
9
  const multer_1 = __importDefault(require("multer"));
8
10
  const uuid_1 = require("uuid");
9
11
  const bad_request_error_1 = require("../errors/bad-request-error");
10
- const globalUploadMiddleware = (options) => (0, multer_1.default)({
11
- storage: multer_1.default.memoryStorage(),
12
- fileFilter(req, file, callback) {
13
- if (!file.mimetype.startsWith((options === null || options === void 0 ? void 0 : options.fileType) || 'image'))
14
- return callback(new bad_request_error_1.BadRequestError('invalid file format'));
15
- if (file.size > ((options === null || options === void 0 ? void 0 : options.maxSize) || 2 * 1024 * 1024))
16
- return callback(new bad_request_error_1.BadRequestError('invalid file size'));
17
- const splittedOriginalName = file.originalname.split('.').at(-1);
18
- file.filename = `${(0, uuid_1.v4)()}.${splittedOriginalName}`;
19
- callback(null, true);
20
- },
12
+ const globalUploadMiddleware = (folder, options) => (0, multer_1.default)({
13
+ storage: multer_1.default.diskStorage({
14
+ destination: path_1.default.resolve(`media/${folder}`),
15
+ filename(req, file, callback) {
16
+ callback(null, `${(0, uuid_1.v4)()}.${file.originalname.split('.').at(-1)}`);
17
+ },
18
+ }),
19
+ limits: { fileSize: (options === null || options === void 0 ? void 0 : options.maxSize) || 3 * 1024 * 1024 }, // 3MB
20
+ fileFilter: (options === null || options === void 0 ? void 0 : options.fileFilter)
21
+ ? options.fileFilter
22
+ : function fileFilter(req, file, callback) {
23
+ var _a;
24
+ if (!(options === null || options === void 0 ? void 0 : options.fileTypes)) {
25
+ if (!file.mimetype.startsWith('image'))
26
+ return callback(new bad_request_error_1.BadRequestError('invalid file format'));
27
+ return callback(null, true);
28
+ }
29
+ if ((_a = options === null || options === void 0 ? void 0 : options.fileTypes) === null || _a === void 0 ? void 0 : _a.some((type) => file.mimetype.startsWith(type)))
30
+ return callback(null, true);
31
+ else
32
+ return callback(new bad_request_error_1.BadRequestError('invalid file format'));
33
+ },
21
34
  });
22
35
  exports.globalUploadMiddleware = globalUploadMiddleware;
@@ -9,9 +9,9 @@ const userSchema = new mongoose_1.Schema({
9
9
  name: { type: String, default: null },
10
10
  phoneNumber: {
11
11
  key: { type: String, default: null },
12
- number: { type: String, unique: true, default: null, sparse: true },
12
+ number: { type: String, unique: true, sparse: true },
13
13
  },
14
- username: { type: String, unique: true, sparse: true, default: null },
14
+ username: { type: String, unique: true, sparse: true },
15
15
  password: String,
16
16
  verificationCode: { code: String, expireAt: Date, reason: { type: String, default: null } },
17
17
  isVerified: { type: Boolean, default: false },
@@ -36,9 +36,10 @@ const userSchema = new mongoose_1.Schema({
36
36
  },
37
37
  notificationToken: {
38
38
  type: String,
39
- default: null
40
- }
41
- }, { timestamps: true,
39
+ default: null,
40
+ },
41
+ }, {
42
+ timestamps: true,
42
43
  collection: model_names_1.MODELS.user,
43
44
  toJSON: {
44
45
  transform(doc, ret) {
@@ -47,5 +48,6 @@ const userSchema = new mongoose_1.Schema({
47
48
  if (ret.profileImage)
48
49
  ret.profileImage = process.env.BUCKET_HOST + '/' + ret.profileImage;
49
50
  },
50
- }, });
51
+ },
52
+ });
51
53
  exports.Users = (0, mongoose_1.model)(model_names_1.MODELS.user, userSchema);
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PortfolioPosts = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
5
  const model_names_1 = require("../types/model-names");
6
- const PortfolioPostSchema = new mongoose_1.Schema({
6
+ exports.PortfolioPosts = (0, mongoose_1.model)(model_names_1.MODELS.portfolioPost, new mongoose_1.Schema({
7
7
  user: { type: mongoose_1.Schema.Types.ObjectId, ref: model_names_1.MODELS.user },
8
8
  attachments: [String],
9
9
  cover: { type: String, default: null },
@@ -46,26 +46,15 @@ const PortfolioPostSchema = new mongoose_1.Schema({
46
46
  },
47
47
  })
48
48
  .index({ createdAt: 1, updatedAt: -1 })
49
- .index({ title: 'text', desc: 'text', tools: 'text', searchKeywords: 'text' });
50
- function transformDocument(doc) {
51
- if (doc.cover) {
52
- doc.cover = process.env.BUCKET_HOST + '/' + doc.cover;
49
+ .index({ title: 'text', desc: 'text', tools: 'text', searchKeywords: 'text' }));
50
+ exports.PortfolioPosts.schema.set('toJSON', {
51
+ transform: function (doc, ret) {
52
+ if (ret.cover) {
53
+ ret.cover = process.env.BUCKET_HOST + '/' + ret.cover;
54
+ }
55
+ if (ret.attachments) {
56
+ ret.attachments = ret.attachments.map((el) => process.env.BUCKET_HOST + '/' + el);
57
+ }
58
+ return ret;
53
59
  }
54
- if (doc.attachments) {
55
- doc.attachments = doc.attachments.map(el => process.env.BUCKET_HOST + '/' + el);
56
- }
57
- }
58
- PortfolioPostSchema.pre('save', function (next) {
59
- transformDocument(this);
60
- next();
61
- });
62
- PortfolioPostSchema.pre(/^find/, function (next) {
63
- const query = this;
64
- query.then((documents) => {
65
- documents.forEach((doc) => {
66
- transformDocument(doc);
67
- });
68
- next();
69
- }).catch(next);
70
60
  });
71
- exports.PortfolioPosts = (0, mongoose_1.model)(model_names_1.MODELS.portfolioPost, PortfolioPostSchema);
@@ -43,7 +43,8 @@ export declare enum PERMISSIONS {
43
43
  getAllReportsHandler = "get all reports",
44
44
  getReportHandler = "get report",
45
45
  updateReportHandler = "update report",
46
- deleteReportHandler = "delete report"
46
+ deleteReportHandler = "delete report",
47
+ booking = "booking"
47
48
  }
48
49
  export declare const permissions: {
49
50
  auth: PERMISSIONS[];
@@ -56,4 +57,5 @@ export declare const permissions: {
56
57
  portfolioPost: PERMISSIONS[];
57
58
  copyrights: PERMISSIONS[];
58
59
  studioBooking: PERMISSIONS[];
60
+ booking: PERMISSIONS[];
59
61
  };
@@ -54,6 +54,8 @@ var PERMISSIONS;
54
54
  PERMISSIONS["getReportHandler"] = "get report";
55
55
  PERMISSIONS["updateReportHandler"] = "update report";
56
56
  PERMISSIONS["deleteReportHandler"] = "delete report";
57
+ // book project
58
+ PERMISSIONS["booking"] = "booking";
57
59
  })(PERMISSIONS || (exports.PERMISSIONS = PERMISSIONS = {}));
58
60
  exports.permissions = {
59
61
  auth: [
@@ -114,4 +116,5 @@ exports.permissions = {
114
116
  PERMISSIONS.getCrmStudioProjectsHandlers,
115
117
  PERMISSIONS.getStudioAnalysisHandler,
116
118
  ],
119
+ booking: [PERMISSIONS.booking],
117
120
  };
@@ -4,5 +4,6 @@ export declare enum FOLDERS {
4
4
  report = "report",
5
5
  category = "category",
6
6
  auth = "auth",
7
- chat = "chat"
7
+ chat = "chat",
8
+ copyrights = "copyrights"
8
9
  }
@@ -9,4 +9,5 @@ var FOLDERS;
9
9
  FOLDERS["category"] = "category";
10
10
  FOLDERS["auth"] = "auth";
11
11
  FOLDERS["chat"] = "chat";
12
+ FOLDERS["copyrights"] = "copyrights";
12
13
  })(FOLDERS || (exports.FOLDERS = FOLDERS = {}));
@@ -11,6 +11,7 @@ export declare enum MODELS {
11
11
  studioBooking = "studio-booking",
12
12
  report = "report",
13
13
  copyrights = "copyrights",
14
+ copyrightsBooking = "copyrights-booking",
14
15
  projects = "allProjects",
15
16
  messages = "messages",
16
17
  notifications = "notifications"
@@ -15,6 +15,7 @@ var MODELS;
15
15
  MODELS["studioBooking"] = "studio-booking";
16
16
  MODELS["report"] = "report";
17
17
  MODELS["copyrights"] = "copyrights";
18
+ MODELS["copyrightsBooking"] = "copyrights-booking";
18
19
  MODELS["projects"] = "allProjects";
19
20
  MODELS["messages"] = "messages";
20
21
  MODELS["notifications"] = "notifications";
package/package.json CHANGED
@@ -1,55 +1,55 @@
1
- {
2
- "name": "@duvdu-v1/duvdu",
3
- "version": "1.1.41",
4
- "main": "./build/index.js",
5
- "types": "./build/index.d.ts",
6
- "files": [
7
- "build/**/*"
8
- ],
9
- "scripts": {
10
- "clean": "rimraf ./build",
11
- "build": "npm run clean && tsc",
12
- "fix:build": "mv ./build/common/src/* ./build && rm -rf ./build/auth ./build/portfolio-post ./build/common",
13
- "pub": "git add . && git commit -m \"updates\" && npm version patch && npm run build && npm publish",
14
- "lint": "eslint .",
15
- "lint:fix": "eslint --fix .",
16
- "format": "prettier --write ."
17
- },
18
- "keywords": [],
19
- "author": "motemed khaled",
20
- "license": "ISC",
21
- "dependencies": {
22
- "@duvdu-v1/duvdu": "^1.1.4",
23
- "@types/express": "^4.17.21",
24
- "@types/express-session": "^1.18.0",
25
- "@types/jsonwebtoken": "^9.0.5",
26
- "@types/multer": "^1.4.11",
27
- "@types/node": "^20.11.0",
28
- "@typescript-eslint/eslint-plugin": "^6.19.0",
29
- "@typescript-eslint/parser": "^6.19.0",
30
- "aws-sdk": "^2.1595.0",
31
- "connect-redis": "^7.1.1",
32
- "express": "^4.18.2",
33
- "express-async-errors": "^3.1.1",
34
- "express-session": "^1.18.0",
35
- "express-validator": "^7.0.1",
36
- "jsonwebtoken": "^9.0.2",
37
- "mongoose": "^8.0.4",
38
- "multer": "^1.4.5-lts.1",
39
- "node-nats-streaming": "^0.3.2",
40
- "redis": "^4.6.13",
41
- "rimraf": "^5.0.5",
42
- "typescript": "^5.3.3",
43
- "uuid": "^9.0.1"
44
- },
45
- "devDependencies": {
46
- "@types/uuid": "^9.0.8",
47
- "del-cli": "^5.1.0",
48
- "eslint": "^8.56.0",
49
- "eslint-config-prettier": "^9.1.0",
50
- "eslint-plugin-import": "^2.29.1",
51
- "eslint-plugin-prettier": "^5.1.3",
52
- "prettier": "^3.2.4"
53
- },
54
- "description": ""
55
- }
1
+ {
2
+ "name": "@duvdu-v1/duvdu",
3
+ "version": "1.1.43",
4
+ "main": "./build/index.js",
5
+ "types": "./build/index.d.ts",
6
+ "files": [
7
+ "build/**/*"
8
+ ],
9
+ "scripts": {
10
+ "clean": "rimraf ./build",
11
+ "build": "npm run clean && tsc",
12
+ "fix:build": "mv ./build/common/src/* ./build && rm -rf ./build/auth ./build/portfolio-post ./build/common",
13
+ "pub": "git add . && git commit -m \"updates\" && npm version patch && npm run build && npm publish",
14
+ "lint": "eslint .",
15
+ "lint:fix": "eslint --fix .",
16
+ "format": "prettier --write ."
17
+ },
18
+ "keywords": [],
19
+ "author": "motemed khaled",
20
+ "license": "ISC",
21
+ "dependencies": {
22
+ "@duvdu-v1/duvdu": "^1.1.4",
23
+ "@types/express": "^4.17.21",
24
+ "@types/express-session": "^1.18.0",
25
+ "@types/jsonwebtoken": "^9.0.5",
26
+ "@types/multer": "^1.4.11",
27
+ "@types/node": "^20.11.0",
28
+ "@typescript-eslint/eslint-plugin": "^6.19.0",
29
+ "@typescript-eslint/parser": "^6.19.0",
30
+ "aws-sdk": "^2.1595.0",
31
+ "connect-redis": "^7.1.1",
32
+ "express": "^4.18.2",
33
+ "express-async-errors": "^3.1.1",
34
+ "express-session": "^1.18.0",
35
+ "express-validator": "^7.0.1",
36
+ "jsonwebtoken": "^9.0.2",
37
+ "mongoose": "^8.0.4",
38
+ "multer": "^1.4.5-lts.1",
39
+ "node-nats-streaming": "^0.3.2",
40
+ "redis": "^4.6.13",
41
+ "rimraf": "^5.0.5",
42
+ "typescript": "^5.3.3",
43
+ "uuid": "^9.0.1"
44
+ },
45
+ "devDependencies": {
46
+ "@types/uuid": "^9.0.8",
47
+ "del-cli": "^5.1.0",
48
+ "eslint": "^8.56.0",
49
+ "eslint-config-prettier": "^9.1.0",
50
+ "eslint-plugin-import": "^2.29.1",
51
+ "eslint-plugin-prettier": "^5.1.3",
52
+ "prettier": "^3.2.4"
53
+ },
54
+ "description": ""
55
+ }