plac-micro-common 1.1.9 → 1.1.11

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,5 +1,6 @@
1
1
  export * from "./common";
2
2
  export * from "./decorators";
3
- export * from "./modules";
4
3
  export * from "./guards";
4
+ export * from "./modules";
5
+ export * from "./pipes";
5
6
  export * from "./services";
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./common"), exports);
18
18
  __exportStar(require("./decorators"), exports);
19
- __exportStar(require("./modules"), exports);
20
19
  __exportStar(require("./guards"), exports);
20
+ __exportStar(require("./modules"), exports);
21
+ __exportStar(require("./pipes"), exports);
21
22
  __exportStar(require("./services"), exports);
@@ -0,0 +1,8 @@
1
+ import { ValidationError, ValidationPipe } from "@nestjs/common";
2
+ export type PlacValidationErrorBody = {
3
+ code: "VALIDATION_ERROR";
4
+ message: string;
5
+ errors: Record<string, string[]>;
6
+ };
7
+ export declare function flattenValidationErrors(validationErrors?: ValidationError[]): Record<string, string[]>;
8
+ export declare function createGlobalValidationPipe(): ValidationPipe;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flattenValidationErrors = flattenValidationErrors;
4
+ exports.createGlobalValidationPipe = createGlobalValidationPipe;
5
+ const common_1 = require("@nestjs/common");
6
+ function flattenValidationErrors(validationErrors = []) {
7
+ const errors = {};
8
+ const walk = (err, parentPath = "") => {
9
+ const path = parentPath ? `${parentPath}.${err.property}` : err.property;
10
+ if (err.constraints) {
11
+ errors[path] ??= [];
12
+ errors[path].push(...Object.values(err.constraints));
13
+ }
14
+ if (err.children?.length) {
15
+ for (const child of err.children)
16
+ walk(child, path);
17
+ }
18
+ };
19
+ for (const err of validationErrors)
20
+ walk(err);
21
+ return errors;
22
+ }
23
+ function createGlobalValidationPipe() {
24
+ return new common_1.ValidationPipe({
25
+ whitelist: true,
26
+ skipMissingProperties: false,
27
+ transform: true,
28
+ transformOptions: { enableImplicitConversion: true },
29
+ exceptionFactory: (validationErrors = []) => {
30
+ const errors = flattenValidationErrors(validationErrors);
31
+ // IMPORTANT: don't add trace_id/success here — let your exception filter do it globally.
32
+ const body = {
33
+ code: "VALIDATION_ERROR",
34
+ message: "Request validation failed",
35
+ errors,
36
+ };
37
+ return new common_1.BadRequestException(body);
38
+ },
39
+ });
40
+ }
@@ -0,0 +1 @@
1
+ export * from "./global_validation.pipe";
@@ -0,0 +1,17 @@
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("./global_validation.pipe"), exports);
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./http";
2
+ export * from "./models";
2
3
  export * from "./types";
3
4
  export * from "./utils";
package/dist/index.js CHANGED
@@ -15,5 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./http"), exports);
18
+ __exportStar(require("./models"), exports);
18
19
  __exportStar(require("./types"), exports);
19
20
  __exportStar(require("./utils"), exports);
