aws-service-stack 0.17.268 → 0.17.270
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/dist/_examples/controller/branch/branch-config.d.ts +6 -0
- package/dist/_examples/controller/branch/branch-config.js +47 -0
- package/dist/_examples/controller/branch/branch-config.js.map +1 -0
- package/dist/_examples/controller/branch/branch-controller.d.ts +16 -0
- package/dist/_examples/controller/branch/branch-controller.js +77 -0
- package/dist/_examples/controller/branch/branch-controller.js.map +1 -0
- package/dist/_examples/controller/branch/branch-crud.d.ts +4 -0
- package/dist/_examples/controller/branch/branch-crud.js +57 -0
- package/dist/_examples/controller/branch/branch-crud.js.map +1 -0
- package/dist/_examples/controller/commission/commission-controller.d.ts +9 -0
- package/dist/_examples/controller/commission/commission-controller.js +66 -0
- package/dist/_examples/controller/commission/commission-controller.js.map +1 -0
- package/dist/_examples/controller/commission/commission-crud.d.ts +4 -0
- package/dist/_examples/controller/commission/commission-crud.js +57 -0
- package/dist/_examples/controller/commission/commission-crud.js.map +1 -0
- package/dist/_examples/controller/commission/commission.config.d.ts +6 -0
- package/dist/_examples/controller/commission/commission.config.js +41 -0
- package/dist/_examples/controller/commission/commission.config.js.map +1 -0
- package/dist/_examples/controller/raccount/raccount-config.d.ts +6 -0
- package/dist/_examples/controller/raccount/raccount-config.js +60 -0
- package/dist/_examples/controller/raccount/raccount-config.js.map +1 -0
- package/dist/_examples/controller/raccount/raccount-controller.d.ts +14 -0
- package/dist/_examples/controller/raccount/raccount-controller.js +73 -0
- package/dist/_examples/controller/raccount/raccount-controller.js.map +1 -0
- package/dist/_examples/controller/raccount/raccount-crud.d.ts +4 -0
- package/dist/_examples/controller/raccount/raccount-crud.js +57 -0
- package/dist/_examples/controller/raccount/raccount-crud.js.map +1 -0
- package/dist/_examples/controller/rorder/order-config.js +3 -5
- package/dist/_examples/controller/rorder/order-config.js.map +1 -1
- package/dist/_examples/controller/supplier/supplier-config.js +8 -8
- package/dist/_examples/controller/supplier/supplier-config.js.map +1 -1
- package/dist/_examples/controller/supplier/supplier-controller-api.d.ts +1 -1
- package/dist/_examples/controller/supplier/supplier-controller-api.js.map +1 -1
- package/dist/_examples/model-shared/address.model.d.ts +18 -0
- package/dist/_examples/model-shared/address.model.js +3 -0
- package/dist/_examples/model-shared/address.model.js.map +1 -0
- package/dist/_examples/model-shared/branch.model.d.ts +72 -0
- package/dist/_examples/model-shared/branch.model.js +64 -0
- package/dist/_examples/model-shared/branch.model.js.map +1 -0
- package/dist/_examples/model-shared/commission.model.d.ts +30 -0
- package/dist/_examples/model-shared/commission.model.js +38 -0
- package/dist/_examples/model-shared/commission.model.js.map +1 -0
- package/dist/_examples/model-shared/raccount.model.d.ts +134 -0
- package/dist/_examples/model-shared/raccount.model.js +187 -0
- package/dist/_examples/model-shared/raccount.model.js.map +1 -0
- package/dist/_examples/model-shared/{suppler.model.js → suppler.model-to-remove.js} +1 -1
- package/dist/_examples/model-shared/suppler.model-to-remove.js.map +1 -0
- package/dist/_examples/model-shared/supplier-portal.model.d.ts +4 -0
- package/dist/_examples/model-shared/supplier-portal.model.js.map +1 -1
- package/dist/_examples/model-shared/supplier.model.d.ts +77 -0
- package/dist/_examples/model-shared/supplier.model.js +124 -0
- package/dist/_examples/model-shared/supplier.model.js.map +1 -0
- package/dist/_examples/repositories/branch/branch-db.repo.d.ts +6 -0
- package/dist/_examples/repositories/branch/branch-db.repo.interface.d.ts +4 -0
- package/dist/_examples/repositories/branch/branch-db.repo.interface.js +3 -0
- package/dist/_examples/repositories/branch/branch-db.repo.interface.js.map +1 -0
- package/dist/_examples/repositories/branch/branch-db.repo.js +19 -0
- package/dist/_examples/repositories/branch/branch-db.repo.js.map +1 -0
- package/dist/_examples/repositories/commission/commission-repo-db.d.ts +5 -0
- package/dist/_examples/repositories/commission/commission-repo-db.interface.d.ts +4 -0
- package/dist/_examples/repositories/commission/commission-repo-db.interface.js +3 -0
- package/dist/_examples/repositories/commission/commission-repo-db.interface.js.map +1 -0
- package/dist/_examples/repositories/commission/commission-repo-db.js +18 -0
- package/dist/_examples/repositories/commission/commission-repo-db.js.map +1 -0
- package/dist/_examples/repositories/raccount/raccount-db.repo.d.ts +5 -0
- package/dist/_examples/repositories/raccount/raccount-db.repo.interface.d.ts +4 -0
- package/dist/_examples/repositories/raccount/raccount-db.repo.interface.js +3 -0
- package/dist/_examples/repositories/raccount/raccount-db.repo.interface.js.map +1 -0
- package/dist/_examples/repositories/raccount/raccount-db.repo.js +18 -0
- package/dist/_examples/repositories/raccount/raccount-db.repo.js.map +1 -0
- package/dist/_examples/repositories/raccount/raccount-es.repo.d.ts +6 -0
- package/dist/_examples/repositories/raccount/raccount-es.repo.interface.d.ts +4 -0
- package/dist/_examples/repositories/raccount/raccount-es.repo.interface.js +3 -0
- package/dist/_examples/repositories/raccount/raccount-es.repo.interface.js.map +1 -0
- package/dist/_examples/repositories/raccount/raccount-es.repo.js +19 -0
- package/dist/_examples/repositories/raccount/raccount-es.repo.js.map +1 -0
- package/dist/_examples/repositories/supplier/supplier-repo-db.d.ts +1 -1
- package/dist/_examples/repositories/supplier/supplier-repo-db.interface.d.ts +1 -1
- package/dist/_examples/repositories/supplier/supplier-repo-db.interface.js.map +1 -1
- package/dist/_examples/repositories/supplier/supplier-repo-db.js.map +1 -1
- package/dist/_examples/repositories/supplier/supplier-repo-es.d.ts +1 -1
- package/dist/_examples/repositories/supplier/supplier-repo-es.interface.d.ts +1 -1
- package/dist/_examples/repositories/supplier/supplier-repo-es.interface.js.map +1 -1
- package/dist/_examples/repositories/supplier/supplier-repo-es.js.map +1 -1
- package/dist/_examples/service/branch/branch-service.d.ts +13 -0
- package/dist/_examples/service/branch/branch-service.interface.d.ts +4 -0
- package/dist/_examples/service/branch/branch-service.interface.js +3 -0
- package/dist/_examples/service/branch/branch-service.interface.js.map +1 -0
- package/dist/_examples/service/branch/branch-service.js +70 -0
- package/dist/_examples/service/branch/branch-service.js.map +1 -0
- package/dist/_examples/service/commission/commission-service.d.ts +15 -0
- package/dist/_examples/service/commission/commission-service.interface.d.ts +6 -0
- package/dist/_examples/service/commission/commission-service.interface.js +3 -0
- package/dist/_examples/service/commission/commission-service.interface.js.map +1 -0
- package/dist/_examples/service/commission/commission-service.js +114 -0
- package/dist/_examples/service/commission/commission-service.js.map +1 -0
- package/dist/_examples/service/raccount/raccount-service.d.ts +10 -0
- package/dist/_examples/service/raccount/raccount-service.interface.d.ts +4 -0
- package/dist/_examples/service/raccount/raccount-service.interface.js +3 -0
- package/dist/_examples/service/raccount/raccount-service.interface.js.map +1 -0
- package/dist/_examples/service/raccount/raccount-service.js +64 -0
- package/dist/_examples/service/raccount/raccount-service.js.map +1 -0
- package/dist/_examples/service/supplier/supplier-service-crud.d.ts +1 -1
- package/dist/_examples/service/supplier/supplier-service-crud.interface.d.ts +1 -1
- package/dist/_examples/service/supplier/supplier-service-crud.interface.js.map +1 -1
- package/dist/_examples/service/supplier/supplier-service-crud.js.map +1 -1
- package/dist/_examples/service/supplier/supplier-service-stream.d.ts +1 -1
- package/dist/_examples/service/supplier/supplier-service-stream.interface.d.ts +1 -1
- package/dist/_examples/service/supplier/supplier-service-stream.interface.js.map +1 -1
- package/dist/_examples/service/supplier/supplier-service-stream.js.map +1 -1
- package/dist/controller/controller-api.js +3 -3
- package/dist/controller/controller-api.js.map +1 -1
- package/dist/exception/exception-handler.js +4 -0
- package/dist/exception/exception-handler.js.map +1 -1
- package/dist/model/base.config.d.ts +4 -4
- package/dist/model/base.config.js +8 -6
- package/dist/model/base.config.js.map +1 -1
- package/dist/model/dynamodb.model.d.ts +2 -4
- package/dist/model/dynamodb.model.js +1 -3
- package/dist/model/dynamodb.model.js.map +1 -1
- package/dist/repositories/base-db.repo.d.ts +8 -7
- package/dist/repositories/base-db.repo.js +53 -31
- package/dist/repositories/base-db.repo.js.map +1 -1
- package/dist/service/crud.service.js +15 -8
- package/dist/service/crud.service.js.map +1 -1
- package/dist/utils/http/http.util.js +12 -2
- package/dist/utils/http/http.util.js.map +1 -1
- package/package.json +1 -1
- package/dist/_examples/model-shared/suppler.model.js.map +0 -1
- /package/dist/_examples/model-shared/{suppler.model.d.ts → suppler.model-to-remove.d.ts} +0 -0
|
@@ -0,0 +1,114 @@
|
|
|
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.CommissionServiceImpl = void 0;
|
|
49
|
+
const service_1 = require("src/service");
|
|
50
|
+
const exception_handler_1 = require("src/exception/exception-handler");
|
|
51
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
52
|
+
const typedi_1 = __importStar(require("typedi"));
|
|
53
|
+
require("src/_examples/repositories/commission/commission-repo-db");
|
|
54
|
+
require("../supplier/supplier-service-crud");
|
|
55
|
+
require("../raccount/raccount-service");
|
|
56
|
+
const raccount_model_1 = require("src/_examples/model-shared/raccount.model");
|
|
57
|
+
let CommissionServiceImpl = class CommissionServiceImpl extends service_1.CrudServiceImpl {
|
|
58
|
+
feePool;
|
|
59
|
+
supplierService;
|
|
60
|
+
rAccountService;
|
|
61
|
+
constructor() {
|
|
62
|
+
const repoDB = typedi_1.default.get("CommissionRepoDB");
|
|
63
|
+
super(repoDB, null);
|
|
64
|
+
this.feePool = new Map();
|
|
65
|
+
this.supplierService = typedi_1.default.get("SupplierCrudService");
|
|
66
|
+
this.rAccountService = typedi_1.default.get("RAccountService");
|
|
67
|
+
}
|
|
68
|
+
async create(supplierUsername, retailerUsername, toRetailerPercent) {
|
|
69
|
+
const supplier = (await this.supplierService.find({ username: supplierUsername })).items[0];
|
|
70
|
+
const retailer = (await this.rAccountService.find({ username: retailerUsername })).items[0];
|
|
71
|
+
if (retailer.contractStatus === raccount_model_1.ContractStatus.EXPIRED) {
|
|
72
|
+
this.throwError(exception_handler_1.HTTP.BAD_REQUEST.code, "Уг retailer идэвхжээгүй байна.");
|
|
73
|
+
}
|
|
74
|
+
const existingFee = await this.find({
|
|
75
|
+
supplierUsername,
|
|
76
|
+
retailerUsername,
|
|
77
|
+
});
|
|
78
|
+
if (existingFee.items.length > 0) {
|
|
79
|
+
this.throwError(exception_handler_1.HTTP.BAD_REQUEST.code, `Fee already exist on supplier: ${supplierUsername} and retailer: ${retailerUsername}`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const percentage = retailer.commission1 ?? retailer.commission2;
|
|
83
|
+
return this.save({
|
|
84
|
+
supplierUsername: supplierUsername,
|
|
85
|
+
retailerUsername: retailerUsername,
|
|
86
|
+
toRetailerPercent: toRetailerPercent ?? percentage,
|
|
87
|
+
supplier: {
|
|
88
|
+
firstName: supplier.firstName + " " + supplier.lastName,
|
|
89
|
+
username: supplier.username,
|
|
90
|
+
taxPayer: supplier.taxPayer,
|
|
91
|
+
},
|
|
92
|
+
retailer: retailer,
|
|
93
|
+
isActive: true,
|
|
94
|
+
createdMonth: (0, dayjs_1.default)(new Date()).format("YYYY-MM-DD"),
|
|
95
|
+
}, retailerUsername);
|
|
96
|
+
}
|
|
97
|
+
async getRetailerCommissionBySupplier(retailerRegNum, supplierRegNum) {
|
|
98
|
+
if (!retailerRegNum || !supplierRegNum) {
|
|
99
|
+
console.error("retailerRegNum or supplierRegNum is missing");
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
const percentList = await this.findAllByIndex("byOwner", supplierRegNum);
|
|
103
|
+
const fee = percentList
|
|
104
|
+
.filter((item) => item.retailerUsername === retailerRegNum)
|
|
105
|
+
.map((item) => item.toRetailerPercent)[0];
|
|
106
|
+
return !fee ? 0 : fee;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
exports.CommissionServiceImpl = CommissionServiceImpl;
|
|
110
|
+
exports.CommissionServiceImpl = CommissionServiceImpl = __decorate([
|
|
111
|
+
(0, typedi_1.Service)("CommissionService"),
|
|
112
|
+
__metadata("design:paramtypes", [])
|
|
113
|
+
], CommissionServiceImpl);
|
|
114
|
+
//# sourceMappingURL=commission-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commission-service.js","sourceRoot":"","sources":["../../../../src/_examples/service/commission/commission-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA8C;AAC9C,uEAAuD;AACvD,kDAA0B;AAC1B,iDAA4C;AAG5C,oEAAkE;AAGlE,6CAA2C;AAG3C,wCAAsC;AAGtC,8EAAqF;AAK9E,IAAM,qBAAqB,GAA3B,MAAM,qBACX,SAAQ,yBAAmD;IAG1C,OAAO,CAAsB;IAC7B,eAAe,CAAkB;IACjC,eAAe,CAAkB;IAElD;QACE,MAAM,MAAM,GAAqB,gBAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;QACnE,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;QAEzC,IAAI,CAAC,eAAe,GAAG,gBAAS,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QAC5D,IAAI,CAAC,eAAe,GAAG,gBAAS,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,gBAAwB,EAAE,gBAAwB,EAAE,iBAA0B;QACzF,MAAM,QAAQ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IAAA,eAAK,EAAC,IAAI,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;SACrD,EACD,gBAAgB,CACjB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,+BAA+B,CAAC,cAAsB,EAAE,cAAsB;QAClF,IAAI,CAAC,cAAc,IAAI,CAAC,cAAc,EAAE,CAAC;YACvC,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;YAC7D,OAAO,CAAC,CAAC;QACX,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QAEzE,MAAM,GAAG,GAAG,WAAW;aACpB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,gBAAgB,KAAK,cAAc,CAAC;aAC1D,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;QAE5C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACxB,CAAC;CACF,CAAA;AAxEY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,gBAAO,EAAC,mBAAmB,CAAC;;GAChB,qBAAqB,CAwEjC","sourcesContent":["import { CrudServiceImpl } from \"src/service\";\nimport { HTTP } from \"src/exception/exception-handler\";\nimport dayjs from \"dayjs\";\nimport Container, { Service } from \"typedi\";\n\nimport { CommissionRepoDB } from \"src/_examples/repositories/commission/commission-repo-db.interface\";\nimport \"src/_examples/repositories/commission/commission-repo-db\";\n\nimport { SupplierService } from \"../supplier/supplier-service-crud.interface\";\nimport \"../supplier/supplier-service-crud\";\n\nimport { RAccountService } from \"../raccount/raccount-service.interface\";\nimport \"../raccount/raccount-service\";\n\nimport { Commission } from \"src/_examples/model-shared/commission.model\";\nimport { ContractStatus, Retailer } from \"src/_examples/model-shared/raccount.model\";\n\nimport { CommissionService } from \"./commission-service.interface\";\n\n@Service(\"CommissionService\")\nexport class CommissionServiceImpl\n extends CrudServiceImpl<Commission, CommissionRepoDB, null>\n implements CommissionService\n{\n private readonly feePool: Map<string, number>;\n private readonly supplierService: SupplierService;\n private readonly rAccountService: RAccountService;\n\n constructor() {\n const repoDB: CommissionRepoDB = Container.get(\"CommissionRepoDB\");\n super(repoDB, null);\n this.feePool = new Map<string, number>();\n\n this.supplierService = Container.get(\"SupplierCrudService\");\n this.rAccountService = Container.get(\"RAccountService\");\n }\n\n async create(supplierUsername: string, retailerUsername: string, toRetailerPercent?: number): Promise<Commission> {\n const supplier = (await this.supplierService.find({ username: supplierUsername })).items[0];\n const retailer = (await this.rAccountService.find({ username: retailerUsername })).items[0];\n\n if (retailer.contractStatus === ContractStatus.EXPIRED) {\n this.throwError(HTTP.BAD_REQUEST.code, \"Уг retailer идэвхжээгүй байна.\");\n }\n\n const existingFee = await this.find({\n supplierUsername,\n retailerUsername,\n });\n\n if (existingFee.items.length > 0) {\n this.throwError(\n HTTP.BAD_REQUEST.code,\n `Fee already exist on supplier: ${supplierUsername} and retailer: ${retailerUsername}`,\n );\n return;\n }\n\n const percentage = retailer.commission1 ?? retailer.commission2;\n\n return this.save(\n {\n supplierUsername: supplierUsername,\n retailerUsername: retailerUsername,\n toRetailerPercent: toRetailerPercent ?? percentage,\n supplier: {\n firstName: supplier.firstName + \" \" + supplier.lastName,\n username: supplier.username,\n taxPayer: supplier.taxPayer,\n },\n retailer: retailer as Retailer,\n isActive: true,\n createdMonth: dayjs(new Date()).format(\"YYYY-MM-DD\"),\n },\n retailerUsername,\n );\n }\n\n async getRetailerCommissionBySupplier(retailerRegNum: string, supplierRegNum: string): Promise<number> {\n if (!retailerRegNum || !supplierRegNum) {\n console.error(\"retailerRegNum or supplierRegNum is missing\");\n return 0;\n }\n\n const percentList = await this.findAllByIndex(\"byOwner\", supplierRegNum);\n\n const fee = percentList\n .filter((item) => item.retailerUsername === retailerRegNum)\n .map((item) => item.toRetailerPercent)[0];\n\n return !fee ? 0 : fee;\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Retailer } from "src/_examples/model-shared/raccount.model";
|
|
2
|
+
import { CrudServiceImpl } from "src/service";
|
|
3
|
+
import { RAccountRepoDB } from "src/_examples/repositories/raccount/raccount-db.repo.interface";
|
|
4
|
+
import "src/_examples/repositories/raccount/raccount-db.repo";
|
|
5
|
+
import { RAccountRepoES } from "src/_examples/repositories/raccount/raccount-es.repo.interface";
|
|
6
|
+
import "src/_examples/repositories/raccount/raccount-es.repo";
|
|
7
|
+
import { RAccountService } from "./raccount-service.interface";
|
|
8
|
+
export declare class RAccountServiceImpl extends CrudServiceImpl<Retailer, RAccountRepoDB, RAccountRepoES> implements RAccountService {
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raccount-service.interface.js","sourceRoot":"","sources":["../../../../src/_examples/service/raccount/raccount-service.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { Retailer } from \"src/_examples/model-shared/raccount.model\";\nimport { CrudService } from \"src/service\";\n\nexport interface RAccountService extends CrudService<Retailer> {}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.RAccountServiceImpl = void 0;
|
|
46
|
+
const typedi_1 = __importStar(require("typedi"));
|
|
47
|
+
const service_1 = require("src/service");
|
|
48
|
+
require("src/_examples/repositories/raccount/raccount-db.repo");
|
|
49
|
+
require("src/_examples/repositories/raccount/raccount-es.repo");
|
|
50
|
+
const raccount_config_1 = require("src/_examples/controller/raccount/raccount-config");
|
|
51
|
+
let RAccountServiceImpl = class RAccountServiceImpl extends service_1.CrudServiceImpl {
|
|
52
|
+
constructor() {
|
|
53
|
+
const repoDB = typedi_1.default.get("RAccountRepoDB");
|
|
54
|
+
const repoES = typedi_1.default.get("RAccountRepoES");
|
|
55
|
+
super(repoDB, repoES);
|
|
56
|
+
this.setConfig(raccount_config_1.CONFIG_RETAILER);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.RAccountServiceImpl = RAccountServiceImpl;
|
|
60
|
+
exports.RAccountServiceImpl = RAccountServiceImpl = __decorate([
|
|
61
|
+
(0, typedi_1.Service)("RAccountService"),
|
|
62
|
+
__metadata("design:paramtypes", [])
|
|
63
|
+
], RAccountServiceImpl);
|
|
64
|
+
//# sourceMappingURL=raccount-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raccount-service.js","sourceRoot":"","sources":["../../../../src/_examples/service/raccount/raccount-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAA4C;AAC5C,yCAA8C;AAG9C,gEAA8D;AAG9D,gEAA8D;AAE9D,uFAAoF;AAK7E,IAAM,mBAAmB,GAAzB,MAAM,mBACX,SAAQ,yBAAyD;IAGjE;QACE,MAAM,MAAM,GAAmB,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC/D,MAAM,MAAM,GAAmB,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC/D,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACtB,IAAI,CAAC,SAAS,CAAC,iCAAe,CAAC,CAAC;IAClC,CAAC;CACF,CAAA;AAVY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,gBAAO,EAAC,iBAAiB,CAAC;;GACd,mBAAmB,CAU/B","sourcesContent":["import { Retailer } from \"src/_examples/model-shared/raccount.model\";\nimport Container, { Service } from \"typedi\";\nimport { CrudServiceImpl } from \"src/service\";\n\nimport { RAccountRepoDB } from \"src/_examples/repositories/raccount/raccount-db.repo.interface\";\nimport \"src/_examples/repositories/raccount/raccount-db.repo\";\n\nimport { RAccountRepoES } from \"src/_examples/repositories/raccount/raccount-es.repo.interface\";\nimport \"src/_examples/repositories/raccount/raccount-es.repo\";\n\nimport { CONFIG_RETAILER } from \"src/_examples/controller/raccount/raccount-config\";\n\nimport { RAccountService } from \"./raccount-service.interface\";\n\n@Service(\"RAccountService\")\nexport class RAccountServiceImpl\n extends CrudServiceImpl<Retailer, RAccountRepoDB, RAccountRepoES>\n implements RAccountService\n{\n constructor() {\n const repoDB: RAccountRepoDB = Container.get(\"RAccountRepoDB\");\n const repoES: RAccountRepoES = Container.get(\"RAccountRepoES\");\n super(repoDB, repoES);\n this.setConfig(CONFIG_RETAILER);\n }\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import "../../repositories/supplier/supplier-repo-db";
|
|
|
4
4
|
import { SupplierRepoES } from "../../repositories/supplier/supplier-repo-es.interface";
|
|
5
5
|
import "../../repositories/supplier/supplier-repo-es";
|
|
6
6
|
import { ActionDynamoDB, Filter, List } from "../../../index.js";
|
|
7
|
-
import { SAccount } from "../../model-shared/suppler.model";
|
|
7
|
+
import { SAccount } from "../../model-shared/suppler.model-to-remove";
|
|
8
8
|
import { CrudServiceImpl } from "../../../service/crud.service";
|
|
9
9
|
export declare class SupplierCrudServiceImpl extends CrudServiceImpl<SAccount, SupplierRepoDB, SupplierRepoES> implements SupplierService {
|
|
10
10
|
constructor();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Filter, List } from "../../../index.js";
|
|
2
|
-
import { SAccount } from "../../model-shared/suppler.model";
|
|
2
|
+
import { SAccount } from "../../model-shared/suppler.model-to-remove";
|
|
3
3
|
import { CrudService } from "../../../service/crud.service.interface";
|
|
4
4
|
export interface SupplierService extends CrudService<SAccount> {
|
|
5
5
|
ListNonLevelOne(filterAndSort: Filter): Promise<List<SAccount>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supplier-service-crud.interface.js","sourceRoot":"","sources":["../../../../src/_examples/service/supplier/supplier-service-crud.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { Filter, List } from \"@chinggis/core\";\nimport { SAccount } from \"../../model-shared/suppler.model\";\nimport { CrudService } from \"../../../service/crud.service.interface\";\n\nexport interface SupplierService extends CrudService<SAccount> {\n ListNonLevelOne(filterAndSort: Filter): Promise<List<SAccount>>;\n\n convertToCognitoUser(username: string, email: string): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"supplier-service-crud.interface.js","sourceRoot":"","sources":["../../../../src/_examples/service/supplier/supplier-service-crud.interface.ts"],"names":[],"mappings":"","sourcesContent":["import { Filter, List } from \"@chinggis/core\";\nimport { SAccount } from \"../../model-shared/suppler.model-to-remove\";\nimport { CrudService } from \"../../../service/crud.service.interface\";\n\nexport interface SupplierService extends CrudService<SAccount> {\n ListNonLevelOne(filterAndSort: Filter): Promise<List<SAccount>>;\n\n convertToCognitoUser(username: string, email: string): Promise<void>;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supplier-service-crud.js","sourceRoot":"","sources":["../../../../src/_examples/service/supplier/supplier-service-crud.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAK5C,wDAAsD;AAGtD,wDAAsD;AACtD,yCAAuF;AAEvF,+EAAgF;AAChF,gEAAgE;AAGzD,IAAM,uBAAuB,GAA7B,MAAM,uBACX,SAAQ,8BAAyD;IAGjE,mFAAmF;IACnF,0EAA0E;IAE1E,EAAE;IACF;QACE,MAAM,MAAM,G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AAE;oBACR,eAAe,EAAE;wBACf,KAAK,EAAE,IAAI,aAAa,GAAG;wBAC3B,gBAAgB,EAAE,IAAI;qBACvB;iBACF;aACF,CAAC,CAAC;QACL,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAEhD,OAAO;YACL,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAiB,EAAE,OAAiB,EAAE,MAAsB,EAAE,SAAiB;QAClG,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;CACF,CAAA;AAlGY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,gBAAO,EAAC,qBAAqB,CAAC;;GAClB,uBAAuB,CAkGnC","sourcesContent":["import Container, { Service } from \"typedi\";\n\nimport { SupplierService } from \"./supplier-service-crud.interface\";\n\nimport { SupplierRepoDB } from \"../../repositories/supplier/supplier-repo-db.interface\";\nimport \"../../repositories/supplier/supplier-repo-db\";\n\nimport { SupplierRepoES } from \"../../repositories/supplier/supplier-repo-es.interface\";\nimport \"../../repositories/supplier/supplier-repo-es\";\nimport { ActionDynamoDB, Filter, HTTP, List, toCaseInsensitive } from \"@chinggis/core\";\nimport { SAccount } from \"../../model-shared/suppler.model\";\nimport { openSearch_supplier } from \"../../controller/supplier/supplier-config\";\nimport { CrudServiceImpl } from \"../../../service/crud.service\";\n\n@Service(\"SupplierCrudService\")\nexport class SupplierCrudServiceImpl\n extends CrudServiceImpl<SAccount, SupplierRepoDB, SupplierRepoES>\n implements SupplierService\n{\n // @Inject(\"EcomOrderService\") private readonly ecomOrderService: EcomOrderService;\n // @Inject(\"ROrderService\") private readonly rOrderService: ROrderService;\n\n //\n constructor() {\n const repoDB: SupplierRepoDB = Container.get(\"SupplierRepoDB\");\n const repoES: SupplierRepoES = Container.get(\"SupplierRepoES\");\n super(repoDB, repoES);\n }\n\n async convertToCognitoUser(username: string, email: string): Promise<void> {\n const supplier = await this.findById(\"system\", username);\n\n if (!supplier) return this.throwError(HTTP.BAD_REQUEST.code, \"supplier not found!\");\n if (supplier?.loginStatus === \"pending\") return this.throwError(HTTP.BAD_REQUEST.code, \"already pending user!\");\n if (supplier?.loginStatus === \"confirmed\") return this.throwError(HTTP.BAD_REQUEST.code, \"already confirmed user!\");\n }\n\n async ListNonLevelOne(filterAndSort: Filter): Promise<List<SAccount>> {\n if (filterAndSort.page > 0) filterAndSort.page = filterAndSort.page - 1;\n const filter = {\n index: openSearch_supplier.index,\n body: {\n query: {\n bool: {\n must_not: [\n {\n term: {\n accountType: \"level1\",\n },\n },\n ],\n should: [],\n minimum_should_match: 1,\n },\n },\n from: filterAndSort.page * filterAndSort.size,\n size: filterAndSort.size,\n },\n };\n\n if (filterAndSort.page && filterAndSort.size) {\n filter.body.from = filterAndSort.page * filterAndSort.size;\n }\n\n if (filterAndSort.size) {\n filter.body.size = filterAndSort.size;\n }\n\n if (!filterAndSort.searchKeyword) {\n const result = await this.repoES.search(filter, true);\n return {\n items: result,\n lastKey: null,\n };\n }\n\n let searchKeyword = filterAndSort.searchKeyword.trim();\n\n const searchFields = [\"username\", \"firstName\", \"lastName\", \"phoneList\", \"bankAccountNumber\", \"bankName\"];\n searchKeyword = toCaseInsensitive(searchKeyword);\n searchFields.forEach((field) => {\n filter.body.query.bool.should.push({\n regexp: {\n [field]: {\n value: `.*${searchKeyword}.*`,\n case_insensitive: true,\n },\n },\n });\n });\n\n if (searchKeyword.includes(\"@\")) {\n filter.body.query.bool.should.push({\n wildcard: {\n \"email.keyword\": {\n value: `*${searchKeyword}*`,\n case_insensitive: true,\n },\n },\n });\n }\n\n const result = await this.repoES.search(filter);\n\n return {\n items: result,\n lastKey: null,\n };\n }\n\n async processChanges(itemOld: SAccount, itemNew: SAccount, action: ActionDynamoDB, tableName: string): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n}\n"]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AAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;gBACjC,MAAM,EAAE;oBACN,CAAC,KAAK,CAAC,EAAE;wBACP,KAAK,EAAE,KAAK,aAAa,IAAI;wBAC7B,gBAAgB,EAAE,IAAI;qBACvB;iBACF;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;gBACjC,QAAQ,EAAE;oBACR,eAAe,EAAE;wBACf,KAAK,EAAE,IAAI,aAAa,GAAG;wBAC3B,gBAAgB,EAAE,IAAI;qBACvB;iBACF;aACF,CAAC,CAAC;QACL,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAEhD,OAAO;YACL,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAiB,EAAE,OAAiB,EAAE,MAAsB,EAAE,SAAiB;QAClG,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;CACF,CAAA;AAlGY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,gBAAO,EAAC,qBAAqB,CAAC;;GAClB,uBAAuB,CAkGnC","sourcesContent":["import Container, { Service } from \"typedi\";\n\nimport { SupplierService } from \"./supplier-service-crud.interface\";\n\nimport { SupplierRepoDB } from \"../../repositories/supplier/supplier-repo-db.interface\";\nimport \"../../repositories/supplier/supplier-repo-db\";\n\nimport { SupplierRepoES } from \"../../repositories/supplier/supplier-repo-es.interface\";\nimport \"../../repositories/supplier/supplier-repo-es\";\nimport { ActionDynamoDB, Filter, HTTP, List, toCaseInsensitive } from \"@chinggis/core\";\nimport { SAccount } from \"../../model-shared/suppler.model-to-remove\";\nimport { openSearch_supplier } from \"../../controller/supplier/supplier-config\";\nimport { CrudServiceImpl } from \"../../../service/crud.service\";\n\n@Service(\"SupplierCrudService\")\nexport class SupplierCrudServiceImpl\n extends CrudServiceImpl<SAccount, SupplierRepoDB, SupplierRepoES>\n implements SupplierService\n{\n // @Inject(\"EcomOrderService\") private readonly ecomOrderService: EcomOrderService;\n // @Inject(\"ROrderService\") private readonly rOrderService: ROrderService;\n\n //\n constructor() {\n const repoDB: SupplierRepoDB = Container.get(\"SupplierRepoDB\");\n const repoES: SupplierRepoES = Container.get(\"SupplierRepoES\");\n super(repoDB, repoES);\n }\n\n async convertToCognitoUser(username: string, email: string): Promise<void> {\n const supplier = await this.findById(\"system\", username);\n\n if (!supplier) return this.throwError(HTTP.BAD_REQUEST.code, \"supplier not found!\");\n if (supplier?.loginStatus === \"pending\") return this.throwError(HTTP.BAD_REQUEST.code, \"already pending user!\");\n if (supplier?.loginStatus === \"confirmed\") return this.throwError(HTTP.BAD_REQUEST.code, \"already confirmed user!\");\n }\n\n async ListNonLevelOne(filterAndSort: Filter): Promise<List<SAccount>> {\n if (filterAndSort.page > 0) filterAndSort.page = filterAndSort.page - 1;\n const filter = {\n index: openSearch_supplier.index,\n body: {\n query: {\n bool: {\n must_not: [\n {\n term: {\n accountType: \"level1\",\n },\n },\n ],\n should: [],\n minimum_should_match: 1,\n },\n },\n from: filterAndSort.page * filterAndSort.size,\n size: filterAndSort.size,\n },\n };\n\n if (filterAndSort.page && filterAndSort.size) {\n filter.body.from = filterAndSort.page * filterAndSort.size;\n }\n\n if (filterAndSort.size) {\n filter.body.size = filterAndSort.size;\n }\n\n if (!filterAndSort.searchKeyword) {\n const result = await this.repoES.search(filter, true);\n return {\n items: result,\n lastKey: null,\n };\n }\n\n let searchKeyword = filterAndSort.searchKeyword.trim();\n\n const searchFields = [\"username\", \"firstName\", \"lastName\", \"phoneList\", \"bankAccountNumber\", \"bankName\"];\n searchKeyword = toCaseInsensitive(searchKeyword);\n searchFields.forEach((field) => {\n filter.body.query.bool.should.push({\n regexp: {\n [field]: {\n value: `.*${searchKeyword}.*`,\n case_insensitive: true,\n },\n },\n });\n });\n\n if (searchKeyword.includes(\"@\")) {\n filter.body.query.bool.should.push({\n wildcard: {\n \"email.keyword\": {\n value: `*${searchKeyword}*`,\n case_insensitive: true,\n },\n },\n });\n }\n\n const result = await this.repoES.search(filter);\n\n return {\n items: result,\n lastKey: null,\n };\n }\n\n async processChanges(itemOld: SAccount, itemNew: SAccount, action: ActionDynamoDB, tableName: string): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import { SupplierRepoDB } from "../../repositories/supplier/supplier-repo-db.int
|
|
|
2
2
|
import "../../repositories/supplier/supplier-repo-db";
|
|
3
3
|
import { SupplierRepoES } from "../../repositories/supplier/supplier-repo-es.interface";
|
|
4
4
|
import "../../repositories/supplier/supplier-repo-es";
|
|
5
|
-
import { SAccount } from "../../model-shared/suppler.model";
|
|
5
|
+
import { SAccount } from "../../model-shared/suppler.model-to-remove";
|
|
6
6
|
import { SupplierServiceStream } from "./supplier-service-stream.interface";
|
|
7
7
|
import { StreamServiceImpl } from "../../../service/stream.service";
|
|
8
8
|
export declare class SupplierServiceStreamImpl extends StreamServiceImpl<SAccount, SupplierRepoDB, SupplierRepoES> implements SupplierServiceStream {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SAccount } from "../../model-shared/suppler.model";
|
|
1
|
+
import { SAccount } from "../../model-shared/suppler.model-to-remove";
|
|
2
2
|
import { StreamService } from "../../../service/stream.service.interface";
|
|
3
3
|
import "../../../service/stream.service";
|
|
4
4
|
export interface SupplierServiceStream extends StreamService<SAccount> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supplier-service-stream.interface.js","sourceRoot":"","sources":["../../../../src/_examples/service/supplier/supplier-service-stream.interface.ts"],"names":[],"mappings":";;AAEA,2CAAyC","sourcesContent":["import { SAccount } from \"../../model-shared/suppler.model\";\nimport { StreamService } from \"../../../service/stream.service.interface\";\nimport \"../../../service/stream.service\";\n\nexport interface SupplierServiceStream extends StreamService<SAccount> {}\n"]}
|
|
1
|
+
{"version":3,"file":"supplier-service-stream.interface.js","sourceRoot":"","sources":["../../../../src/_examples/service/supplier/supplier-service-stream.interface.ts"],"names":[],"mappings":";;AAEA,2CAAyC","sourcesContent":["import { SAccount } from \"../../model-shared/suppler.model-to-remove\";\nimport { StreamService } from \"../../../service/stream.service.interface\";\nimport \"../../../service/stream.service\";\n\nexport interface SupplierServiceStream extends StreamService<SAccount> {}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supplier-service-stream.js","sourceRoot":"","sources":["../../../../src/_examples/service/supplier/supplier-service-stream.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAG5C,wDAAsD;AAGtD,wDAAsD;AAGtD,oEAAoE;AAG7D,IAAM,yBAAyB,GAA/B,MAAM,yBACX,SAAQ,kCAA2D;IAGnE,EAAE;IACF;QACE,MAAM,MAAM,GAAmB,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC/D,MAAM,MAAM,GAAmB,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC/D,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,eAAe,CAAC,OAAiB,EAAE,OAAiB,EAAE,SAAkB;QACtE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,gBAAgB,CAAC,OAAiB,EAAE,SAAiB;QACnD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,mBAAmB,CAAC,OAAiB,EAAE,OAAiB,EAAE,SAAkB;QAC1E,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;CACF,CAAA;AApBY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,gBAAO,EAAC,uBAAuB,CAAC;;GACpB,yBAAyB,CAoBrC","sourcesContent":["import Container, { Service } from \"typedi\";\n\nimport { SupplierRepoDB } from \"../../repositories/supplier/supplier-repo-db.interface\";\nimport \"../../repositories/supplier/supplier-repo-db\";\n\nimport { SupplierRepoES } from \"../../repositories/supplier/supplier-repo-es.interface\";\nimport \"../../repositories/supplier/supplier-repo-es\";\nimport { SAccount } from \"../../model-shared/suppler.model\";\nimport { SupplierServiceStream } from \"./supplier-service-stream.interface\";\nimport { StreamServiceImpl } from \"../../../service/stream.service\";\n\n@Service(\"SupplierStreamService\")\nexport class SupplierServiceStreamImpl\n extends StreamServiceImpl<SAccount, SupplierRepoDB, SupplierRepoES>\n implements SupplierServiceStream\n{\n //\n constructor() {\n const repoDB: SupplierRepoDB = Container.get(\"SupplierRepoDB\");\n const repoES: SupplierRepoES = Container.get(\"SupplierRepoES\");\n super(repoDB, repoES);\n }\n\n processDeletion(oldItem: SAccount, newItem: SAccount, tableName?: string): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n processInsertion(newItem: SAccount, tableName: string): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n processModification(itemOld: SAccount, itemNew: SAccount, tableName?: string): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"supplier-service-stream.js","sourceRoot":"","sources":["../../../../src/_examples/service/supplier/supplier-service-stream.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAG5C,wDAAsD;AAGtD,wDAAsD;AAGtD,oEAAoE;AAG7D,IAAM,yBAAyB,GAA/B,MAAM,yBACX,SAAQ,kCAA2D;IAGnE,EAAE;IACF;QACE,MAAM,MAAM,GAAmB,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC/D,MAAM,MAAM,GAAmB,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;QAC/D,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,CAAC;IAED,eAAe,CAAC,OAAiB,EAAE,OAAiB,EAAE,SAAkB;QACtE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,gBAAgB,CAAC,OAAiB,EAAE,SAAiB;QACnD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IACD,mBAAmB,CAAC,OAAiB,EAAE,OAAiB,EAAE,SAAkB;QAC1E,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;CACF,CAAA;AApBY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,gBAAO,EAAC,uBAAuB,CAAC;;GACpB,yBAAyB,CAoBrC","sourcesContent":["import Container, { Service } from \"typedi\";\n\nimport { SupplierRepoDB } from \"../../repositories/supplier/supplier-repo-db.interface\";\nimport \"../../repositories/supplier/supplier-repo-db\";\n\nimport { SupplierRepoES } from \"../../repositories/supplier/supplier-repo-es.interface\";\nimport \"../../repositories/supplier/supplier-repo-es\";\nimport { SAccount } from \"../../model-shared/suppler.model-to-remove\";\nimport { SupplierServiceStream } from \"./supplier-service-stream.interface\";\nimport { StreamServiceImpl } from \"../../../service/stream.service\";\n\n@Service(\"SupplierStreamService\")\nexport class SupplierServiceStreamImpl\n extends StreamServiceImpl<SAccount, SupplierRepoDB, SupplierRepoES>\n implements SupplierServiceStream\n{\n //\n constructor() {\n const repoDB: SupplierRepoDB = Container.get(\"SupplierRepoDB\");\n const repoES: SupplierRepoES = Container.get(\"SupplierRepoES\");\n super(repoDB, repoES);\n }\n\n processDeletion(oldItem: SAccount, newItem: SAccount, tableName?: string): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n processInsertion(newItem: SAccount, tableName: string): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n processModification(itemOld: SAccount, itemNew: SAccount, tableName?: string): Promise<any> {\n throw new Error(\"Method not implemented.\");\n }\n}\n"]}
|
|
@@ -27,9 +27,9 @@ class ControllerApi {
|
|
|
27
27
|
log.debug("groups: " + JSON.stringify(req.groups, null, 2));
|
|
28
28
|
log.debug(`claims:${JSON.stringify(req.identity, null, 2)}`);
|
|
29
29
|
log.debug(`groups:${req.groups}, isAdmin:${req.isAdmin}, userId:${req.userId}, profileId:${req.profileId}, username:${req.username}, requestType:${req.requestType}`);
|
|
30
|
-
// if (
|
|
31
|
-
//
|
|
32
|
-
// req.filter[
|
|
30
|
+
// if (req.isAdmin) {
|
|
31
|
+
// delete req.filter["profileId"];
|
|
32
|
+
// delete req.filter["ownerParentId"];
|
|
33
33
|
// }
|
|
34
34
|
req = await this.processCrudRequestPre(req);
|
|
35
35
|
let response = await this.handleCrudByMethod(req);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-api.js","sourceRoot":"","sources":["../../src/controller/controller-api.ts"],"names":[],"mappings":";;;AAAA,oCAiBkB;AAElB,4CAA2D;AAE3D,sDAAuD;AAGvD,MAAsB,aAAa;IACd,OAAO,CAAI;IACpB,MAAM,CAAe;IACrB,eAAe,CAAW;IAEpC,YAAsB,WAAc,EAAE,MAAoB;QACxD,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC;QAE3B,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,MAAM,CAAC,gBAAgB,EAAE,CAAC;YAC5B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,gBAAgB,CAAC;QACjD,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,KAA2B;QAClD,IAAI,CAAC;YACH,IAAI,GAAG,GAAG,IAAA,wBAAgB,EAAC,KAAK,EAAE,IAAI,C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E,kBAAkB,EAAE,EACxC,4BAA4B,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,kBAAkB,EAAE,CACvF,CAAC;IACJ,CAAC;IAEO,aAAa,CAAC,OAAY,EAAE,OAAgB,EAAE,SAAiB;QACrE,IAAI,OAAO,IAAI,CAAC,SAAS;YAAE,OAAO;QAClC,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,mBAAmB,IAAI,SAAS,CAAC;QACtE,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,GAAG,SAAS,CAAC;QACpD,OAAO,OAAO,CAAC,aAAa,CAAC;IAC/B,CAAC;IAEO,WAAW,CAAC,WAAgB;QAClC,IAAI,CAAC,WAAW;YAAE,OAAO,EAAO,CAAC;QACjC,OAAO,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;IACjF,CAAC;IAEO,eAAe,CAAC,MAAW,EAAE,WAAgB;QACnD,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,IAAI,CAAC;YACH,IAAA,0BAAkB,EAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAC1C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,eAAe,GAAG,IAAA,oBAAY,EAAC,KAAK,CAAC,CAAC;YAC5C,MAAM,IAAI,qBAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,eAAe,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CACF;AA9TD,sCA8TC","sourcesContent":["import {\n Access,\n APIResponse,\n BaseEntity,\n createApiResponse,\n EndpointPolicy,\n Filter,\n findMatchedPolicy,\n formatErrors,\n HttpMethod,\n HttpRequest,\n List,\n parseHttpRequest,\n removeFields,\n RequestType,\n ResponseFields,\n validateWithSchema,\n} from \"../index\";\nimport { APIGatewayProxyEvent } from \"aws-lambda\";\nimport { errorHandlerHttp, ErrorHttp } from \"../exception\";\nimport { CognitoUser, EntityConfig } from \"@chinggis/types\";\nimport { trimSpecialChar } from \"../utils/string.util\";\nimport { CrudService } from \"../service\";\n\nexport abstract class ControllerApi<R extends BaseEntity, T extends CrudService<R>> {\n protected readonly service: T;\n protected config: EntityConfig;\n protected adminGroupNames: string[];\n\n protected constructor(baseService: T, config: EntityConfig) {\n this.service = baseService;\n\n if (!config) return;\n\n this.config = config;\n\n if (config.ADMIN_GROUP_NAME) {\n this.adminGroupNames = config.ADMIN_GROUP_NAME;\n }\n\n this.service.setConfig(config);\n }\n\n async resolveCrudRequest(event: APIGatewayProxyEvent): Promise<APIResponse> {\n try {\n let req = parseHttpRequest(event, this.adminGroupNames);\n\n const policy: EndpointPolicy | undefined = findMatchedPolicy(\n req.methode,\n event?.requestContext?.resourcePath,\n this.config.ENDPOINT_POLICY,\n );\n\n this.checkPermission(policy?.access, req.requestType);\n this.validateRequest(policy?.validator, req.body);\n\n log.debug(\"groups: \" + JSON.stringify(req.groups, null, 2));\n log.debug(`claims:${JSON.stringify(req.identity, null, 2)}`);\n log.debug(\n `groups:${req.groups}, isAdmin:${req.isAdmin}, userId:${req.userId}, profileId:${req.profileId}, username:${req.username}, requestType:${req.requestType}`,\n );\n\n // if (!req.isAdmin && req.profileId) {\n // const ownerIdFieldName = this.config.OWNER_ID_FIELD_NAME || \"ownerId\";\n // req.filter[ownerIdFieldName] = req.profileId;\n // }\n\n req = await this.processCrudRequestPre(req);\n\n let response: any = await this.handleCrudByMethod(req);\n\n if (response) response = await this.processCrudRequestPost(req, response);\n else response = await this.processCrudRequest(req); // Custom Endpoints\n\n if (!policy?.response) {\n return createApiResponse(200, response);\n }\n\n const filteredResponse = this.filterResponse(response, policy.response);\n\n return createApiResponse(200, filteredResponse);\n } catch (err) {\n const error = errorHandlerHttp(err);\n log.error(error);\n error.content.message = \"[CORE] \" + error.content.message;\n return createApiResponse(error.statusCode, error.content);\n }\n }\n\n setConfig(config: EntityConfig): void {\n this.config = config;\n }\n\n async processCrudRequestPre(req: HttpRequest): Promise<HttpRequest> {\n return req;\n }\n\n async processCrudRequestPost(request: HttpRequest, response: R | List<R>): Promise<R | List<R>> {\n return response;\n }\n\n protected async handleList(methode: HttpMethod, path: string, filter: Filter): Promise<any> {\n if (methode === \"GET\" && trimSpecialChar(path) === trimSpecialChar(this.config.BASE_PATH)) {\n return await this.service.find(filter || {});\n }\n\n if (methode === \"GET\" && trimSpecialChar(path) === trimSpecialChar(this.config.BASE_PATH) + \"/search\") {\n return await this.service.search(filter || {});\n }\n\n if (methode === \"GET\" && trimSpecialChar(path) === trimSpecialChar(this.config.BASE_PATH) + \"/scan\") {\n return await this.service.scan(filter || {});\n }\n }\n\n protected async handleUpdate(entityId: string, requestBody: any, profileId?: string): Promise<R> {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot PATCH resource without id field\");\n\n const entity = this.parseEntity(requestBody);\n\n if (Object.keys(entity).length === 0) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] No fields to update\");\n }\n\n // id change is forbidden\n if (\"id\" in entity) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot modify the id field\");\n }\n\n entity.id = entityId;\n return this.service.update(entity as R, profileId);\n }\n\n protected async handleDelete(entityId: string, profileId?: string): Promise<boolean> {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot delete resource without id field\");\n\n return this.service.remove(entityId, profileId);\n }\n\n protected async handleFetch(entityId: string, profileId?: string): Promise<R> {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot fetch resource without id field\");\n\n const result = await this.service.findById(entityId, profileId);\n\n if (result) return result;\n\n throw new ErrorHttp({ code: 404, error: \"NotFound\" }, `[CORE] Resource with ID ${entityId} not found`);\n }\n\n protected async handleReplace(entityId: string, entity: any, profileId?: string) {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot PUT resource without id field\");\n\n if (!Object.keys(entity).length) {\n throw new ErrorHttp({ code: 400, error: \"Bad Request\" }, \"[CORE] No entity provided for PUT update\");\n }\n\n if (!entityId) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot PUT resource without id field\");\n }\n\n entity.id = entityId;\n\n return this.service.update(entity, profileId);\n }\n\n protected async handlePostCreate(entity: R, isAdmin: boolean, cognitoUser: CognitoUser) {\n if (!entity || Object.keys(entity).length === 0) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] No entity payload provided\");\n }\n\n if (!entity.ownerId) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] No ownerId provided\");\n }\n\n // Initialize IDs\n const { ownerId, ownerParentId: inputParentId } = entity;\n let profileId = ownerId;\n let parentId: string;\n\n // Determine parentId and profileId\n if (isAdmin && inputParentId) {\n parentId = inputParentId;\n } else if (cognitoUser.isParent) {\n console.log(\"is parent becomming true\");\n\n parentId = cognitoUser.profile;\n } else {\n console.log(\"is parent not becomming true\");\n console.log(\"the value of isParent: \", cognitoUser.isParent, typeof cognitoUser.isParent);\n\n parentId = cognitoUser.parentId;\n profileId = cognitoUser.profile;\n }\n\n // Remove fields that shouldn't be saved directly\n delete entity.ownerParentId;\n delete entity.ownerId;\n\n // Save entity\n return this.service.save(entity, profileId, parentId);\n }\n\n protected abstract processCrudRequest(event: HttpRequest): Promise<any>;\n\n protected isListRequest(methode: HttpMethod, path: string): boolean {\n const basePath = trimSpecialChar(this.config.BASE_PATH);\n\n const allowedPaths = [basePath, `${basePath}/search`, `${basePath}/scan`];\n\n const isMethodGet = methode === \"GET\";\n const isAllowedPath = allowedPaths.includes(trimSpecialChar(path));\n\n return isMethodGet && isAllowedPath;\n }\n\n protected isUpdateRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodPatch = methode === \"PATCH\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodPatch && isExpectedPath;\n }\n\n protected isDeleteRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodDelete = methode === \"DELETE\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodDelete && isExpectedPath;\n }\n\n protected isFetchRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodGet = methode === \"GET\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodGet && isExpectedPath;\n }\n\n protected isPostRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}`;\n const isMethodGet = methode === \"POST\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodGet && isExpectedPath;\n }\n\n protected isPutRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodGet = methode === \"PUT\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodGet && isExpectedPath;\n }\n\n private async handleCrudByMethod(req: HttpRequest): Promise<any> {\n const path = req.event?.requestContext?.resourcePath;\n\n const entity = this.parseEntity(req.body);\n\n if (this.isUpdateRequest(req.methode, path)) return this.handleUpdate(req.entityId, entity, req.profileId);\n if (this.isDeleteRequest(req.methode, path)) return this.handleDelete(req.entityId, req.profileId);\n if (this.isFetchRequest(req.methode, path)) return this.handleFetch(req.entityId, req.profileId);\n if (this.isPutRequest(req.methode, path)) return this.handleReplace(req.entityId, entity, req.profileId);\n if (this.isPostRequest(req.methode, path)) return this.handlePostCreate(entity, req.isAdmin, req.identity);\n if (this.isListRequest(req.methode, path)) return this.handleList(req.methode, path, req.filter);\n\n return null;\n }\n\n private filterResponse(response: any, responsePolicy: ResponseFields): any {\n if (Array.isArray(response)) {\n return removeFields(response, responsePolicy.include, responsePolicy.exclude);\n }\n\n if (response?.items && Array.isArray(response.items)) {\n response.items = removeFields(response.items, responsePolicy.include, responsePolicy.exclude);\n return response;\n }\n\n return removeFields([response], responsePolicy.include, responsePolicy.exclude)[0];\n }\n\n /** Map RequestType to Access for permission checking */\n private getUserAccessLevel(requestType: RequestType): Access {\n switch (requestType) {\n case RequestType.ADMIN:\n return Access.ADMIN;\n case RequestType.USER:\n return Access.USER;\n case RequestType.GUEST:\n return Access.PUBLIC;\n case RequestType.SYSTEM:\n return Access.SYSTEM;\n default:\n return Access.PUBLIC;\n }\n }\n\n /** Check if the user has permission for the current operation */\n private checkPermission(allowedAccess: Access[], requestType: RequestType) {\n const currentAccessLevel = this.getUserAccessLevel(requestType);\n\n // This means USER can access OWNER-level permissions, but the service will verify actual ownership\n const hasPermission =\n allowedAccess.includes(currentAccessLevel) ||\n (requestType === RequestType.USER && allowedAccess.includes(Access.OWNER));\n\n if (hasPermission) return;\n\n throw new ErrorHttp(\n { code: 403, error: \"PermissionDenied\" },\n `Access denied. Required: ${allowedAccess.join(\", \")}, Current: ${currentAccessLevel}`,\n );\n }\n\n private setUserFilter(request: any, isAdmin: boolean, profileId: string) {\n if (isAdmin && !profileId) return;\n const ownerIdFieldName = this.config.OWNER_ID_FIELD_NAME || \"ownerId\";\n request.filterAndSort[ownerIdFieldName] = profileId;\n return request.filterAndSort;\n }\n\n private parseEntity(requestBody: any): R {\n if (!requestBody) return {} as R;\n return typeof requestBody === \"string\" ? JSON.parse(requestBody) : requestBody;\n }\n\n private validateRequest(schema: any, requestBody: any) {\n if (!schema) return;\n\n try {\n validateWithSchema(schema, requestBody);\n } catch (error) {\n const formattedErrors = formatErrors(error);\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, formattedErrors);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"controller-api.js","sourceRoot":"","sources":["../../src/controller/controller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AW,EAAE,WAAgB;QACnD,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,IAAI,CAAC;YACH,IAAA,0BAAkB,EAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAC1C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,eAAe,GAAG,IAAA,oBAAY,EAAC,KAAK,CAAC,CAAC;YAC5C,MAAM,IAAI,qBAAS,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,eAAe,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CACF;AA9TD,sCA8TC","sourcesContent":["import {\n Access,\n APIResponse,\n BaseEntity,\n createApiResponse,\n EndpointPolicy,\n Filter,\n findMatchedPolicy,\n formatErrors,\n HttpMethod,\n HttpRequest,\n List,\n parseHttpRequest,\n removeFields,\n RequestType,\n ResponseFields,\n validateWithSchema,\n} from \"../index\";\nimport { APIGatewayProxyEvent } from \"aws-lambda\";\nimport { errorHandlerHttp, ErrorHttp } from \"../exception\";\nimport { CognitoUser, EntityConfig } from \"@chinggis/types\";\nimport { trimSpecialChar } from \"../utils/string.util\";\nimport { CrudService } from \"../service\";\n\nexport abstract class ControllerApi<R extends BaseEntity, T extends CrudService<R>> {\n protected readonly service: T;\n protected config: EntityConfig;\n protected adminGroupNames: string[];\n\n protected constructor(baseService: T, config: EntityConfig) {\n this.service = baseService;\n\n if (!config) return;\n\n this.config = config;\n\n if (config.ADMIN_GROUP_NAME) {\n this.adminGroupNames = config.ADMIN_GROUP_NAME;\n }\n\n this.service.setConfig(config);\n }\n\n async resolveCrudRequest(event: APIGatewayProxyEvent): Promise<APIResponse> {\n try {\n let req = parseHttpRequest(event, this.adminGroupNames);\n\n const policy: EndpointPolicy | undefined = findMatchedPolicy(\n req.methode,\n event?.requestContext?.resourcePath,\n this.config.ENDPOINT_POLICY,\n );\n\n this.checkPermission(policy?.access, req.requestType);\n this.validateRequest(policy?.validator, req.body);\n\n log.debug(\"groups: \" + JSON.stringify(req.groups, null, 2));\n log.debug(`claims:${JSON.stringify(req.identity, null, 2)}`);\n log.debug(\n `groups:${req.groups}, isAdmin:${req.isAdmin}, userId:${req.userId}, profileId:${req.profileId}, username:${req.username}, requestType:${req.requestType}`,\n );\n\n // if (req.isAdmin) {\n // delete req.filter[\"profileId\"];\n // delete req.filter[\"ownerParentId\"];\n // }\n\n req = await this.processCrudRequestPre(req);\n\n let response: any = await this.handleCrudByMethod(req);\n\n if (response) response = await this.processCrudRequestPost(req, response);\n else response = await this.processCrudRequest(req); // Custom Endpoints\n\n if (!policy?.response) {\n return createApiResponse(200, response);\n }\n\n const filteredResponse = this.filterResponse(response, policy.response);\n\n return createApiResponse(200, filteredResponse);\n } catch (err) {\n const error = errorHandlerHttp(err);\n log.error(error);\n error.content.message = \"[CORE] \" + error.content.message;\n return createApiResponse(error.statusCode, error.content);\n }\n }\n\n setConfig(config: EntityConfig): void {\n this.config = config;\n }\n\n async processCrudRequestPre(req: HttpRequest): Promise<HttpRequest> {\n return req;\n }\n\n async processCrudRequestPost(request: HttpRequest, response: R | List<R>): Promise<R | List<R>> {\n return response;\n }\n\n protected async handleList(methode: HttpMethod, path: string, filter: Filter): Promise<any> {\n if (methode === \"GET\" && trimSpecialChar(path) === trimSpecialChar(this.config.BASE_PATH)) {\n return await this.service.find(filter || {});\n }\n\n if (methode === \"GET\" && trimSpecialChar(path) === trimSpecialChar(this.config.BASE_PATH) + \"/search\") {\n return await this.service.search(filter || {});\n }\n\n if (methode === \"GET\" && trimSpecialChar(path) === trimSpecialChar(this.config.BASE_PATH) + \"/scan\") {\n return await this.service.scan(filter || {});\n }\n }\n\n protected async handleUpdate(entityId: string, requestBody: any, profileId?: string): Promise<R> {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot PATCH resource without id field\");\n\n const entity = this.parseEntity(requestBody);\n\n if (Object.keys(entity).length === 0) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] No fields to update\");\n }\n\n // id change is forbidden\n if (\"id\" in entity) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot modify the id field\");\n }\n\n entity.id = entityId;\n return this.service.update(entity as R, profileId);\n }\n\n protected async handleDelete(entityId: string, profileId?: string): Promise<boolean> {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot delete resource without id field\");\n\n return this.service.remove(entityId, profileId);\n }\n\n protected async handleFetch(entityId: string, profileId?: string): Promise<R> {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot fetch resource without id field\");\n\n const result = await this.service.findById(entityId, profileId);\n\n if (result) return result;\n\n throw new ErrorHttp({ code: 404, error: \"NotFound\" }, `[CORE] Resource with ID ${entityId} not found`);\n }\n\n protected async handleReplace(entityId: string, entity: any, profileId?: string) {\n if (!entityId)\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot PUT resource without id field\");\n\n if (!Object.keys(entity).length) {\n throw new ErrorHttp({ code: 400, error: \"Bad Request\" }, \"[CORE] No entity provided for PUT update\");\n }\n\n if (!entityId) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] Cannot PUT resource without id field\");\n }\n\n entity.id = entityId;\n\n return this.service.update(entity, profileId);\n }\n\n protected async handlePostCreate(entity: R, isAdmin: boolean, cognitoUser: CognitoUser) {\n if (!entity || Object.keys(entity).length === 0) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] No entity payload provided\");\n }\n\n if (!entity.ownerId) {\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, \"[CORE] No ownerId provided\");\n }\n\n // Initialize IDs\n const { ownerId, ownerParentId: inputParentId } = entity;\n let profileId = ownerId;\n let parentId: string;\n\n // Determine parentId and profileId\n if (isAdmin && inputParentId) {\n parentId = inputParentId;\n } else if (cognitoUser.isParent) {\n console.log(\"is parent becomming true\");\n\n parentId = cognitoUser.profile;\n } else {\n console.log(\"is parent not becomming true\");\n console.log(\"the value of isParent: \", cognitoUser.isParent, typeof cognitoUser.isParent);\n\n parentId = cognitoUser.parentId;\n profileId = cognitoUser.profile;\n }\n\n // Remove fields that shouldn't be saved directly\n delete entity.ownerParentId;\n delete entity.ownerId;\n\n // Save entity\n return this.service.save(entity, profileId, parentId);\n }\n\n protected abstract processCrudRequest(event: HttpRequest): Promise<any>;\n\n protected isListRequest(methode: HttpMethod, path: string): boolean {\n const basePath = trimSpecialChar(this.config.BASE_PATH);\n\n const allowedPaths = [basePath, `${basePath}/search`, `${basePath}/scan`];\n\n const isMethodGet = methode === \"GET\";\n const isAllowedPath = allowedPaths.includes(trimSpecialChar(path));\n\n return isMethodGet && isAllowedPath;\n }\n\n protected isUpdateRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodPatch = methode === \"PATCH\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodPatch && isExpectedPath;\n }\n\n protected isDeleteRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodDelete = methode === \"DELETE\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodDelete && isExpectedPath;\n }\n\n protected isFetchRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodGet = methode === \"GET\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodGet && isExpectedPath;\n }\n\n protected isPostRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}`;\n const isMethodGet = methode === \"POST\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodGet && isExpectedPath;\n }\n\n protected isPutRequest(methode: HttpMethod, path: string): boolean {\n const expectedPath = `${trimSpecialChar(this.config.BASE_PATH)}/{id}`;\n const isMethodGet = methode === \"PUT\";\n const isExpectedPath = trimSpecialChar(path) === expectedPath;\n\n return isMethodGet && isExpectedPath;\n }\n\n private async handleCrudByMethod(req: HttpRequest): Promise<any> {\n const path = req.event?.requestContext?.resourcePath;\n\n const entity = this.parseEntity(req.body);\n\n if (this.isUpdateRequest(req.methode, path)) return this.handleUpdate(req.entityId, entity, req.profileId);\n if (this.isDeleteRequest(req.methode, path)) return this.handleDelete(req.entityId, req.profileId);\n if (this.isFetchRequest(req.methode, path)) return this.handleFetch(req.entityId, req.profileId);\n if (this.isPutRequest(req.methode, path)) return this.handleReplace(req.entityId, entity, req.profileId);\n if (this.isPostRequest(req.methode, path)) return this.handlePostCreate(entity, req.isAdmin, req.identity);\n if (this.isListRequest(req.methode, path)) return this.handleList(req.methode, path, req.filter);\n\n return null;\n }\n\n private filterResponse(response: any, responsePolicy: ResponseFields): any {\n if (Array.isArray(response)) {\n return removeFields(response, responsePolicy.include, responsePolicy.exclude);\n }\n\n if (response?.items && Array.isArray(response.items)) {\n response.items = removeFields(response.items, responsePolicy.include, responsePolicy.exclude);\n return response;\n }\n\n return removeFields([response], responsePolicy.include, responsePolicy.exclude)[0];\n }\n\n /** Map RequestType to Access for permission checking */\n private getUserAccessLevel(requestType: RequestType): Access {\n switch (requestType) {\n case RequestType.ADMIN:\n return Access.ADMIN;\n case RequestType.USER:\n return Access.USER;\n case RequestType.GUEST:\n return Access.PUBLIC;\n case RequestType.SYSTEM:\n return Access.SYSTEM;\n default:\n return Access.PUBLIC;\n }\n }\n\n /** Check if the user has permission for the current operation */\n private checkPermission(allowedAccess: Access[], requestType: RequestType) {\n const currentAccessLevel = this.getUserAccessLevel(requestType);\n\n // This means USER can access OWNER-level permissions, but the service will verify actual ownership\n const hasPermission =\n allowedAccess.includes(currentAccessLevel) ||\n (requestType === RequestType.USER && allowedAccess.includes(Access.OWNER));\n\n if (hasPermission) return;\n\n throw new ErrorHttp(\n { code: 403, error: \"PermissionDenied\" },\n `Access denied. Required: ${allowedAccess.join(\", \")}, Current: ${currentAccessLevel}`,\n );\n }\n\n private setUserFilter(request: any, isAdmin: boolean, profileId: string) {\n if (isAdmin && !profileId) return;\n const ownerIdFieldName = this.config.OWNER_ID_FIELD_NAME || \"ownerId\";\n request.filterAndSort[ownerIdFieldName] = profileId;\n return request.filterAndSort;\n }\n\n private parseEntity(requestBody: any): R {\n if (!requestBody) return {} as R;\n return typeof requestBody === \"string\" ? JSON.parse(requestBody) : requestBody;\n }\n\n private validateRequest(schema: any, requestBody: any) {\n if (!schema) return;\n\n try {\n validateWithSchema(schema, requestBody);\n } catch (error) {\n const formattedErrors = formatErrors(error);\n throw new ErrorHttp({ code: 400, error: \"BadRequest\" }, formattedErrors);\n }\n }\n}\n"]}
|
|
@@ -34,6 +34,10 @@ const errorHandlerHttp = (error) => {
|
|
|
34
34
|
response = httpStatus.NOT_FOUND;
|
|
35
35
|
responseMsg = `Resource not found: ${err.tableName}`;
|
|
36
36
|
}
|
|
37
|
+
else if (msg.includes("requires indexName and indexValue")) {
|
|
38
|
+
response = httpStatus.BAD_REQUEST;
|
|
39
|
+
responseMsg = `Index name and value are required: ${err.tableName}`;
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
else if (msg?.includes("search_phase_execution_exception")) {
|
|
39
43
|
response = httpStatus.BAD_REQUEST;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception-handler.js","sourceRoot":"","sources":["../../src/exception/exception-handler.ts"],"names":[],"mappings":";;;AAAA,qCAAqE;AAE9D,MAAM,gBAAgB,GAAG,CAAC,KAAU,EAAE,EAAE;IAC7C,MAAM,UAAU,GAAG,YAAI,CAAC;IAExB,MAAM,GAAG,GAAG,KAAK,EAAE,OAAO,CAAC;IAE3B,IAAI,QAAQ,GAAG,UAAU,CAAC,qBAAqB,CAAC;IAChD,IAAI,WAAW,GAAG,GAAG,CAAC;IACtB,IAAI,IAAI,GAAG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AAG,EAAE;IAC5D,+BAA+B,EAAE,EAAE,KAAK,EAAE,iCAAiC,EAAE,IAAI,EAAE,GAAG,EAAE;IACxF,6BAA6B,EAAE,EAAE,KAAK,EAAE,+BAA+B,EAAE,IAAI,EAAE,GAAG,EAAE;IAEpF,oBAAoB;IACpB,qBAAqB,EAAE,EAAE,KAAK,EAAE,uBAAuB,EAAE,IAAI,EAAE,GAAG,EAAE;IACpE,eAAe,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE;IACxD,WAAW,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,EAAE;IAChD,mBAAmB,EAAE,EAAE,KAAK,EAAE,qBAAqB,EAAE,IAAI,EAAE,GAAG,EAAE;IAChE,eAAe,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE;IACxD,0BAA0B,EAAE,EAAE,KAAK,EAAE,4BAA4B,EAAE,IAAI,EAAE,GAAG,EAAE;IAC9E,uBAAuB,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE,IAAI,EAAE,GAAG,EAAE;IACxE,oBAAoB,EAAE,EAAE,KAAK,EAAE,sBAAsB,EAAE,IAAI,EAAE,GAAG,EAAE;IAClE,aAAa,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,GAAG,EAAE;IACpD,YAAY,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,EAAE;IAClD,+BAA+B,EAAE,EAAE,KAAK,EAAE,iCAAiC,EAAE,IAAI,EAAE,GAAG,EAAE;CACzF,CAAC","sourcesContent":["import { ErrorDynamoDB, ErrorHttp, ErrorValidation } from \"./errors\";\n\nexport const errorHandlerHttp = (error: any) => {\n const httpStatus = HTTP;\n\n const msg = error?.message;\n\n let response = httpStatus.INTERNAL_SERVER_ERROR;\n let responseMsg = msg;\n let data = error?.data;\n\n if (error instanceof ErrorValidation) {\n response = httpStatus.BAD_REQUEST;\n response.error = response.error + \" - Validation Error\";\n // responseMsg = error.validation\n responseMsg = Object.fromEntries(error.validation.entries());\n data = error.content;\n } else if (error instanceof ErrorHttp) {\n response.code = error.statusCode;\n response.error = error.error;\n responseMsg = error.message;\n data = error.data;\n } else if (error instanceof ErrorDynamoDB) {\n const err = error as ErrorDynamoDB;\n if (msg.includes(\"ConditionalCheckFailedException\")) {\n response = httpStatus.CONFLICT;\n response.error = response.error + \" - DynamoDB Error\";\n responseMsg =\n `ConditionalCheckFailedException: by table: ${err.tableName}, command: ${err.command}, error: ` +\n JSON.stringify(err);\n } else if (msg.includes(\"ResourceNotFoundException\")) {\n response = httpStatus.NOT_FOUND;\n responseMsg = `Resource not found: ${err.tableName}`;\n }\n } else if (msg?.includes(\"search_phase_execution_exception\")) {\n response = httpStatus.BAD_REQUEST;\n responseMsg = \"OpenSearch: Cannot sort by text field — use '.keyword' instead.\";\n }\n\n return {\n statusCode: response.code,\n content: {\n error: response.error,\n message: responseMsg,\n data: data,\n },\n };\n};\n\nexport const HTTP = {\n // 1xx Informational\n CONTINUE: { error: \"Continue\", code: 100 },\n SWITCHING_PROTOCOLS: { error: \"Switching Protocols\", code: 101 },\n PROCESSING: { error: \"Processing\", code: 102 },\n\n // 2xx Success\n OK: { error: \"OK\", code: 200 },\n CREATED: { error: \"Created\", code: 201 },\n ACCEPTED: { error: \"Accepted\", code: 202 },\n NON_AUTHORITATIVE_INFORMATION: { error: \"Non-Authoritative Information\", code: 203 },\n NO_CONTENT: { error: \"No Content\", code: 204 },\n RESET_CONTENT: { error: \"Reset Content\", code: 205 },\n PARTIAL_CONTENT: { error: \"Partial Content\", code: 206 },\n\n // 3xx Redirection\n MULTIPLE_CHOICES: { error: \"Multiple Choices\", code: 300 },\n MOVED_PERMANENTLY: { error: \"Moved Permanently\", code: 301 },\n FOUND: { error: \"Found\", code: 302 },\n SEE_OTHER: { error: \"See Other\", code: 303 },\n NOT_MODIFIED: { error: \"Not Modified\", code: 304 },\n TEMPORARY_REDIRECT: { error: \"Temporary Redirect\", code: 307 },\n PERMANENT_REDIRECT: { error: \"Permanent Redirect\", code: 308 },\n\n // 4xx Client Errors\n BAD_REQUEST: { error: \"Bad Request\", code: 400 },\n UNAUTHORIZED: { error: \"Unauthorized\", code: 401 },\n PAYMENT_REQUIRED: { error: \"Payment Required\", code: 402 },\n FORBIDDEN: { error: \"Forbidden\", code: 403 },\n NOT_FOUND: { error: \"Not Found\", code: 404 },\n METHOD_NOT_ALLOWED: { error: \"Method Not Allowed\", code: 405 },\n NOT_ACCEPTABLE: { error: \"Not Acceptable\", code: 406 },\n PROXY_AUTHENTICATION_REQUIRED: { error: \"Proxy Authentication Required\", code: 407 },\n REQUEST_TIMEOUT: { error: \"Request Timeout\", code: 408 },\n CONFLICT: { error: \"Conflict\", code: 409 },\n GONE: { error: \"Gone\", code: 410 },\n LENGTH_REQUIRED: { error: \"Length Required\", code: 411 },\n PRECONDITION_FAILED: { error: \"Precondition Failed\", code: 412 },\n PAYLOAD_TOO_LARGE: { error: \"Payload Too Large\", code: 413 },\n URI_TOO_LONG: { error: \"URI Too Long\", code: 414 },\n UNSUPPORTED_MEDIA_TYPE: { error: \"Unsupported Media Type\", code: 415 },\n RANGE_NOT_SATISFIABLE: { error: \"Range Not Satisfiable\", code: 416 },\n EXPECTATION_FAILED: { error: \"Expectation Failed\", code: 417 },\n IM_A_TEAPOT: { error: \"I'm a teapot\", code: 418 },\n MISDIRECTED_REQUEST: { error: \"Misdirected Request\", code: 421 },\n UNPROCESSABLE_ENTITY: { error: \"Unprocessable Entity\", code: 422 },\n LOCKED: { error: \"Locked\", code: 423 },\n FAILED_DEPENDENCY: { error: \"Failed Dependency\", code: 424 },\n TOO_EARLY: { error: \"Too Early\", code: 425 },\n UPGRADE_REQUIRED: { error: \"Upgrade Required\", code: 426 },\n PRECONDITION_REQUIRED: { error: \"Precondition Required\", code: 428 },\n TOO_MANY_REQUESTS: { error: \"Too Many Requests\", code: 429 },\n REQUEST_HEADER_FIELDS_TOO_LARGE: { error: \"Request Header Fields Too Large\", code: 431 },\n UNAVAILABLE_FOR_LEGAL_REASONS: { error: \"Unavailable For Legal Reasons\", code: 451 },\n\n // 5xx Server Errors\n INTERNAL_SERVER_ERROR: { error: \"Internal Server Error\", code: 500 },\n NOT_IMPLEMENTED: { error: \"Not Implemented\", code: 501 },\n BAD_GATEWAY: { error: \"Bad Gateway\", code: 502 },\n SERVICE_UNAVAILABLE: { error: \"Service Unavailable\", code: 503 },\n GATEWAY_TIMEOUT: { error: \"Gateway Timeout\", code: 504 },\n HTTP_VERSION_NOT_SUPPORTED: { error: \"HTTP Version Not Supported\", code: 505 },\n VARIANT_ALSO_NEGOTIATES: { error: \"Variant Also Negotiates\", code: 506 },\n INSUFFICIENT_STORAGE: { error: \"Insufficient Storage\", code: 507 },\n LOOP_DETECTED: { error: \"Loop Detected\", code: 508 },\n NOT_EXTENDED: { error: \"Not Extended\", code: 510 },\n NETWORK_AUTHENTICATION_REQUIRED: { error: \"Network Authentication Required\", code: 511 },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"exception-handler.js","sourceRoot":"","sources":["../../src/exception/exception-handler.ts"],"names":[],"mappings":";;;AAAA,qCAAqE;AAE9D,MAAM,gBAAgB,GAAG,CAAC,KAAU,EAAE,EAAE;IAC7C,MAAM,UAAU,GAAG,YAAI,CAAC;IAExB,MAAM,GAAG,GAAG,KAAK,EAAE,OAAO,CAAC;IAE3B,IAAI,QAAQ,GAAG,UAAU,CAAC,qBAAqB,CAAC;IAChD,IAAI,WAAW,GAAG,GAAG,CAAC;IACtB,IAAI,IAAI,GAAG,KAAK,EAAE,IAAI,CAAC;IAEvB,IAAI,KAAK,YAAY,wBAAe,EAAE,CAAC;QACrC,QAAQ,GAAG,UAAU,CAAC,WAAW,CAAC;QAClC,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,GAAG,qBAAqB,CAAC;QACxD,iCAAiC;QACjC,WAAW,GAAG,MAAM,C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E,iCAAiC,EAAE,IAAI,EAAE,GAAG,EAAE;IACxF,6BAA6B,EAAE,EAAE,KAAK,EAAE,+BAA+B,EAAE,IAAI,EAAE,GAAG,EAAE;IAEpF,oBAAoB;IACpB,qBAAqB,EAAE,EAAE,KAAK,EAAE,uBAAuB,EAAE,IAAI,EAAE,GAAG,EAAE;IACpE,eAAe,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE;IACxD,WAAW,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,EAAE;IAChD,mBAAmB,EAAE,EAAE,KAAK,EAAE,qBAAqB,EAAE,IAAI,EAAE,GAAG,EAAE;IAChE,eAAe,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE;IACxD,0BAA0B,EAAE,EAAE,KAAK,EAAE,4BAA4B,EAAE,IAAI,EAAE,GAAG,EAAE;IAC9E,uBAAuB,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE,IAAI,EAAE,GAAG,EAAE;IACxE,oBAAoB,EAAE,EAAE,KAAK,EAAE,sBAAsB,EAAE,IAAI,EAAE,GAAG,EAAE;IAClE,aAAa,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,GAAG,EAAE;IACpD,YAAY,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,EAAE;IAClD,+BAA+B,EAAE,EAAE,KAAK,EAAE,iCAAiC,EAAE,IAAI,EAAE,GAAG,EAAE;CACzF,CAAC","sourcesContent":["import { ErrorDynamoDB, ErrorHttp, ErrorValidation } from \"./errors\";\n\nexport const errorHandlerHttp = (error: any) => {\n const httpStatus = HTTP;\n\n const msg = error?.message;\n\n let response = httpStatus.INTERNAL_SERVER_ERROR;\n let responseMsg = msg;\n let data = error?.data;\n\n if (error instanceof ErrorValidation) {\n response = httpStatus.BAD_REQUEST;\n response.error = response.error + \" - Validation Error\";\n // responseMsg = error.validation\n responseMsg = Object.fromEntries(error.validation.entries());\n data = error.content;\n } else if (error instanceof ErrorHttp) {\n response.code = error.statusCode;\n response.error = error.error;\n responseMsg = error.message;\n data = error.data;\n } else if (error instanceof ErrorDynamoDB) {\n const err = error;\n if (msg.includes(\"ConditionalCheckFailedException\")) {\n response = httpStatus.CONFLICT;\n response.error = response.error + \" - DynamoDB Error\";\n responseMsg =\n `ConditionalCheckFailedException: by table: ${err.tableName}, command: ${err.command}, error: ` +\n JSON.stringify(err);\n } else if (msg.includes(\"ResourceNotFoundException\")) {\n response = httpStatus.NOT_FOUND;\n responseMsg = `Resource not found: ${err.tableName}`;\n } else if (msg.includes(\"requires indexName and indexValue\")) {\n response = httpStatus.BAD_REQUEST;\n responseMsg = `Index name and value are required: ${err.tableName}`;\n }\n } else if (msg?.includes(\"search_phase_execution_exception\")) {\n response = httpStatus.BAD_REQUEST;\n responseMsg = \"OpenSearch: Cannot sort by text field — use '.keyword' instead.\";\n }\n\n return {\n statusCode: response.code,\n content: {\n error: response.error,\n message: responseMsg,\n data: data,\n },\n };\n};\n\nexport const HTTP = {\n // 1xx Informational\n CONTINUE: { error: \"Continue\", code: 100 },\n SWITCHING_PROTOCOLS: { error: \"Switching Protocols\", code: 101 },\n PROCESSING: { error: \"Processing\", code: 102 },\n\n // 2xx Success\n OK: { error: \"OK\", code: 200 },\n CREATED: { error: \"Created\", code: 201 },\n ACCEPTED: { error: \"Accepted\", code: 202 },\n NON_AUTHORITATIVE_INFORMATION: { error: \"Non-Authoritative Information\", code: 203 },\n NO_CONTENT: { error: \"No Content\", code: 204 },\n RESET_CONTENT: { error: \"Reset Content\", code: 205 },\n PARTIAL_CONTENT: { error: \"Partial Content\", code: 206 },\n\n // 3xx Redirection\n MULTIPLE_CHOICES: { error: \"Multiple Choices\", code: 300 },\n MOVED_PERMANENTLY: { error: \"Moved Permanently\", code: 301 },\n FOUND: { error: \"Found\", code: 302 },\n SEE_OTHER: { error: \"See Other\", code: 303 },\n NOT_MODIFIED: { error: \"Not Modified\", code: 304 },\n TEMPORARY_REDIRECT: { error: \"Temporary Redirect\", code: 307 },\n PERMANENT_REDIRECT: { error: \"Permanent Redirect\", code: 308 },\n\n // 4xx Client Errors\n BAD_REQUEST: { error: \"Bad Request\", code: 400 },\n UNAUTHORIZED: { error: \"Unauthorized\", code: 401 },\n PAYMENT_REQUIRED: { error: \"Payment Required\", code: 402 },\n FORBIDDEN: { error: \"Forbidden\", code: 403 },\n NOT_FOUND: { error: \"Not Found\", code: 404 },\n METHOD_NOT_ALLOWED: { error: \"Method Not Allowed\", code: 405 },\n NOT_ACCEPTABLE: { error: \"Not Acceptable\", code: 406 },\n PROXY_AUTHENTICATION_REQUIRED: { error: \"Proxy Authentication Required\", code: 407 },\n REQUEST_TIMEOUT: { error: \"Request Timeout\", code: 408 },\n CONFLICT: { error: \"Conflict\", code: 409 },\n GONE: { error: \"Gone\", code: 410 },\n LENGTH_REQUIRED: { error: \"Length Required\", code: 411 },\n PRECONDITION_FAILED: { error: \"Precondition Failed\", code: 412 },\n PAYLOAD_TOO_LARGE: { error: \"Payload Too Large\", code: 413 },\n URI_TOO_LONG: { error: \"URI Too Long\", code: 414 },\n UNSUPPORTED_MEDIA_TYPE: { error: \"Unsupported Media Type\", code: 415 },\n RANGE_NOT_SATISFIABLE: { error: \"Range Not Satisfiable\", code: 416 },\n EXPECTATION_FAILED: { error: \"Expectation Failed\", code: 417 },\n IM_A_TEAPOT: { error: \"I'm a teapot\", code: 418 },\n MISDIRECTED_REQUEST: { error: \"Misdirected Request\", code: 421 },\n UNPROCESSABLE_ENTITY: { error: \"Unprocessable Entity\", code: 422 },\n LOCKED: { error: \"Locked\", code: 423 },\n FAILED_DEPENDENCY: { error: \"Failed Dependency\", code: 424 },\n TOO_EARLY: { error: \"Too Early\", code: 425 },\n UPGRADE_REQUIRED: { error: \"Upgrade Required\", code: 426 },\n PRECONDITION_REQUIRED: { error: \"Precondition Required\", code: 428 },\n TOO_MANY_REQUESTS: { error: \"Too Many Requests\", code: 429 },\n REQUEST_HEADER_FIELDS_TOO_LARGE: { error: \"Request Header Fields Too Large\", code: 431 },\n UNAVAILABLE_FOR_LEGAL_REASONS: { error: \"Unavailable For Legal Reasons\", code: 451 },\n\n // 5xx Server Errors\n INTERNAL_SERVER_ERROR: { error: \"Internal Server Error\", code: 500 },\n NOT_IMPLEMENTED: { error: \"Not Implemented\", code: 501 },\n BAD_GATEWAY: { error: \"Bad Gateway\", code: 502 },\n SERVICE_UNAVAILABLE: { error: \"Service Unavailable\", code: 503 },\n GATEWAY_TIMEOUT: { error: \"Gateway Timeout\", code: 504 },\n HTTP_VERSION_NOT_SUPPORTED: { error: \"HTTP Version Not Supported\", code: 505 },\n VARIANT_ALSO_NEGOTIATES: { error: \"Variant Also Negotiates\", code: 506 },\n INSUFFICIENT_STORAGE: { error: \"Insufficient Storage\", code: 507 },\n LOOP_DETECTED: { error: \"Loop Detected\", code: 508 },\n NOT_EXTENDED: { error: \"Not Extended\", code: 510 },\n NETWORK_AUTHENTICATION_REQUIRED: { error: \"Network Authentication Required\", code: 511 },\n};\n"]}
|
|
@@ -2,7 +2,7 @@ import { DynamoIndexMap, EndpointPolicy } from "../index.js";
|
|
|
2
2
|
/** Generic DynamoDB Configuration */
|
|
3
3
|
export declare class DynamoDBConfig {
|
|
4
4
|
NAME: string;
|
|
5
|
-
|
|
5
|
+
OWNER_PARENT_FIELD_NAME?: string;
|
|
6
6
|
OWNER_FIELD_NAME: string;
|
|
7
7
|
MAP: DynamoIndexMap;
|
|
8
8
|
constructor(tableName: string, ownerFieldName: string, indexMap: DynamoIndexMap, parentFieldName?: string);
|
|
@@ -20,7 +20,7 @@ export interface EntityConfig {
|
|
|
20
20
|
OPEN_SEARCH: OpenSearchConfig;
|
|
21
21
|
ENDPOINT_POLICY: EndpointPolicy[];
|
|
22
22
|
ADMIN_GROUP_NAME: string[];
|
|
23
|
-
|
|
23
|
+
OWNER_PARENT_ID_FIELD_NAME?: string;
|
|
24
24
|
OWNER_ID_FIELD_NAME?: string;
|
|
25
25
|
}
|
|
26
26
|
/** Generic Entity Configuration Class **/
|
|
@@ -30,11 +30,11 @@ export declare class EntityConfigImpl implements EntityConfig {
|
|
|
30
30
|
OPEN_SEARCH: OpenSearchConfig;
|
|
31
31
|
ENDPOINT_POLICY: EndpointPolicy[];
|
|
32
32
|
ADMIN_GROUP_NAME: string[];
|
|
33
|
-
|
|
33
|
+
OWNER_PARENT_ID_FIELD_NAME?: string;
|
|
34
34
|
OWNER_ID_FIELD_NAME: string;
|
|
35
35
|
constructor(basePath: string, adminGroupName?: string[]);
|
|
36
36
|
/** Set DynamoDB configuration */
|
|
37
|
-
setDynamoDB(tableName: string, ownerFieldName: string, indexMap: DynamoIndexMap,
|
|
37
|
+
setDynamoDB(tableName: string, ownerFieldName: string, indexMap: DynamoIndexMap, ownerParentFieldName?: string): this;
|
|
38
38
|
/** Set OpenSearch configuration */
|
|
39
39
|
setOpenSearch(domain: string, index: string): this;
|
|
40
40
|
/** Set path-based policies */
|
|
@@ -4,12 +4,12 @@ exports.EntityConfigImpl = exports.OpenSearchConfig = exports.DynamoDBConfig = v
|
|
|
4
4
|
/** Generic DynamoDB Configuration */
|
|
5
5
|
class DynamoDBConfig {
|
|
6
6
|
NAME; // DynamoDB table name
|
|
7
|
-
|
|
7
|
+
OWNER_PARENT_FIELD_NAME;
|
|
8
8
|
OWNER_FIELD_NAME; // DynamoDB index map for queries
|
|
9
9
|
MAP;
|
|
10
10
|
constructor(tableName, ownerFieldName, indexMap, parentFieldName) {
|
|
11
11
|
this.NAME = tableName;
|
|
12
|
-
this.
|
|
12
|
+
this.OWNER_PARENT_FIELD_NAME = parentFieldName;
|
|
13
13
|
this.OWNER_FIELD_NAME = ownerFieldName;
|
|
14
14
|
this.MAP = indexMap;
|
|
15
15
|
}
|
|
@@ -32,7 +32,7 @@ class EntityConfigImpl {
|
|
|
32
32
|
OPEN_SEARCH; // OpenSearch configuration
|
|
33
33
|
ENDPOINT_POLICY; // Path-based permission configuration
|
|
34
34
|
ADMIN_GROUP_NAME; // Admin group name for Cognito
|
|
35
|
-
|
|
35
|
+
OWNER_PARENT_ID_FIELD_NAME;
|
|
36
36
|
OWNER_ID_FIELD_NAME;
|
|
37
37
|
constructor(basePath, adminGroupName) {
|
|
38
38
|
this.BASE_PATH = basePath;
|
|
@@ -40,8 +40,10 @@ class EntityConfigImpl {
|
|
|
40
40
|
this.ENDPOINT_POLICY = [];
|
|
41
41
|
}
|
|
42
42
|
/** Set DynamoDB configuration */
|
|
43
|
-
setDynamoDB(tableName, ownerFieldName, indexMap,
|
|
44
|
-
this.DYNAMO_DB = new DynamoDBConfig(tableName, ownerFieldName, indexMap,
|
|
43
|
+
setDynamoDB(tableName, ownerFieldName, indexMap, ownerParentFieldName) {
|
|
44
|
+
this.DYNAMO_DB = new DynamoDBConfig(tableName, ownerFieldName, indexMap, ownerParentFieldName);
|
|
45
|
+
this.OWNER_PARENT_ID_FIELD_NAME = ownerParentFieldName;
|
|
46
|
+
this.OWNER_ID_FIELD_NAME = ownerFieldName;
|
|
45
47
|
return this;
|
|
46
48
|
}
|
|
47
49
|
/** Set OpenSearch configuration */
|
|
@@ -62,7 +64,7 @@ class EntityConfigImpl {
|
|
|
62
64
|
OPEN_SEARCH: this.OPEN_SEARCH,
|
|
63
65
|
ENDPOINT_POLICY: this.ENDPOINT_POLICY,
|
|
64
66
|
ADMIN_GROUP_NAME: this.ADMIN_GROUP_NAME,
|
|
65
|
-
|
|
67
|
+
OWNER_PARENT_ID_FIELD_NAME: this.OWNER_PARENT_ID_FIELD_NAME,
|
|
66
68
|
OWNER_ID_FIELD_NAME: this.OWNER_ID_FIELD_NAME,
|
|
67
69
|
};
|
|
68
70
|
}
|