@shoppingapp.org/common 1.0.28 → 1.0.32
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/build/constants/seller/product.interface.d.ts +12 -0
- package/build/constants/seller/product.interface.js +4 -0
- package/build/index.d.ts +3 -1
- package/build/index.js +4 -2
- package/build/middlewares/current-user.d.ts +1 -0
- package/build/middlewares/uploader.d.ts +14 -0
- package/build/middlewares/uploader.js +51 -0
- package/package.json +2 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
import { UserDoc } from "../auth/user.interfaces";
|
|
3
|
+
export interface ProductDoc extends mongoose.Document {
|
|
4
|
+
user: UserDoc | string;
|
|
5
|
+
title: string;
|
|
6
|
+
price: number;
|
|
7
|
+
images: {
|
|
8
|
+
src: string;
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
export interface ProductModel extends mongoose.Model<ProductDoc> {
|
|
12
|
+
}
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './middlewares/current-user';
|
|
2
2
|
export * from './middlewares/error-handler';
|
|
3
|
+
export * from './middlewares/uploader';
|
|
3
4
|
export * from './errors/bad-request-error';
|
|
4
5
|
export * from './errors/custom-error';
|
|
5
6
|
export * from './errors/database-connection-error';
|
|
@@ -7,5 +8,6 @@ export * from './errors/not-authorized-error';
|
|
|
7
8
|
export * from './errors/not-found-error';
|
|
8
9
|
export * from './errors/request-validation-error';
|
|
9
10
|
export * from './constants/auth/user.interfaces';
|
|
10
|
-
export * from './services/authentication.service';
|
|
11
11
|
export * from './constants/globals';
|
|
12
|
+
export * from './constants/seller/product.interface';
|
|
13
|
+
export * from './services/authentication.service';
|
package/build/index.js
CHANGED
|
@@ -16,7 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./middlewares/current-user"), exports);
|
|
18
18
|
// export * from './middlewares/require-auth';
|
|
19
|
-
__exportStar(require("./middlewares/error-handler"), exports);
|
|
19
|
+
__exportStar(require("./middlewares/error-handler"), exports);
|
|
20
|
+
__exportStar(require("./middlewares/uploader"), exports);
|
|
20
21
|
__exportStar(require("./errors/bad-request-error"), exports); // 🔹 Fixed
|
|
21
22
|
__exportStar(require("./errors/custom-error"), exports); // 🔹 Fixed
|
|
22
23
|
__exportStar(require("./errors/database-connection-error"), exports); // 🔹 Fixed
|
|
@@ -24,5 +25,6 @@ __exportStar(require("./errors/not-authorized-error"), exports); // 🔹 Fixed
|
|
|
24
25
|
__exportStar(require("./errors/not-found-error"), exports); // 🔹 Fixed
|
|
25
26
|
__exportStar(require("./errors/request-validation-error"), exports);
|
|
26
27
|
__exportStar(require("./constants/auth/user.interfaces"), exports);
|
|
27
|
-
__exportStar(require("./services/authentication.service"), exports);
|
|
28
28
|
__exportStar(require("./constants/globals"), exports);
|
|
29
|
+
__exportStar(require("./constants/seller/product.interface"), exports);
|
|
30
|
+
__exportStar(require("./services/authentication.service"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import multer, { FileFilterCallback } from "multer";
|
|
2
|
+
export interface UploaderMIddlewareOptions {
|
|
3
|
+
types?: string[];
|
|
4
|
+
fieldName?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class Uploader {
|
|
7
|
+
uploadDir?: string | undefined;
|
|
8
|
+
fileFilter: (types?: Array<string>) => (req: Req, file: Express.Multer.File, cb: FileFilterCallback) => void;
|
|
9
|
+
storage: multer.StorageEngine;
|
|
10
|
+
defaultUploadeDir: string;
|
|
11
|
+
constructor(uploadDir?: string | undefined);
|
|
12
|
+
uploadeMultipleFiles(options: UploaderMIddlewareOptions): import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
13
|
+
uploadeSingleFile(options: UploaderMIddlewareOptions): import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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.Uploader = void 0;
|
|
7
|
+
const multer_1 = __importDefault(require("multer"));
|
|
8
|
+
;
|
|
9
|
+
class Uploader {
|
|
10
|
+
constructor(uploadDir) {
|
|
11
|
+
this.uploadDir = uploadDir;
|
|
12
|
+
this.fileFilter = (types) => {
|
|
13
|
+
return (req, file, cb) => {
|
|
14
|
+
const type = file.mimetype;
|
|
15
|
+
if (!types)
|
|
16
|
+
return cb(null, true);
|
|
17
|
+
if (types.length === 0)
|
|
18
|
+
return cb(null, true);
|
|
19
|
+
if (types.some((accepted) => type === accepted)) {
|
|
20
|
+
return cb(null, true);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
req.uploaderError = new Error(`We only accept these types: ${types}`);
|
|
24
|
+
return cb(null, false);
|
|
25
|
+
}
|
|
26
|
+
;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
this.storage = multer_1.default.diskStorage({
|
|
30
|
+
destination: (req, file, cb) => {
|
|
31
|
+
cb(null, this.uploadDir || this.defaultUploadeDir);
|
|
32
|
+
},
|
|
33
|
+
filename: (req, file, cb) => {
|
|
34
|
+
cb(null, file.fieldname + Date.now());
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
this.defaultUploadeDir = "/upload";
|
|
38
|
+
}
|
|
39
|
+
;
|
|
40
|
+
uploadeMultipleFiles(options) {
|
|
41
|
+
return (0, multer_1.default)({ storage: this.storage, fileFilter: this.fileFilter(options.types) })
|
|
42
|
+
.array(options.fieldName || 'file');
|
|
43
|
+
}
|
|
44
|
+
;
|
|
45
|
+
uploadeSingleFile(options) {
|
|
46
|
+
return (0, multer_1.default)({ storage: this.storage, fileFilter: this.fileFilter(options.types) })
|
|
47
|
+
.single(options.fieldName || 'file');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.Uploader = Uploader;
|
|
51
|
+
;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shoppingapp.org/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.32",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"author": "",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"@shoppingapp.org/common": "^1.0.28",
|
|
19
20
|
"express": "^4.18.1",
|
|
20
21
|
"express-validator": "^6.14.2",
|
|
21
22
|
"jsonwebtoken": "^8.5.1",
|