@@ -0,0 +1,6 @@
1
+ export declare abstract class _BaseEntity {
2
+ created_by?: string | null;
3
+ updated_by?: string | null;
4
+ created_at: Date;
5
+ updated_at: Date;
6
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports._BaseEntity = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ class _BaseEntity {
15
+ }
16
+ exports._BaseEntity = _BaseEntity;
17
+ __decorate([
18
+ (0, typeorm_1.Column)({ type: "uuid", nullable: true }),
19
+ __metadata("design:type", Object)
20
+ ], _BaseEntity.prototype, "created_by", void 0);
21
+ __decorate([
22
+ (0, typeorm_1.Column)({ type: "uuid", nullable: true }),
23
+ __metadata("design:type", Object)
24
+ ], _BaseEntity.prototype, "updated_by", void 0);
25
+ __decorate([
26
+ (0, typeorm_1.CreateDateColumn)(),
27
+ __metadata("design:type", Date)
28
+ ], _BaseEntity.prototype, "created_at", void 0);
29
+ __decorate([
30
+ (0, typeorm_1.UpdateDateColumn)(),
31
+ __metadata("design:type", Date)
32
+ ], _BaseEntity.prototype, "updated_at", void 0);
@@ -0,0 +1,8 @@
1
+ import { _BaseEntity } from "./_base_entity";
2
+ export declare abstract class _BaseGeneralEntity extends _BaseEntity {
3
+ id: string;
4
+ name: string;
5
+ name_kh?: string | null;
6
+ description?: string | null;
7
+ is_active: boolean;
8
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports._BaseGeneralEntity = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ const _base_entity_1 = require("./_base_entity");
15
+ class _BaseGeneralEntity extends _base_entity_1._BaseEntity {
16
+ }
17
+ exports._BaseGeneralEntity = _BaseGeneralEntity;
18
+ __decorate([
19
+ (0, typeorm_1.PrimaryGeneratedColumn)("uuid"),
20
+ __metadata("design:type", String)
21
+ ], _BaseGeneralEntity.prototype, "id", void 0);
22
+ __decorate([
23
+ (0, typeorm_1.Column)({ type: "varchar", length: 255 }),
24
+ __metadata("design:type", String)
25
+ ], _BaseGeneralEntity.prototype, "name", void 0);
26
+ __decorate([
27
+ (0, typeorm_1.Column)({ type: "varchar", length: 255, nullable: true }),
28
+ __metadata("design:type", Object)
29
+ ], _BaseGeneralEntity.prototype, "name_kh", void 0);
30
+ __decorate([
31
+ (0, typeorm_1.Column)({ type: "varchar", length: 500, nullable: true }),
32
+ __metadata("design:type", Object)
33
+ ], _BaseGeneralEntity.prototype, "description", void 0);
34
+ __decorate([
35
+ (0, typeorm_1.Column)({ type: "boolean", default: true }),
36
+ __metadata("design:type", Boolean)
37
+ ], _BaseGeneralEntity.prototype, "is_active", void 0);
@@ -0,0 +1,6 @@
1
+ import { _BaseEntity } from "./_base_entity";
2
+ export declare abstract class _baseOwnershipEntity extends _BaseEntity {
3
+ partner_id?: string;
4
+ staff_id?: string | null;
5
+ branch_id?: string | null;
6
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports._baseOwnershipEntity = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ const _base_entity_1 = require("./_base_entity");
15
+ class _baseOwnershipEntity extends _base_entity_1._BaseEntity {
16
+ }
17
+ exports._baseOwnershipEntity = _baseOwnershipEntity;
18
+ __decorate([
19
+ (0, typeorm_1.Column)({ type: "uuid", nullable: true }),
20
+ (0, typeorm_1.Index)(),
21
+ __metadata("design:type", String)
22
+ ], _baseOwnershipEntity.prototype, "partner_id", void 0);
23
+ __decorate([
24
+ (0, typeorm_1.Column)({ type: "uuid", nullable: true }),
25
+ (0, typeorm_1.Index)(),
26
+ __metadata("design:type", Object)
27
+ ], _baseOwnershipEntity.prototype, "staff_id", void 0);
28
+ __decorate([
29
+ (0, typeorm_1.Column)({ type: "uuid", nullable: true }),
30
+ (0, typeorm_1.Index)(),
31
+ __metadata("design:type", Object)
32
+ ], _baseOwnershipEntity.prototype, "branch_id", void 0);
@@ -0,0 +1,3 @@
1
+ export * from "./_base_entity";
2
+ export * from "./_base_general_entity";
3
+ export * from "./_base_ownership_entity";
@@ -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("./_base_entity"), exports);
18
+ __exportStar(require("./_base_general_entity"), exports);
19
+ __exportStar(require("./_base_ownership_entity"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plac-micro-common",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -30,6 +30,7 @@
30
30
  "@nestjs/common": "^11.1.9",
31
31
  "@nestjs/core": "^11.1.9",
32
32
  "express": "^5.2.1",
33
- "jsonwebtoken": "^9.0.3"
33
+ "jsonwebtoken": "^9.0.3",
34
+ "typeorm": "^0.3.28"
34
35
  }
35
36
  }