@nest-omni/core 1.0.6 → 1.0.8
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/{src → dist}/boilerplate.polyfill.js +0 -1
- package/{src → dist}/common/abstract-client.service.d.ts +0 -4
- package/{src → dist}/common/abstract-client.service.js +0 -4
- package/{src → dist}/common/abstract.entity.d.ts +0 -7
- package/dist/common/abstract.entity.js +64 -0
- package/dist/common/dto/abstract.dto.js +59 -0
- package/dist/common/dto/bulk-id.dto.js +27 -0
- package/dist/common/dto/create-translation.dto.js +25 -0
- package/dist/common/dto/page-meta.dto.js +48 -0
- package/dist/common/dto/page-options.dto.js +52 -0
- package/dist/common/dto/page.dto.js +53 -0
- package/{src → dist}/common/utils.d.ts +0 -11
- package/{src → dist}/common/utils.js +1 -15
- package/{src → dist}/constants/language-code.js +0 -1
- package/dist/decorators/controller.decorator.js +11 -0
- package/{src → dist}/decorators/field.decorators.js +1 -7
- package/{src → dist}/decorators/omni-auth.decorator.js +1 -26
- package/{src → dist}/decorators/property.decorators.js +1 -5
- package/{src → dist}/decorators/public-route.decorator.js +0 -1
- package/{src → dist}/decorators/swagger.schema.js +1 -4
- package/{src → dist}/decorators/timestamp-column.decorator.js +1 -1
- package/dist/decorators/transform.decorators.d.ts +8 -0
- package/{src → dist}/decorators/transform.decorators.js +0 -27
- package/{src → dist}/decorators/translate.decorator.js +0 -1
- package/dist/decorators/user-check.decorator.js +21 -0
- package/{src → dist}/decorators/user.decorator.js +1 -25
- package/dist/filters/bad-request.filter.js +60 -0
- package/{src → dist}/filters/constraint-errors.js +0 -1
- package/dist/filters/query-failed.filter.js +42 -0
- package/dist/health-checker/health-checker.controller.js +72 -0
- package/dist/health-checker/health-checker.module.js +25 -0
- package/dist/health-checker/health-indicators/service.indicator.js +66 -0
- package/dist/helpers/common.helper.d.ts +3 -0
- package/{src → dist}/helpers/common.helper.js +0 -13
- package/{src → dist}/helpers/date.helper.d.ts +3 -3
- package/{src → dist}/helpers/date.helper.js +2 -25
- package/dist/i18n/en_US/validation.json +38 -0
- package/dist/i18n/zh_CN/validation.json +38 -0
- package/{src → dist}/index.js +0 -1
- package/dist/interceptors/auth-user.interceptor.js +24 -0
- package/dist/interceptors/language-interceptor.service.js +30 -0
- package/dist/interceptors/translation-interceptor.service.js +34 -0
- package/{src → dist}/providers/context.provider.js +0 -2
- package/{src → dist}/providers/generator.provider.d.ts +0 -4
- package/{src → dist}/providers/generator.provider.js +0 -4
- package/{src → dist}/setup/bootstrap.setup.js +7 -33
- package/dist/shared/serviceRegistryModule.js +110 -0
- package/{src → dist}/shared/services/api-config.service.d.ts +0 -3
- package/dist/shared/services/api-config.service.js +290 -0
- package/dist/shared/services/aws-s3.service.js +56 -0
- package/dist/shared/services/generator.service.js +23 -0
- package/dist/shared/services/translation.service.js +70 -0
- package/dist/shared/services/validator.service.js +20 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/validators/is-exists.validator.js +61 -0
- package/dist/validators/is-unique.validator.js +92 -0
- package/{src → dist}/validators/skip-empty.validator.d.ts +0 -5
- package/{src → dist}/validators/skip-empty.validator.js +0 -5
- package/package.json +4 -1
- package/src/boilerplate.polyfill.ts +0 -202
- package/src/common/abstract-client.service.ts +0 -56
- package/src/common/abstract.entity.js +0 -152
- package/src/common/abstract.entity.ts +0 -73
- package/src/common/dto/abstract.dto.js +0 -96
- package/src/common/dto/abstract.dto.ts +0 -64
- package/src/common/dto/bulk-id.dto.js +0 -63
- package/src/common/dto/bulk-id.dto.ts +0 -13
- package/src/common/dto/create-translation.dto.js +0 -63
- package/src/common/dto/create-translation.dto.ts +0 -10
- package/src/common/dto/page-meta.dto.js +0 -88
- package/src/common/dto/page-meta.dto.ts +0 -37
- package/src/common/dto/page-options.dto.js +0 -87
- package/src/common/dto/page-options.dto.ts +0 -35
- package/src/common/dto/page.dto.js +0 -94
- package/src/common/dto/page.dto.ts +0 -36
- package/src/common/utils.ts +0 -45
- package/src/constants/index.ts +0 -4
- package/src/constants/language-code.ts +0 -7
- package/src/constants/order.ts +0 -4
- package/src/constants/role-type.ts +0 -4
- package/src/constants/token-type.ts +0 -4
- package/src/decorators/api-page-ok-response.decorator.ts +0 -31
- package/src/decorators/auth-user.decorator.ts +0 -16
- package/src/decorators/controller.decorator.js +0 -34
- package/src/decorators/controller.decorator.ts +0 -8
- package/src/decorators/field.decorators.ts +0 -773
- package/src/decorators/http.decorators.ts +0 -10
- package/src/decorators/index.ts +0 -12
- package/src/decorators/omni-auth.decorator.ts +0 -46
- package/src/decorators/operation.decorator.ts +0 -4
- package/src/decorators/property.decorators.ts +0 -62
- package/src/decorators/public-route.decorator.ts +0 -8
- package/src/decorators/swagger.schema.ts +0 -117
- package/src/decorators/timestamp-column.decorator.ts +0 -29
- package/src/decorators/transform.decorators.d.ts +0 -35
- package/src/decorators/transform.decorators.ts +0 -147
- package/src/decorators/translate.decorator.ts +0 -19
- package/src/decorators/use-dto.decorator.ts +0 -11
- package/src/decorators/user-check.decorator.js +0 -44
- package/src/decorators/user-check.decorator.ts +0 -30
- package/src/decorators/user.decorator.ts +0 -48
- package/src/decorators/user_auth.decorator.ts +0 -15
- package/src/decorators/validator.decorators.ts +0 -78
- package/src/exceptions/file-not-image.exception.ts +0 -7
- package/src/exceptions/index.ts +0 -2
- package/src/exceptions/page-type.exception.ts +0 -7
- package/src/exceptions/user-not-found.exception.ts +0 -7
- package/src/filters/bad-request.filter.js +0 -104
- package/src/filters/bad-request.filter.ts +0 -67
- package/src/filters/constraint-errors.ts +0 -5
- package/src/filters/index.ts +0 -3
- package/src/filters/query-failed.filter.js +0 -81
- package/src/filters/query-failed.filter.ts +0 -32
- package/src/health-checker/health-checker.controller.js +0 -104
- package/src/health-checker/health-checker.controller.ts +0 -51
- package/src/health-checker/health-checker.module.js +0 -69
- package/src/health-checker/health-checker.module.ts +0 -13
- package/src/health-checker/health-indicators/service.indicator.js +0 -102
- package/src/health-checker/health-indicators/service.indicator.ts +0 -44
- package/src/helpers/common.helper.d.ts +0 -16
- package/src/helpers/common.helper.ts +0 -49
- package/src/helpers/date.helper.ts +0 -64
- package/src/helpers/excel.helper.d.ts +0 -27
- package/src/helpers/excel.helper.js +0 -338
- package/src/helpers/index.ts +0 -3
- package/src/i18n/en_US/validation.json +0 -38
- package/src/i18n/zh_CN/validation.json +0 -38
- package/src/index.ts +0 -12
- package/src/interceptors/auth-user.interceptor.js +0 -68
- package/src/interceptors/auth-user.interceptor.ts +0 -20
- package/src/interceptors/index.ts +0 -2
- package/src/interceptors/language-interceptor.service.js +0 -74
- package/src/interceptors/language-interceptor.service.ts +0 -31
- package/src/interceptors/translation-interceptor.service.js +0 -83
- package/src/interceptors/translation-interceptor.service.ts +0 -43
- package/src/interfaces/IApiFile.ts +0 -4
- package/src/interfaces/IFile.ts +0 -8
- package/src/interfaces/ITranslationDecoratorInterface.ts +0 -3
- package/src/interfaces/index.ts +0 -3
- package/src/interfaces/response.ts +0 -37
- package/src/middlewares/index.ts +0 -3
- package/src/middlewares/omni-auth.middleware.ts +0 -10
- package/src/middlewares/powerby.middleware.ts +0 -6
- package/src/middlewares/request-id.middleware.ts +0 -28
- package/src/providers/context.provider.ts +0 -98
- package/src/providers/generator.provider.ts +0 -66
- package/src/providers/index.ts +0 -2
- package/src/setup/bootstrap.setup.ts +0 -139
- package/src/setup/index.ts +0 -1
- package/src/setup/microservices.setup.js +0 -55
- package/src/setup-swagger.ts +0 -67
- package/src/shared/index.ts +0 -2
- package/src/shared/serviceRegistryModule.js +0 -176
- package/src/shared/serviceRegistryModule.ts +0 -110
- package/src/shared/services/api-config.service.js +0 -335
- package/src/shared/services/api-config.service.ts +0 -319
- package/src/shared/services/aws-s3.service.js +0 -96
- package/src/shared/services/aws-s3.service.ts +0 -39
- package/src/shared/services/generator.service.js +0 -67
- package/src/shared/services/generator.service.ts +0 -13
- package/src/shared/services/index.ts +0 -5
- package/src/shared/services/translation.service.js +0 -109
- package/src/shared/services/translation.service.ts +0 -59
- package/src/shared/services/validator.service.js +0 -64
- package/src/shared/services/validator.service.ts +0 -10
- package/src/snake-naming.strategy.ts +0 -64
- package/src/types.ts +0 -44
- package/src/validators/file-mimetype.validator.ts +0 -34
- package/src/validators/index.ts +0 -3
- package/src/validators/is-exists.validator.js +0 -99
- package/src/validators/is-exists.validator.ts +0 -60
- package/src/validators/is-unique.validator.js +0 -131
- package/src/validators/is-unique.validator.ts +0 -93
- package/src/validators/phone-country-code.validator.ts +0 -36
- package/src/validators/same-as.validator.ts +0 -27
- package/src/validators/skip-empty.validator.ts +0 -25
- package/tsconfig.json +0 -26
- package/tsconfig.lib.json +0 -16
- package/tsconfig.tsbuildinfo +0 -1
- /package/{src → dist}/boilerplate.polyfill.d.ts +0 -0
- /package/{src → dist}/common/dto/abstract.dto.d.ts +0 -0
- /package/{src → dist}/common/dto/bulk-id.dto.d.ts +0 -0
- /package/{src → dist}/common/dto/create-translation.dto.d.ts +0 -0
- /package/{src → dist}/common/dto/page-meta.dto.d.ts +0 -0
- /package/{src → dist}/common/dto/page-options.dto.d.ts +0 -0
- /package/{src → dist}/common/dto/page.dto.d.ts +0 -0
- /package/{src → dist}/constants/index.d.ts +0 -0
- /package/{src → dist}/constants/index.js +0 -0
- /package/{src → dist}/constants/language-code.d.ts +0 -0
- /package/{src → dist}/constants/order.d.ts +0 -0
- /package/{src → dist}/constants/order.js +0 -0
- /package/{src → dist}/constants/role-type.d.ts +0 -0
- /package/{src → dist}/constants/role-type.js +0 -0
- /package/{src → dist}/constants/token-type.d.ts +0 -0
- /package/{src → dist}/constants/token-type.js +0 -0
- /package/{src → dist}/decorators/api-page-ok-response.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/api-page-ok-response.decorator.js +0 -0
- /package/{src → dist}/decorators/auth-user.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/auth-user.decorator.js +0 -0
- /package/{src → dist}/decorators/controller.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/field.decorators.d.ts +0 -0
- /package/{src → dist}/decorators/http.decorators.d.ts +0 -0
- /package/{src → dist}/decorators/http.decorators.js +0 -0
- /package/{src → dist}/decorators/index.d.ts +0 -0
- /package/{src → dist}/decorators/index.js +0 -0
- /package/{src → dist}/decorators/omni-auth.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/operation.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/operation.decorator.js +0 -0
- /package/{src → dist}/decorators/property.decorators.d.ts +0 -0
- /package/{src → dist}/decorators/public-route.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/swagger.schema.d.ts +0 -0
- /package/{src → dist}/decorators/timestamp-column.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/translate.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/use-dto.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/use-dto.decorator.js +0 -0
- /package/{src → dist}/decorators/user-check.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/user.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/user_auth.decorator.d.ts +0 -0
- /package/{src → dist}/decorators/user_auth.decorator.js +0 -0
- /package/{src → dist}/decorators/validator.decorators.d.ts +0 -0
- /package/{src → dist}/decorators/validator.decorators.js +0 -0
- /package/{src → dist}/exceptions/file-not-image.exception.d.ts +0 -0
- /package/{src → dist}/exceptions/file-not-image.exception.js +0 -0
- /package/{src → dist}/exceptions/index.d.ts +0 -0
- /package/{src → dist}/exceptions/index.js +0 -0
- /package/{src → dist}/exceptions/page-type.exception.d.ts +0 -0
- /package/{src → dist}/exceptions/page-type.exception.js +0 -0
- /package/{src → dist}/exceptions/user-not-found.exception.d.ts +0 -0
- /package/{src → dist}/exceptions/user-not-found.exception.js +0 -0
- /package/{src → dist}/filters/bad-request.filter.d.ts +0 -0
- /package/{src → dist}/filters/constraint-errors.d.ts +0 -0
- /package/{src → dist}/filters/index.d.ts +0 -0
- /package/{src → dist}/filters/index.js +0 -0
- /package/{src → dist}/filters/query-failed.filter.d.ts +0 -0
- /package/{src → dist}/health-checker/health-checker.controller.d.ts +0 -0
- /package/{src → dist}/health-checker/health-checker.module.d.ts +0 -0
- /package/{src → dist}/health-checker/health-indicators/service.indicator.d.ts +0 -0
- /package/{src → dist}/helpers/index.d.ts +0 -0
- /package/{src → dist}/helpers/index.js +0 -0
- /package/{src → dist}/index.d.ts +0 -0
- /package/{src → dist}/interceptors/auth-user.interceptor.d.ts +0 -0
- /package/{src → dist}/interceptors/index.d.ts +0 -0
- /package/{src → dist}/interceptors/index.js +0 -0
- /package/{src → dist}/interceptors/language-interceptor.service.d.ts +0 -0
- /package/{src → dist}/interceptors/translation-interceptor.service.d.ts +0 -0
- /package/{src → dist}/interfaces/IApiFile.d.ts +0 -0
- /package/{src → dist}/interfaces/IApiFile.js +0 -0
- /package/{src → dist}/interfaces/IFile.d.ts +0 -0
- /package/{src → dist}/interfaces/IFile.js +0 -0
- /package/{src → dist}/interfaces/ITranslationDecoratorInterface.d.ts +0 -0
- /package/{src → dist}/interfaces/ITranslationDecoratorInterface.js +0 -0
- /package/{src → dist}/interfaces/index.d.ts +0 -0
- /package/{src → dist}/interfaces/index.js +0 -0
- /package/{src → dist}/interfaces/response.d.ts +0 -0
- /package/{src → dist}/interfaces/response.js +0 -0
- /package/{src → dist}/middlewares/index.d.ts +0 -0
- /package/{src → dist}/middlewares/index.js +0 -0
- /package/{src → dist}/middlewares/omni-auth.middleware.d.ts +0 -0
- /package/{src → dist}/middlewares/omni-auth.middleware.js +0 -0
- /package/{src → dist}/middlewares/powerby.middleware.d.ts +0 -0
- /package/{src → dist}/middlewares/powerby.middleware.js +0 -0
- /package/{src → dist}/middlewares/request-id.middleware.d.ts +0 -0
- /package/{src → dist}/middlewares/request-id.middleware.js +0 -0
- /package/{src → dist}/providers/context.provider.d.ts +0 -0
- /package/{src → dist}/providers/index.d.ts +0 -0
- /package/{src → dist}/providers/index.js +0 -0
- /package/{src → dist}/setup/bootstrap.setup.d.ts +0 -0
- /package/{src → dist}/setup/index.d.ts +0 -0
- /package/{src → dist}/setup/index.js +0 -0
- /package/{src → dist}/setup-swagger.d.ts +0 -0
- /package/{src → dist}/setup-swagger.js +0 -0
- /package/{src → dist}/shared/index.d.ts +0 -0
- /package/{src → dist}/shared/index.js +0 -0
- /package/{src → dist}/shared/serviceRegistryModule.d.ts +0 -0
- /package/{src → dist}/shared/services/aws-s3.service.d.ts +0 -0
- /package/{src → dist}/shared/services/generator.service.d.ts +0 -0
- /package/{src → dist}/shared/services/index.d.ts +0 -0
- /package/{src → dist}/shared/services/index.js +0 -0
- /package/{src → dist}/shared/services/translation.service.d.ts +0 -0
- /package/{src → dist}/shared/services/validator.service.d.ts +0 -0
- /package/{src → dist}/snake-naming.strategy.d.ts +0 -0
- /package/{src → dist}/snake-naming.strategy.js +0 -0
- /package/{src → dist}/types.d.ts +0 -0
- /package/{src → dist}/types.js +0 -0
- /package/{src → dist}/validators/file-mimetype.validator.d.ts +0 -0
- /package/{src → dist}/validators/file-mimetype.validator.js +0 -0
- /package/{src → dist}/validators/index.d.ts +0 -0
- /package/{src → dist}/validators/index.js +0 -0
- /package/{src → dist}/validators/is-exists.validator.d.ts +0 -0
- /package/{src → dist}/validators/is-unique.validator.d.ts +0 -0
- /package/{src → dist}/validators/phone-country-code.validator.d.ts +0 -0
- /package/{src → dist}/validators/phone-country-code.validator.js +0 -0
- /package/{src → dist}/validators/same-as.validator.d.ts +0 -0
- /package/{src → dist}/validators/same-as.validator.js +0 -0
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
3
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
4
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
5
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
6
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
7
|
-
var _, done = false;
|
|
8
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
9
|
-
var context = {};
|
|
10
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
11
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
12
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
13
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
14
|
-
if (kind === "accessor") {
|
|
15
|
-
if (result === void 0) continue;
|
|
16
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
17
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
18
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
19
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
20
|
-
}
|
|
21
|
-
else if (_ = accept(result)) {
|
|
22
|
-
if (kind === "field") initializers.unshift(_);
|
|
23
|
-
else descriptor[key] = _;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
27
|
-
done = true;
|
|
28
|
-
};
|
|
29
|
-
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
30
|
-
var useValue = arguments.length > 2;
|
|
31
|
-
for (var i = 0; i < initializers.length; i++) {
|
|
32
|
-
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
33
|
-
}
|
|
34
|
-
return useValue ? value : void 0;
|
|
35
|
-
};
|
|
36
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
46
|
-
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
47
|
-
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.ServiceHealthIndicator = void 0;
|
|
51
|
-
const common_1 = require("@nestjs/common");
|
|
52
|
-
const terminus_1 = require("@nestjs/terminus");
|
|
53
|
-
const rxjs_1 = require("rxjs");
|
|
54
|
-
const operators_1 = require("rxjs/operators");
|
|
55
|
-
let ServiceHealthIndicator = (() => {
|
|
56
|
-
let _classDecorators = [(0, common_1.Injectable)()];
|
|
57
|
-
let _classDescriptor;
|
|
58
|
-
let _classExtraInitializers = [];
|
|
59
|
-
let _classThis;
|
|
60
|
-
let _classSuper = terminus_1.HealthIndicator;
|
|
61
|
-
var ServiceHealthIndicator = _classThis = class extends _classSuper {
|
|
62
|
-
constructor(clientProxy) {
|
|
63
|
-
super();
|
|
64
|
-
this.clientProxy = clientProxy;
|
|
65
|
-
}
|
|
66
|
-
isHealthy(eventName) {
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
try {
|
|
69
|
-
if (!this.clientProxy) {
|
|
70
|
-
return {
|
|
71
|
-
[eventName]: {
|
|
72
|
-
status: 'down',
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
const result = yield (0, rxjs_1.firstValueFrom)(this.clientProxy.send(eventName, { check: true }).pipe((0, operators_1.timeout)(10000)), {
|
|
77
|
-
defaultValue: undefined,
|
|
78
|
-
});
|
|
79
|
-
return {
|
|
80
|
-
[eventName]: result,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
throw new terminus_1.HealthCheckError(`${eventName} failed`, {
|
|
85
|
-
[eventName]: error,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
__setFunctionName(_classThis, "ServiceHealthIndicator");
|
|
92
|
-
(() => {
|
|
93
|
-
var _a;
|
|
94
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_a = _classSuper[Symbol.metadata]) !== null && _a !== void 0 ? _a : null) : void 0;
|
|
95
|
-
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
96
|
-
ServiceHealthIndicator = _classThis = _classDescriptor.value;
|
|
97
|
-
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
98
|
-
__runInitializers(_classThis, _classExtraInitializers);
|
|
99
|
-
})();
|
|
100
|
-
return ServiceHealthIndicator = _classThis;
|
|
101
|
-
})();
|
|
102
|
-
exports.ServiceHealthIndicator = ServiceHealthIndicator;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Inject, Injectable, Optional } from '@nestjs/common';
|
|
2
|
-
import { ClientProxy } from '@nestjs/microservices';
|
|
3
|
-
import type { HealthIndicatorResult } from '@nestjs/terminus';
|
|
4
|
-
import { HealthCheckError, HealthIndicator } from '@nestjs/terminus';
|
|
5
|
-
import { firstValueFrom } from 'rxjs';
|
|
6
|
-
import { timeout } from 'rxjs/operators';
|
|
7
|
-
|
|
8
|
-
@Injectable()
|
|
9
|
-
export class ServiceHealthIndicator extends HealthIndicator {
|
|
10
|
-
constructor(
|
|
11
|
-
@Optional()
|
|
12
|
-
@Inject('NATS_SERVICE')
|
|
13
|
-
private readonly clientProxy?: ClientProxy,
|
|
14
|
-
) {
|
|
15
|
-
super();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async isHealthy(eventName: string): Promise<HealthIndicatorResult> {
|
|
19
|
-
try {
|
|
20
|
-
if (!this.clientProxy) {
|
|
21
|
-
return {
|
|
22
|
-
[eventName]: {
|
|
23
|
-
status: 'down',
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const result = await firstValueFrom(
|
|
29
|
-
this.clientProxy.send(eventName, { check: true }).pipe(timeout(10000)),
|
|
30
|
-
{
|
|
31
|
-
defaultValue: undefined,
|
|
32
|
-
},
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
[eventName]: result,
|
|
37
|
-
};
|
|
38
|
-
} catch (error) {
|
|
39
|
-
throw new HealthCheckError(`${eventName} failed`, {
|
|
40
|
-
[eventName]: error,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 将枚举值转换成数组
|
|
3
|
-
* @param Enum 枚举
|
|
4
|
-
*/
|
|
5
|
-
export declare function enumToArray<E>(Enum: any): E[];
|
|
6
|
-
/**
|
|
7
|
-
* 生成随机字符串
|
|
8
|
-
* @param {number} length 生成长度
|
|
9
|
-
* @param {string} charSet 指定字符集
|
|
10
|
-
* @returns {string} 生成字符串
|
|
11
|
-
*/
|
|
12
|
-
export declare const randomString: (length?: number, charSet?: string) => string;
|
|
13
|
-
/**
|
|
14
|
-
* 获取服务部署 IP 地址
|
|
15
|
-
*/
|
|
16
|
-
export declare function getIPAdress(): string;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { networkInterfaces } from 'os';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 将枚举值转换成数组
|
|
5
|
-
* @param Enum 枚举
|
|
6
|
-
*/
|
|
7
|
-
export function enumToArray<E>(Enum: any): E[] {
|
|
8
|
-
return Object.keys(Enum)
|
|
9
|
-
.filter((key) => typeof Enum[key as any] === 'number')
|
|
10
|
-
.map((key) => Enum[key]);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 生成随机字符串
|
|
15
|
-
* @param {number} length 生成长度
|
|
16
|
-
* @param {string} charSet 指定字符集
|
|
17
|
-
* @returns {string} 生成字符串
|
|
18
|
-
*/
|
|
19
|
-
export const randomString = (length: number = 8, charSet?: string): string => {
|
|
20
|
-
charSet =
|
|
21
|
-
charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
22
|
-
let randomString = '';
|
|
23
|
-
for (let i = 0; i < length; i++) {
|
|
24
|
-
const randomPoz = Math.floor(Math.random() * charSet.length);
|
|
25
|
-
randomString += charSet.substring(randomPoz, randomPoz + 1);
|
|
26
|
-
}
|
|
27
|
-
return randomString;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 获取服务部署 IP 地址
|
|
32
|
-
*/
|
|
33
|
-
export function getIPAdress(): string {
|
|
34
|
-
const interfaces = networkInterfaces();
|
|
35
|
-
|
|
36
|
-
for (const devName in interfaces) {
|
|
37
|
-
const iface = interfaces[devName];
|
|
38
|
-
for (let i = 0; i < iface.length; i++) {
|
|
39
|
-
const alias = iface[i];
|
|
40
|
-
if (
|
|
41
|
-
alias.family === 'IPv4' &&
|
|
42
|
-
alias.address !== '127.0.0.1' &&
|
|
43
|
-
!alias.internal
|
|
44
|
-
) {
|
|
45
|
-
return alias.address;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { ColumnOptions } from 'typeorm/decorator/options/ColumnOptions';
|
|
2
|
-
import * as moment from 'moment';
|
|
3
|
-
import * as _ from 'lodash';
|
|
4
|
-
|
|
5
|
-
export function timestamp(value?: number) {
|
|
6
|
-
if (!value) {
|
|
7
|
-
value = moment.now();
|
|
8
|
-
}
|
|
9
|
-
return Math.round(value / 1000);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function strToTimeStamp(str: string | Date) {
|
|
13
|
-
if (_.isEmpty(str)) {
|
|
14
|
-
return 0;
|
|
15
|
-
}
|
|
16
|
-
return moment(str).unix();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function getTodayTimeStamp() {
|
|
20
|
-
const startTime = strToTimeStamp(moment().format('YYYY-MM-DD 00:00:00'));
|
|
21
|
-
const endTime = strToTimeStamp(moment().format('YYYY-MM-DD 23:59:59'));
|
|
22
|
-
return {
|
|
23
|
-
startTime,
|
|
24
|
-
endTime,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function unixtimestampToDate(value: number): Date {
|
|
29
|
-
return moment(value * 1000).toDate();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function formatDateTime(
|
|
33
|
-
value: number | string,
|
|
34
|
-
format: string = 'YYYY-MM-DD HH:mm:ss',
|
|
35
|
-
holder: string | null = '',
|
|
36
|
-
): string {
|
|
37
|
-
if (value === 'now') {
|
|
38
|
-
return moment().format(format);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (typeof value === 'string') {
|
|
42
|
-
return value;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (value > 0) {
|
|
46
|
-
return moment(value * 1000).format(format);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return holder;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function timestampColumn(name: string): ColumnOptions {
|
|
53
|
-
return {
|
|
54
|
-
type: 'int',
|
|
55
|
-
name,
|
|
56
|
-
nullable: false,
|
|
57
|
-
default: 0,
|
|
58
|
-
transformer: {
|
|
59
|
-
to: (value) =>
|
|
60
|
-
value === 0 || /\d{10}/.test(value) ? value : strToTimeStamp(value),
|
|
61
|
-
from: (value?: number) => (!value ? value : formatDateTime),
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
interface ExcelImportData {
|
|
2
|
-
status: boolean;
|
|
3
|
-
data?: any[];
|
|
4
|
-
msg?: string;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* 导入 excel 表
|
|
8
|
-
* @param column 在读取 excel 时指定列的位置必须与当前映射的位置相同
|
|
9
|
-
* @param filePath 读取 excel 文件的路径
|
|
10
|
-
* @param hasHeader 是否有表头
|
|
11
|
-
* @param validateDto 校验DTO
|
|
12
|
-
*/
|
|
13
|
-
export declare const importExcel: (column: any, filePath: any, hasHeader: any, validateDto?: any) => Promise<ExcelImportData>;
|
|
14
|
-
/**
|
|
15
|
-
* 导出excel文件
|
|
16
|
-
* @param {Array} columns 列头信息
|
|
17
|
-
* @param {Array} rows 行数据
|
|
18
|
-
* @param {String} sheetName 工作表名称
|
|
19
|
-
* @param {path} savePath 文件保存路径
|
|
20
|
-
* @param {path} style 设置每行高度
|
|
21
|
-
*/
|
|
22
|
-
export declare const exportExcel: (columns: any, rows: any, sheetName: any, savePath?: any, style?: {
|
|
23
|
-
row: {
|
|
24
|
-
height: number;
|
|
25
|
-
};
|
|
26
|
-
}) => Promise<any>;
|
|
27
|
-
export {};
|
|
@@ -1,338 +0,0 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.exportExcel = exports.importExcel = void 0;
|
|
36
|
-
const _ = __importStar(require("lodash"));
|
|
37
|
-
const moment = __importStar(require("moment"));
|
|
38
|
-
const Excel = __importStar(require("exceljs"));
|
|
39
|
-
const path_1 = require("path");
|
|
40
|
-
const fs_1 = require("fs");
|
|
41
|
-
const common_helper_1 = require("./common.helper");
|
|
42
|
-
const class_transformer_1 = require("class-transformer");
|
|
43
|
-
const class_validator_1 = require("class-validator");
|
|
44
|
-
process.on('excel', ({ filePath, rows, columns, sheetName, type, style, hasHeader }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
try {
|
|
46
|
-
if (type === 'export') {
|
|
47
|
-
yield (0, exports.exportExcel)(columns, rows, sheetName, filePath, style);
|
|
48
|
-
process.send({ code: 200, message: '导出成功' });
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
const rows = yield (0, exports.importExcel)(columns, filePath, hasHeader);
|
|
52
|
-
process.send({ code: 200, message: '导入成功', data: rows });
|
|
53
|
-
}
|
|
54
|
-
process.exit();
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
console.log('exceljs export file. Error:', error);
|
|
58
|
-
process.send({ code: 200, message: error.message });
|
|
59
|
-
process.exit();
|
|
60
|
-
}
|
|
61
|
-
}));
|
|
62
|
-
/**
|
|
63
|
-
* 导入 excel 表
|
|
64
|
-
* @param column 在读取 excel 时指定列的位置必须与当前映射的位置相同
|
|
65
|
-
* @param filePath 读取 excel 文件的路径
|
|
66
|
-
* @param hasHeader 是否有表头
|
|
67
|
-
* @param validateDto 校验DTO
|
|
68
|
-
*/
|
|
69
|
-
const importExcel = (column, filePath, hasHeader, validateDto) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
-
const rows = [];
|
|
71
|
-
let [meidaIndex, cells] = [0, 0];
|
|
72
|
-
const workbook = new Excel.Workbook();
|
|
73
|
-
if (typeof filePath === 'string') {
|
|
74
|
-
yield workbook.xlsx.readFile(filePath);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
yield workbook.xlsx.load(filePath);
|
|
78
|
-
}
|
|
79
|
-
const worksheet = yield workbook.getWorksheet(1);
|
|
80
|
-
cells = hasHeader ? Number(worksheet.getRow(1).values.length) : 0;
|
|
81
|
-
for (let r = hasHeader ? 2 : 1; r <= worksheet.rowCount; r++) {
|
|
82
|
-
const row = worksheet.getRow(r);
|
|
83
|
-
const rowData = {};
|
|
84
|
-
for (let i = 1; i < cells; i++) {
|
|
85
|
-
let value = row.getCell(i).value;
|
|
86
|
-
if (row.getCell(i).type === Excel.ValueType.RichText) {
|
|
87
|
-
value = richText2String(value);
|
|
88
|
-
}
|
|
89
|
-
getRowValue(workbook, column, meidaIndex, i, value, rowData);
|
|
90
|
-
}
|
|
91
|
-
if (_.isEmpty(rowData)) {
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (validateDto) {
|
|
95
|
-
const object = (0, class_transformer_1.plainToClass)(validateDto, rowData);
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
const errors = (0, class_validator_1.validateSync)(object, {
|
|
98
|
-
transform: true,
|
|
99
|
-
stopAtFirstError: true,
|
|
100
|
-
forbidNonWhitelisted: false,
|
|
101
|
-
disableErrorMessages: true,
|
|
102
|
-
validateCustomDecorators: true,
|
|
103
|
-
forbidUnknownValues: false,
|
|
104
|
-
enableDebugMessages: true,
|
|
105
|
-
whitelist: true,
|
|
106
|
-
});
|
|
107
|
-
if (errors.length > 0) {
|
|
108
|
-
const error = errors.shift();
|
|
109
|
-
const errorMessage = Object.values(error.constraints);
|
|
110
|
-
return {
|
|
111
|
-
status: false,
|
|
112
|
-
data: rows,
|
|
113
|
-
msg: `Row ${row.number}:${errorMessage}`,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
rows.push(rowData);
|
|
118
|
-
meidaIndex++;
|
|
119
|
-
}
|
|
120
|
-
return { status: true, data: rows };
|
|
121
|
-
});
|
|
122
|
-
exports.importExcel = importExcel;
|
|
123
|
-
/**
|
|
124
|
-
* 获取Excel行值
|
|
125
|
-
* @param workbook 工作簿
|
|
126
|
-
* @param column 列数据
|
|
127
|
-
* @param meidaIndex
|
|
128
|
-
* @param cellIndex 单元格索引
|
|
129
|
-
* @param value 数据
|
|
130
|
-
* @param rowData 返回数据
|
|
131
|
-
*/
|
|
132
|
-
const getRowValue = (workbook, column, meidaIndex, cellIndex, value, rowData) => {
|
|
133
|
-
try {
|
|
134
|
-
const descriptor = _.find(column, { index: cellIndex });
|
|
135
|
-
if (!descriptor || (typeof value !== 'number' && _.isEmpty(value))) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
switch (descriptor.type) {
|
|
139
|
-
case 'Image':
|
|
140
|
-
try {
|
|
141
|
-
if (meidaIndex < workbook.media.length) {
|
|
142
|
-
const image = workbook.media[meidaIndex];
|
|
143
|
-
const filePath = (0, path_1.join)(descriptor.baseUri, (0, common_helper_1.randomString)(12) + '.jpg');
|
|
144
|
-
(0, fs_1.writeFileSync)(filePath, image.buffer);
|
|
145
|
-
_.set(rowData, descriptor.key, getUrlPath(filePath));
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
_.set(rowData, descriptor.key, '');
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
_.set(rowData, descriptor.key, '');
|
|
153
|
-
}
|
|
154
|
-
break;
|
|
155
|
-
case 'String':
|
|
156
|
-
// 处理相同字段具有不同用户情况下,避免漏掉其他字段值,其他字段需要使用cb来实现
|
|
157
|
-
if (!_.get(rowData, descriptor.key)) {
|
|
158
|
-
_.set(rowData, descriptor.key, (descriptor.cb && descriptor.cb(value)) || value || '');
|
|
159
|
-
}
|
|
160
|
-
if (descriptor.link) {
|
|
161
|
-
_.set(rowData, descriptor.link, (descriptor.cb && descriptor.cb(value)) || value || '');
|
|
162
|
-
}
|
|
163
|
-
break;
|
|
164
|
-
case 'Email':
|
|
165
|
-
if (typeof value === 'object' && value.text) {
|
|
166
|
-
value = value.text;
|
|
167
|
-
}
|
|
168
|
-
if (!_.get(rowData, descriptor.key)) {
|
|
169
|
-
_.set(rowData, descriptor.key, (descriptor.cb && descriptor.cb(value)) || value || '');
|
|
170
|
-
}
|
|
171
|
-
break;
|
|
172
|
-
case 'Number':
|
|
173
|
-
if (!_.get(rowData, descriptor.key)) {
|
|
174
|
-
_.set(rowData, descriptor.key, (descriptor.cb && descriptor.cb(value)) || Number(value) || '');
|
|
175
|
-
}
|
|
176
|
-
break;
|
|
177
|
-
case 'Date':
|
|
178
|
-
_.set(rowData, descriptor.key, value ? moment(value).format(descriptor.format || 'X') : '');
|
|
179
|
-
break;
|
|
180
|
-
case 'Enum':
|
|
181
|
-
_.set(rowData, descriptor.key, getEmunValue(descriptor.enum, value));
|
|
182
|
-
break;
|
|
183
|
-
default:
|
|
184
|
-
_.set(rowData, descriptor.key, '错误类型');
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
catch (error) {
|
|
188
|
-
console.log(error);
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* 导出excel文件
|
|
193
|
-
* @param {Array} columns 列头信息
|
|
194
|
-
* @param {Array} rows 行数据
|
|
195
|
-
* @param {String} sheetName 工作表名称
|
|
196
|
-
* @param {path} savePath 文件保存路径
|
|
197
|
-
* @param {path} style 设置每行高度
|
|
198
|
-
*/
|
|
199
|
-
const exportExcel = (columns, rows, sheetName, savePath = null, style = { row: { height: 20 } }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
200
|
-
try {
|
|
201
|
-
const workbook = new Excel.Workbook();
|
|
202
|
-
const sheet = workbook.addWorksheet(sheetName);
|
|
203
|
-
// 设置表头
|
|
204
|
-
sheet.columns = columns.map((column) => {
|
|
205
|
-
return { header: column.name, width: column.size, key: column.key };
|
|
206
|
-
});
|
|
207
|
-
// 设置列的样式,对齐方式、自动换行等样式
|
|
208
|
-
for (let i = 0; i < columns.length; i++) {
|
|
209
|
-
const column = columns[i];
|
|
210
|
-
if (!_.get(column, 'alignment', '')) {
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
sheet.getColumn(column.key).alignment = column.alignment;
|
|
214
|
-
}
|
|
215
|
-
// 设置表头单元格样式与对齐方式
|
|
216
|
-
const rowHeader = sheet.getRow(1);
|
|
217
|
-
for (let i = 1; i <= sheet.columns.length; i++) {
|
|
218
|
-
rowHeader.getCell(i).font = { name: 'Arial Black', size: 12, bold: true };
|
|
219
|
-
rowHeader.getCell(i).alignment = {
|
|
220
|
-
wrapText: false,
|
|
221
|
-
horizontal: 'center',
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
// 填充数据
|
|
225
|
-
for (let index = 0; index < rows.length; index++) {
|
|
226
|
-
const row = rows[index];
|
|
227
|
-
const data = setRowVaules(columns, row, index, sheet, workbook);
|
|
228
|
-
sheet.addRow(data);
|
|
229
|
-
sheet.getRow(index + 2).height = style.row.height;
|
|
230
|
-
}
|
|
231
|
-
if (savePath) {
|
|
232
|
-
return yield workbook.xlsx.writeFile(savePath);
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
return yield workbook.xlsx.writeBuffer();
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
catch (error) {
|
|
239
|
-
console.log(error);
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
exports.exportExcel = exportExcel;
|
|
243
|
-
/**
|
|
244
|
-
* 根据列类型描述收集行数据,由于增加了图片类型,需要同时写入sheet
|
|
245
|
-
* @param {*} columns 数据列描述对象
|
|
246
|
-
* @param {*} row 行数数据项
|
|
247
|
-
* @param {*} rowIndex 行号
|
|
248
|
-
* @param {*} sheet 工作表
|
|
249
|
-
* @param {*} workbook 工作簿
|
|
250
|
-
*/
|
|
251
|
-
const setRowVaules = (columns, row, rowIndex, sheet, workbook) => {
|
|
252
|
-
const rowData = [];
|
|
253
|
-
for (let i = 0; i < columns.length; i++) {
|
|
254
|
-
const column = columns[i];
|
|
255
|
-
switch (column.type) {
|
|
256
|
-
case 'Image':
|
|
257
|
-
const filePath = getImagePath(_.get(row, column.key, ''), column.baseUri);
|
|
258
|
-
if (filePath === '.') {
|
|
259
|
-
rowData.push('');
|
|
260
|
-
}
|
|
261
|
-
else if ((0, fs_1.existsSync)(filePath)) {
|
|
262
|
-
rowData.push('');
|
|
263
|
-
const imageid = workbook.addImage({
|
|
264
|
-
buffer: (0, fs_1.readFileSync)(filePath),
|
|
265
|
-
extension: 'jpeg',
|
|
266
|
-
});
|
|
267
|
-
sheet.addImage(imageid, {
|
|
268
|
-
tl: { col: 0.01 + i, row: rowIndex + 1 },
|
|
269
|
-
ext: { width: 100, height: 100 },
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
rowData.push('未知的图片');
|
|
274
|
-
}
|
|
275
|
-
break;
|
|
276
|
-
case 'Email':
|
|
277
|
-
case 'String':
|
|
278
|
-
case 'Number':
|
|
279
|
-
rowData.push(_.get(row, column.key, ''));
|
|
280
|
-
break;
|
|
281
|
-
case 'Date':
|
|
282
|
-
_.get(row, column.key)
|
|
283
|
-
? rowData.push(moment(_.get(row, column.key, '') * 1000).format('YYYY-MM-DD HH:mm:ss'))
|
|
284
|
-
: rowData.push('');
|
|
285
|
-
break;
|
|
286
|
-
case 'Enum':
|
|
287
|
-
rowData.push(column.enum[_.get(row, column.key, '')] || '');
|
|
288
|
-
break;
|
|
289
|
-
default:
|
|
290
|
-
rowData.push('未知类型的数据');
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return rowData;
|
|
294
|
-
};
|
|
295
|
-
/**
|
|
296
|
-
* 获取枚举值
|
|
297
|
-
* @param {*} enums 枚举对象
|
|
298
|
-
* @param {*} cellValue 单元格值
|
|
299
|
-
*/
|
|
300
|
-
const getEmunValue = (enums, cellValue) => {
|
|
301
|
-
const pairs = Object.entries(enums).find((item) => item[1] === cellValue);
|
|
302
|
-
const value = pairs && Number(pairs[0]);
|
|
303
|
-
if (typeof value === 'number') {
|
|
304
|
-
return value;
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
return pairs && pairs[0];
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
/**
|
|
311
|
-
* 获取图片的磁盘映射路径
|
|
312
|
-
* @param {*} fllePath url路径
|
|
313
|
-
* @param {*} prefix 磁盘映射目录
|
|
314
|
-
*/
|
|
315
|
-
const getImagePath = (filePath, prefix) => {
|
|
316
|
-
const lastPath = (0, path_1.basename)(prefix);
|
|
317
|
-
const regex = new RegExp(`.*/${lastPath}`);
|
|
318
|
-
return (0, path_1.normalize)(filePath.replace(regex, prefix));
|
|
319
|
-
};
|
|
320
|
-
/**
|
|
321
|
-
* 获取图片的磁盘映射路径
|
|
322
|
-
* @param {*} fllePath url路径
|
|
323
|
-
* @param {*} separator 磁盘映射目录
|
|
324
|
-
*/
|
|
325
|
-
const getUrlPath = (filePath, separator = 'pic') => {
|
|
326
|
-
return (0, path_1.normalize)(`/image${filePath.split(separator).pop()}`);
|
|
327
|
-
};
|
|
328
|
-
/**
|
|
329
|
-
* excel富文本格式转换成字符串
|
|
330
|
-
* @param {*} values 富文本对象
|
|
331
|
-
*/
|
|
332
|
-
const richText2String = (values) => {
|
|
333
|
-
let str = '';
|
|
334
|
-
for (const [, value] of Object.entries(values.richText)) {
|
|
335
|
-
str += _.get(value, 'text', '');
|
|
336
|
-
}
|
|
337
|
-
return str;
|
|
338
|
-
};
|
package/src/helpers/index.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"NOT_EMPTY": "{property} cannot be empty",
|
|
3
|
-
"NOT_EQUALS": "{property} should not be equal to {constraints.1}",
|
|
4
|
-
"LENGTH": "{property} needs to be at least {constraints.0} and at most {constraints.1} characters long",
|
|
5
|
-
"MIN_LENGTH": "{property} needs to be at least {constraints.0} characters long",
|
|
6
|
-
"MAX_LENGTH": "{property} needs to be at most {constraints.0} characters long",
|
|
7
|
-
"INVALID_EMAIL": " {property} is invalid email",
|
|
8
|
-
"INVALID_BOOLEAN": "{property} is not a boolean",
|
|
9
|
-
"MIN": "{property} with value: \"{value}\" needs to be at least {constraints.0}",
|
|
10
|
-
"MAX": "{property} with value: \"{value}\" needs to be less than {constraints.0}",
|
|
11
|
-
"NOT_FOUND": "Not Found",
|
|
12
|
-
"DELETE_FAILED": "Gagal menghapus data",
|
|
13
|
-
"FILE_NOT_EMPTY": "File tidak boleh kosong",
|
|
14
|
-
"FILE_ONLY_EXCEL": "Hanya menerima extensi xlsx, xls",
|
|
15
|
-
"EMAIL_EXISTS": "email already exits",
|
|
16
|
-
"CONFIRM_PASSWORD_NOT_MATCH": "confirm password not match",
|
|
17
|
-
"INVALID_STRING": "{property} must be a string",
|
|
18
|
-
"INVALID_DATETIME": "{property} is not a valid date",
|
|
19
|
-
"IS_NUMBER": "{property} must be a number",
|
|
20
|
-
"IS_ENUM": "{property} must be one of the following values: {constraints.1}",
|
|
21
|
-
"IS_STRING": "{property} must be a string",
|
|
22
|
-
"IS_ARRAY": "{property} must be an array",
|
|
23
|
-
"IS_URL": "{property} must be a URL",
|
|
24
|
-
"IS_UUID": "{property} must be a UUID",
|
|
25
|
-
"IS_DATE": "{property} must be a Date instance",
|
|
26
|
-
"MIN_DATE": "{property} should be later than {constraints.0}",
|
|
27
|
-
"MIN_DATE_NOW": "{property} should be later than the current time",
|
|
28
|
-
"MAX_DATE": "{property} should be earlier than {constraints.0}",
|
|
29
|
-
"MAX_DATE_NOW": "{property} should be earlier than current time",
|
|
30
|
-
"IS_IN": "{property} must be one of the following values: {constraints.1}",
|
|
31
|
-
"IS_INT": "{property} must be an integer number",
|
|
32
|
-
"IS_POSITIVE": "{property} must be a positive number",
|
|
33
|
-
"IS_NOT_EMPTY": "{property} should not be empty",
|
|
34
|
-
"IS_UNIQUE": "{property} with the same value `{value}` exists",
|
|
35
|
-
"IS_EXISTS": "{property} value `{value}` does not exists",
|
|
36
|
-
"IS_FQDN": "{property} value `{value}` not a valid FQDN",
|
|
37
|
-
"IS_IP": "{property} value `{value}` not a valid IP"
|
|
38
|
-
}
|